From: Nathaniel Wesley Filardo Date: Thu, 10 Sep 2015 02:28:38 +0000 (-0400) Subject: Move section metadata to its own data type X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=dd0ade438d8851bd5dd8df9164cac3470c30ed53;p=grade Move section metadata to its own data type --- diff --git a/lib/Grade/Grade.hs b/lib/Grade/Grade.hs index eea6e8e..1065a16 100644 --- a/lib/Grade/Grade.hs +++ b/lib/Grade/Grade.hs @@ -38,7 +38,7 @@ dingsToScore :: ExSection loc' -> 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 diff --git a/lib/Grade/Parse.hs b/lib/Grade/Parse.hs index fa21c7e..6fa074a 100644 --- a/lib/Grade/Parse.hs +++ b/lib/Grade/Parse.hs @@ -40,6 +40,8 @@ hashComment :: T.DeltaParsing f => f Text 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 @@ -86,7 +88,7 @@ parseSectionDefn fsdap = do 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 diff --git a/lib/Grade/Skeleton.hs b/lib/Grade/Skeleton.hs index 546b85b..5dedc4d 100644 --- a/lib/Grade/Skeleton.hs +++ b/lib/Grade/Skeleton.hs @@ -23,7 +23,7 @@ makeSkel :: Defines loc -> Doc e 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' diff --git a/lib/Grade/Types.hs b/lib/Grade/Types.hs index 5bff9de..f711eef 100644 --- a/lib/Grade/Types.hs +++ b/lib/Grade/Types.hs @@ -27,8 +27,8 @@ newtype DingName = DN { unDN :: Text } -- 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 @@ -37,6 +37,21 @@ data Ding sdt loc = Ding 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 @@ -45,13 +60,10 @@ $(LTH.makeLenses ''Ding) -- 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)