]> hydra-www.ietfng.org Git - grade/commitdiff
Move section metadata to its own data type
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Thu, 10 Sep 2015 02:28:38 +0000 (22:28 -0400)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Sat, 12 Sep 2015 00:34:00 +0000 (20:34 -0400)
lib/Grade/Grade.hs
lib/Grade/Parse.hs
lib/Grade/Skeleton.hs
lib/Grade/Types.hs

index eea6e8efd13e8819c33bbf891a7c8ccbf78e3894..1065a166532fc900d10f36a7de1d4f6c9f7870bc 100644 (file)
@@ -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
index fa21c7e708384ad9b998930c2ebb828ce556ae68..6fa074a627de51c5ac8d026b7429a1f0679f9776 100644 (file)
@@ -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
index 546b85b5f10d5f1aa6aff9eb590857668cae3cae..5dedc4d16b642e57210219cc5415e2b1c4efa2f5 100644 (file)
@@ -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'
index 5bff9dea63f99bf2da5161863c6984a047db35fd..f711eef6ebe2d52cb2372e8cb82aa6865d9efb73 100644 (file)
@@ -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)