(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
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'
(\(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
-- 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
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.
-- 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
{ _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)