]> hydra-www.ietfng.org Git - grade/commitdiff
Split out DingMeta too
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Thu, 10 Sep 2015 03:40:18 +0000 (23:40 -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/Types.hs

index 1065a166532fc900d10f36a7de1d4f6c9f7870bc..91f4b66f5ce98752aa5d9b2c5ccf57e4be7d86bc 100644 (file)
@@ -19,8 +19,8 @@ collectErrors x = case partitionEithers x of
                     (l, _)  -> Left l
 
 lookupSectionDings :: [(DingName, loc)]
-                   -> M.Map DingName (Ding sdt loc')
-                   -> Either [SectionError loc] [(Ding sdt loc', loc)]
+                   -> M.Map DingName (DingDefn sdt loc')
+                   -> Either [SectionError loc] [(DingDefn sdt loc', loc)]
 lookupSectionDings dns0 sm = collectErrors $ flip evalState M.empty $ mapM look dns0
  where
   look (d,loc) = do
@@ -30,7 +30,7 @@ lookupSectionDings dns0 sm = collectErrors $ flip evalState M.empty $ mapM look
       Nothing -> case M.lookup d sm of
                    Nothing -> return $ Left $ SEUndefinedDing d loc
                    Just dd -> do
-                               when (not $ _ding_multiple dd) $ modify (M.insert d loc)
+                               when (not $ _dingd_multiple dd) $ modify (M.insert d loc)
                                return $ Right (dd,loc)
 
 dingsToScore :: ExSection loc'
@@ -43,15 +43,15 @@ dingsToScore es dns =
                           (\(sc, ds) -> Right (stitle, sc, smax, map dopo ds)))
       $ bimap id (reduce . map fst) $ lookupSectionDings dns sdm
       where
-       reduce ds = (\x -> (x,ds)) <$> (sfn $ mconcat $ map _ding_mod ds)
+       reduce ds = (\x -> (x,ds)) <$> (sfn $ mconcat $ map (_dm_mod . _dingd_meta) ds)
 
-       dopo d = T.unlines $ addMod $ pure $ _ding_text d
+       dopo d = T.unlines $ addMod $ pure $ (_dm_text . _dingd_meta) d
         where
          addMod = if smax == 0.0
                    then id -- Don't print if section is worthless
                    else maybe id -- Don't print if the section chooses to not
                               ((:) . T.cons '(' . flip T.snoc ')' . T.pack) -- Add parens otherwise
-                              (spo (_ding_mod d))
+                              (spo (_dm_mod $ _dingd_meta d))
 
 processDFS :: Defines loc'
            -> DataFileSection loc
index 6fa074a627de51c5ac8d026b7429a1f0679f9776..21fc8f963371f6f4eaab4b0f8538889d8680f476 100644 (file)
@@ -60,13 +60,13 @@ untilDotLine = toUtf8 (T.sliced (T.manyTill T.anyChar (T.try $ T.lookAhead end))
 -- any number of "# comment" lines and followed by the ding text, terminated
 -- by a dot line.
 parseDingDefn :: (T.DeltaParsing f, T.LookAheadParsing f)
-              => f (sdt,sds) -> f (DingName, sds, Ding sdt T.Caret)
+              => f (sdt,sds) -> f (DingName, sds, DingDefn sdt T.Caret)
 parseDingDefn dl = do
   (dcs, reuse) <- T.try ((,) <$> many (hashComment) <*> leadchar)
   dn T.:^ c <- T.careted (DN <$> word)
   (dm, ds) <- dl
   dt <- untilDotLine
-  pure (dn, ds, Ding dm c reuse dt dcs)
+  pure (dn, ds, DingDefn (DingMeta dm dt) c reuse dcs)
  where
   leadchar = T.choice [ T.char ':' *> pure False
                       , T.char ';' *> pure True
index f711eef6ebe2d52cb2372e8cb82aa6865d9efb73..958afdd0e0bd693f4cd3a64c560162921f9be900 100644 (file)
@@ -18,6 +18,15 @@ import           Data.Typeable (Typeable)
 newtype DingName = DN { unDN :: Text }
  deriving (Eq,Ord,Show,Typeable)
 
+-- | Things common to dings between their definition and
+-- their use
+data DingMeta mt = DingMeta
+  { _dm_mod  :: mt
+  , _dm_text :: Text
+  }
+ deriving(Eq,Ord,Typeable)
+$(LTH.makeLenses ''DingMeta)
+
 -- | A point deduction definition
 --
 -- A Ding is parameterized by some modifier for its section.
@@ -27,15 +36,14 @@ newtype DingName = DN { unDN :: Text }
 -- Each Ding is associated with a location (parameterized to avoid
 -- dependency on any particular parsing framework)
 --
-data Ding mt loc = Ding
-  { _ding_mod           :: mt
-  , _ding_loc           :: loc
-  , _ding_multiple      :: Bool
-  , _ding_text          :: Text
-  , _ding_comment_lines :: [Text]
+data DingDefn mt loc = DingDefn
+  { _dingd_meta          :: DingMeta mt
+  , _dingd_loc           :: loc
+  , _dingd_multiple      :: Bool
+  , _dingd_comment_lines :: [Text]
   }
  deriving (Eq,Ord,{-Show-}Typeable)
-$(LTH.makeLenses ''Ding)
+$(LTH.makeLenses ''DingDefn)
 
 data SecMeta sdt = SecMeta
   { -- | Title of the section as displayed to the user, not
@@ -63,7 +71,7 @@ data Section sdt loc = Sec
   { _sec_meta          :: SecMeta sdt
   , _sec_hidden        :: Bool
   , _sec_comment_lines :: [Text]
-  , _sec_dings         :: Map DingName (Ding sdt loc)
+  , _sec_dings         :: Map DingName (DingDefn sdt loc)
   }
  deriving (Typeable)
 $(LTH.makeLenses ''Section)