From 4d05560d6d3dac4ef6cda5c68e8241bc95ca5504 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Wed, 30 Sep 2015 15:21:18 -0400 Subject: [PATCH] Skeleton comments changes Allow structured comments everywhere, as we sometimes want #!. Comment out the @ lines when generating skeletons, so that an unmodified skeleton elicits an error from grade rather than a default score, which is a perfect score with the Score modules currently in tree. --- README.rst | 7 +++---- lib/Grade/Skeleton.hs | 25 ++++++++++++------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/README.rst b/README.rst index cfe617a..265b03d 100644 --- a/README.rst +++ b/README.rst @@ -42,7 +42,7 @@ The instructor will have prepared a ``skeleton`` file which will look something like this:: # Basic features of the handin - @packaging + #@packaging #:ftbfs_all #:missing_readme #:readme_no_commentary @@ -56,7 +56,7 @@ something like this:: # Automated test result section # Un-comment the appropriate directive for each test failed. - @tests + #@tests #:ftbfs_all #:simple_test #:more_interesting_test @@ -218,8 +218,7 @@ taste. Lines that begin with ``#`` and not ``#!`` will be copied into the skeleton. Lines beginning with ``#!`` will be ignored entirely, except for some -additional advanced handling in comments immediately before a ``@`` section -heading: +additional advanced handling: * ``#!\n`` (yes, a literal backslash) will cause an empty line to be emitted into the skeleton if the containing section is not being skipped. diff --git a/lib/Grade/Skeleton.hs b/lib/Grade/Skeleton.hs index 80dd2ab..59f13d4 100644 --- a/lib/Grade/Skeleton.hs +++ b/lib/Grade/Skeleton.hs @@ -7,8 +7,8 @@ import Text.PrettyPrint.Free import Grade.Types import Grade.Parse (commentStart, commentEnd) -interpSectionComments :: Bool -> [T.Text] -> Doc e -interpSectionComments f0 = vcat . go f0 +interpComments :: Bool -> [T.Text] -> Maybe (Doc e) +interpComments f0 t0 = let r = go f0 t0 in if null r then Nothing else Just (vcat r) where go _ [] = [] go _ ("#!noskip":bs) = go False bs @@ -23,20 +23,19 @@ makeSkel (Defs _ sl) = vcat $ punctuate line $ flip fmap sl $ \(sn, ExSec (Sec _ _ shidden scl _ sds msh)) -> - let scl' = interpSectionComments shidden scl in + let ic = interpComments shidden in + let scl' = ic scl in if shidden - then scl' - else scl' - `above` "@" <> pretty (unSN sn) <> maybe empty ((empty <+>) . pretty) (fst msh) - `above` prettyDings sds (vcat [empty, commentStart, empty, commentEnd]) + then maybe empty id scl' + else maybe id above scl' $ + "#@" <> pretty (unSN sn) <> maybe empty ((empty <+>) . pretty) (fst msh) + `above` prettyDings ic sds (vcat [empty, commentStart, empty, commentEnd]) where - prettyDings [] = id - prettyDings ds = (indent 1 (vcat $ map prettyDing ds) `above`) + prettyDings _ [] = id + prettyDings ic ds = (indent 1 (vcat $ map (prettyDing ic) ds) `above`) - prettyDing (dn, DingDefn _ _ mult dcl) = - (if not (null dcl) - then (above (vcat (map pretty dcl)) . indent 1) - else id) + prettyDing ic (dn, DingDefn _ _ mult dcl) = + maybe id (\c -> above c . indent 1) (ic dcl) $ "#:" <> pretty (unDN dn) <> (if mult then " # repeat as needed" else empty) -- 2.50.1