-> Either [SectionError loc] (T.Text, Double, Double, [T.Text])
dingsToScore es dns =
case es of
- ExSec (Sec stitle smax _ sfn spo sdm _) ->
+ ExSec (Sec (SecMeta stitle smax sfn spo) _ _ sdm) ->
either Left (either (Left . pure . SEScoreError)
(\(sc, ds) -> Right (stitle, sc, smax, map dopo ds)))
$ bimap id (reduce . map fst) $ lookupSectionDings dns sdm
hashComment = toUtf8 (T.sliced (T.char '#' *> many (T.noneOf "\r\n"))) <* T.whiteSpace
-- hashComment = T.sliced (T.char '#' *> T.manyTill T.anyChar T.newline) <* T.whiteSpace
+-- | Grab a word in its entirety. Note that this is a little strange as
+-- we check the 'notFollowedBy' condition *first*!
word :: (T.DeltaParsing f) => f Text
word = toUtf8 (T.sliced (many $ T.satisfy (not . C.isSpace))) <* T.whiteSpace
SC fsdt sdpo sfn smaxfn -> do
(sstate, sdings) <- getDings fsdt M.empty
return (sname, c, ExSec $
- Sec stitle (smaxfn sstate) shidden (sfn sstate) (sdpo sstate) sdings scs)
+ Sec (SecMeta stitle (smaxfn sstate) (sfn sstate) (sdpo sstate)) shidden scs sdings)
where
getDings sdp = go mempty
where
makeSkel (Defs sm) =
vcat $ punctuate line
$ flip fmap (M.toList sm)
- $ \(sn, (ExSec (Sec _ _ shidden _ _ sdm scl), _)) ->
+ $ \(sn, (ExSec (Sec _ shidden scl sdm), _)) ->
let scl' = interpSectionComments shidden scl in
if shidden
then scl'
-- Each Ding is associated with a location (parameterized to avoid
-- dependency on any particular parsing framework)
--
-data Ding sdt loc = Ding
- { _ding_mod :: sdt
+data Ding mt loc = Ding
+ { _ding_mod :: mt
, _ding_loc :: loc
, _ding_multiple :: Bool
, _ding_text :: Text
deriving (Eq,Ord,{-Show-}Typeable)
$(LTH.makeLenses ''Ding)
+data SecMeta sdt = SecMeta
+ { -- | Title of the section as displayed to the user, not
+ -- necessarily the internal name
+ _sm_title :: Text
+ , -- | Maximum score
+ _sm_max :: Double
+ , -- | Given a reduced sdsdum, format the score for presentation
+ -- or indicate that there has been an error.
+ _sm_scorefn :: sdt -> Either String Double
+ , -- | Provide text for printing out the impact of a particular
+ -- score adjustment.
+ _sm_dingprinter :: sdt -> Maybe String
+ }
+$(LTH.makeLenses ''SecMeta)
+
-- | A Section is mostly a collection of Dings.
--
-- Each section, like each Ding, may have a collection of comments
-- It also conains a section scoring function, which
-- reduces dingmods to a score.
data Section sdt loc = Sec
- { _sec_title :: Text
- , _sec_max :: Double
+ { _sec_meta :: SecMeta sdt
, _sec_hidden :: Bool
- , _sec_scorefn :: sdt -> Either String Double
- , _sec_dingprinter :: sdt -> Maybe String
- , _sec_dings :: Map DingName (Ding sdt loc)
, _sec_comment_lines :: [Text]
+ , _sec_dings :: Map DingName (Ding sdt loc)
}
deriving (Typeable)
$(LTH.makeLenses ''Section)