Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the term "remark" instead of "comment" #48

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Ast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ data Mood

instance Out Mood

data CommentPart
= CommentStr String
| CommentCmt Comment
data RemarkPart
= RemarkStr String
| RemarkCmt Remark
deriving (Eq, Show, Generic)

instance Out CommentPart
instance Out RemarkPart

newtype Comment
= Comment (Mood, [CommentPart])
newtype Remark
= Remark (Mood, [RemarkPart])
deriving (Eq, Show, Generic)

instance Out Comment
instance Out Remark

newtype Property
= Property (String, PropertyExp)
Expand Down Expand Up @@ -79,8 +79,8 @@ data PropertyArithFun
instance Out PropertyArithFun

data Judgement
= Judgement (Header, [Property], [Comment], [Judgement])
| Bonus (Int, [Property], [Comment])
= Judgement (Header, [Property], [Remark], [Judgement])
| Bonus (Int, [Property], [Remark])
| Feedback ([Property], String)
deriving (Eq, Show, Generic)

Expand Down
38 changes: 19 additions & 19 deletions src/Export/Html.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ htmlTableHead (Judgement (_, _, _, js)) =

htmlJudgement :: Judgement -> Doc
htmlJudgement (Feedback _) = empty
htmlJudgement (j@(Bonus (_, _, comments))) =
(tr $ td $ lookupTotal j) $$ (trhidden $ htmlDetailComments comments)
htmlJudgement (j@(Judgement (_, _, comments, judgements))) =
htmlJudgement (j@(Bonus (_, _, remarks))) =
(tr $ td $ lookupTotal j) $$ (trhidden $ htmlDetailRemarks remarks)
htmlJudgement (j@(Judgement (_, _, remarks, judgements))) =
( tr $
(td . toggle $ lookupTitle j)
$$ vcat (map htmlSubJudgement judgements)
$$ (td $ lookupTotal j)
)
$$ (trhidden $ tdspan (length judgements + 2) $ (htmlDetailComments comments $$ htmlDetailJudgements judgements))
$$ (trhidden $ tdspan (length judgements + 2) $ (htmlDetailRemarks remarks $$ htmlDetailJudgements judgements))

htmlSubJudgement :: Judgement -> Doc
htmlSubJudgement j = td $ lookupTotal j
Expand All @@ -129,21 +129,21 @@ htmlDetailJudgements = vcat . (map htmlDetailJudgement)

htmlDetailJudgement :: Judgement -> Doc
htmlDetailJudgement (Feedback _) = empty
htmlDetailJudgement (j@(Bonus (_, _, comments))) =
details (text "Bonus" <+> parens (lookupTotal j)) (htmlDetailComments comments)
htmlDetailJudgement (j@(Judgement (_, _, comments, judgements))) =
htmlDetailJudgement (j@(Bonus (_, _, remarks))) =
details (text "Bonus" <+> parens (lookupTotal j)) (htmlDetailRemarks remarks)
htmlDetailJudgement (j@(Judgement (_, _, remarks, judgements))) =
details
(lookupTitle j <+> parens (lookupTotal j <> text "/" <> lookupMaxPoints j))
(htmlDetailComments comments $$ htmlDetailJudgements judgements)
(htmlDetailRemarks remarks $$ htmlDetailJudgements judgements)

htmlDetailComments :: [Comment] -> Doc
htmlDetailComments [] = empty
htmlDetailComments comments =
ul . vcat $ map htmlDetailComment comments
htmlDetailRemarks :: [Remark] -> Doc
htmlDetailRemarks [] = empty
htmlDetailRemarks remarks =
ul . vcat $ map htmlDetailRemark remarks

htmlDetailComment :: Comment -> Doc
htmlDetailComment (Comment (mood, commentParts)) =
liclass (htmlDetailMood mood) $ vcat $ map htmlDetailCommentPart commentParts
htmlDetailRemark :: Remark -> Doc
htmlDetailRemark (Remark (mood, remarkParts)) =
liclass (htmlDetailMood mood) $ vcat $ map htmlDetailRemarkPart remarkParts

htmlDetailMood :: Mood -> String
htmlDetailMood Positive = "plus"
Expand All @@ -153,7 +153,7 @@ htmlDetailMood Neutral = "star"
htmlDetailMood Impartial = "quest"
htmlDetailMood Warning = "excl"

htmlDetailCommentPart :: CommentPart -> Doc
htmlDetailCommentPart (CommentStr string) = text string
htmlDetailCommentPart (CommentCmt comment) =
ul $ htmlDetailComment comment
htmlDetailRemarkPart :: RemarkPart -> Doc
htmlDetailRemarkPart (RemarkStr string) = text string
htmlDetailRemarkPart (RemarkCmt remark) =
ul $ htmlDetailRemark remark
10 changes: 5 additions & 5 deletions src/Export/HtmlTable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ formatStart :: Judgement -> [Row]
formatStart (Bonus _) = []
formatStart (Feedback _) = []
formatStart (j@(Judgement (_, _, cs, js))) =
[(getTitle j) : (getTotal j) : r1, "" : (formatComments cs) : r2]
[(getTitle j) : (getTotal j) : r1, "" : (formatRemarks cs) : r2]
where
-- [(getTitle j):(getTotal j):r1]

(r1, r2) = concatUnzipMap formatJudgement js

formatJudgement :: Judgement -> (Row, Row)
formatJudgement (j@(Bonus (_, _, cs))) = ([getTotal j], [formatComments cs])
formatJudgement (j@(Bonus (_, _, cs))) = ([getTotal j], [formatRemarks cs])
formatJudgement (Feedback _) = ([], [])
formatJudgement (j@(Judgement (_, _, cs, js))) =
((getTotal j) : r1, (formatComments cs) : r2)
((getTotal j) : r1, (formatRemarks cs) : r2)
where
(r1, r2) = concatUnzipMap formatJudgement js

Expand All @@ -40,5 +40,5 @@ concatUnzipMap f l =
where
(c1, c2) = unzip $ map f l

formatComments :: [Comment] -> String
formatComments cs = concat $ intersperse "<br>" $ map (\x -> "" ++ ppComment x) cs
formatRemarks :: [Remark] -> String
formatRemarks cs = concat $ intersperse "<br>" $ map (\x -> "" ++ ppRemark x) cs
16 changes: 8 additions & 8 deletions src/Export/MD.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ formatJudgement depth (Feedback (_, t)) =
(text $ replicate depth '#') <+> text "Feedback" <> colon
$+$ text "+"
<> text t
formatJudgement depth (j@(Judgement (_, _, comments, judgements))) =
formatJudgement depth (j@(Judgement (_, _, remarks, judgements))) =
formatHeader depth j
$+$ (nest 2 $ vcat $ map formatComment comments)
$+$ (nest 2 $ vcat $ map formatRemark remarks)
$+$ text ""
$+$ (vcat $ map (formatJudgement (depth + 1)) judgements)

Expand All @@ -38,9 +38,9 @@ formatHeader depth j =
<> text "/"
<> lookupMaxPoints j

formatComment :: Comment -> Doc
formatComment (Comment (mood, commentParts)) =
text "*" <+> formatMood mood <+> (vcat $ map formatCommentPart commentParts)
formatRemark :: Remark -> Doc
formatRemark (Remark (mood, remarkParts)) =
text "*" <+> formatMood mood <+> (vcat $ map formatRemarkPart remarkParts)

formatMood :: Mood -> Doc
formatMood Positive = text "(+)"
Expand All @@ -50,6 +50,6 @@ formatMood Mixed = text "(~)"
formatMood Impartial = text "(?)"
formatMood Warning = text "(!)"

formatCommentPart :: CommentPart -> Doc
formatCommentPart (CommentStr string) = text string
formatCommentPart (CommentCmt comment) = nest 2 $ formatComment comment
formatRemarkPart :: RemarkPart -> Doc
formatRemarkPart (RemarkStr string) = text string
formatRemarkPart (RemarkCmt remark) = nest 2 $ formatRemark remark
20 changes: 10 additions & 10 deletions src/Export/PdfMark.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ genPdfMark js = render $ (header $+$ text "" $+$ jmts)
$+$ text " /DOCINFO pdfmark"

formatJudgement :: Judgement -> Doc
formatJudgement j@(Judgement (_, properties, comments, judgements)) =
(vcat $ map (formatPdfMark (formatHeader j) (formatPoints j) properties comments) properties)
formatJudgement j@(Judgement (_, properties, remarks, judgements)) =
(vcat $ map (formatPdfMark (formatHeader j) (formatPoints j) properties remarks) properties)
$+$ (vcat $ map formatJudgement judgements)
formatJudgement j@(Bonus (_, properties, comments)) =
(vcat $ map (formatPdfMark (text "Bonus") (formatPoints j) properties comments) properties)
formatJudgement j@(Bonus (_, properties, remarks)) =
(vcat $ map (formatPdfMark (text "Bonus") (formatPoints j) properties remarks) properties)
formatJudgement (Feedback (properties, txt)) =
(vcat $ map (formatPdfMark (text "Feedback") (text txt) properties []) properties)

formatPdfMark :: Doc -> Doc -> [Property] -> [Comment] -> Property -> Doc
formatPdfMark :: Doc -> Doc -> [Property] -> [Remark] -> Property -> Doc
formatPdfMark header points props comms (Property ("pdfmark", List pmtype)) =
formatPdfMarkType pmtype header points props comms
formatPdfMark _ _ _ _ _ = empty

formatPdfMarkType :: [String] -> Doc -> Doc -> [Property] -> [Comment] -> Doc
formatPdfMarkType (("Comment") : rest) header points _ comms =
formatPdfMarkType :: [String] -> Doc -> Doc -> [Property] -> [Remark] -> Doc
formatPdfMarkType (("Remark") : rest) header points _ comms =
text "[" <+> text "/Title" <+> (parens header)
$+$ text " /Contents" <+> parens (points <> text "\n" <> (text $ formatComments comms))
$+$ text " /Contents" <+> parens (points <> text "\n" <> (text $ formatRemarks comms))
$+$ text " /SrcPg" <+> text page
$+$ text " /Rect" <+> text loc
$+$ text " /Subtype /Text"
Expand All @@ -52,8 +52,8 @@ formatPdfMarkType (("Comment") : rest) header points _ comms =
loc = head $ tail rest
formatPdfMarkType _ _ _ _ _ = empty

formatComments :: [Comment] -> String
formatComments cs = concat $ intersperse "\n" $ map (\x -> "" ++ (escapeParens $ ppComment x)) cs
formatRemarks :: [Remark] -> String
formatRemarks cs = concat $ intersperse "\n" $ map (\x -> "" ++ (escapeParens $ ppRemark x)) cs

formatHeader :: Judgement -> Doc
formatHeader j = text (getTitle j)
Expand Down
4 changes: 2 additions & 2 deletions src/MergeAsts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ mergeMaybeJudgement j Nothing = j
mergeMaybeJudgement j (Just jp) = mergeJudgement j jp

mergeJudgement :: Judgement -> Judgement -> Judgement
mergeJudgement (Judgement (header, p1, comments, subjs)) (Judgement (_, p2, [], subpjs)) =
Judgement (header, p1 ++ p2, comments, (mergeProps subjs subpjs))
mergeJudgement (Judgement (header, p1, remarks, subjs)) (Judgement (_, p2, [], subpjs)) =
Judgement (header, p1 ++ p2, remarks, (mergeProps subjs subpjs))
mergeJudgement j _ = j -- If there is something with bonus, just not add anything
18 changes: 9 additions & 9 deletions src/Parser/ImplMegaparsec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ parseBonus _ = do
total <- parsePointsNum
endline
properties <- sepEndBy parseProperty endline
comments <- many $ parseComment 1
pure $ Bonus (total, properties, comments)
remarks <- many $ parseRemark 1
pure $ Bonus (total, properties, remarks)

parseFeedback :: Int -> MrkParser Judgement
parseFeedback depth = do
Expand All @@ -131,9 +131,9 @@ parseRegularJudgement depth title = do
maxPoints <- parsePointsNum
endline
properties <- sepEndBy parseProperty newline
comments <- many $ parseComment 1
remarks <- many $ parseRemark 1
js <- many (parseJudgement (depth + 1))
pure $ Judgement (Header (title, total, maxPoints), properties, comments, js)
pure $ Judgement (Header (title, total, maxPoints), properties, remarks, js)

parseProperty :: MrkParser Property
parseProperty = try property
Expand Down Expand Up @@ -218,15 +218,15 @@ parsePropertyArithFun =
string "if" *> pure If
]

parseComment :: Int -> MrkParser Comment
parseComment depth = do
parseRemark :: Int -> MrkParser Remark
parseRemark depth = do
void $ try $ string $ concat $ replicate depth indentation
mood <- parseMood
space
comment <- parseLine
remark <- parseLine
morecmt <- many contStr
comments <- many (parseComment $ depth + 1)
pure $ Comment (mood, [(CommentStr comment)] ++ (map CommentStr morecmt) ++ (map CommentCmt comments))
remarks <- many (parseRemark $ depth + 1)
pure $ Remark (mood, [(RemarkStr remark)] ++ (map RemarkStr morecmt) ++ (map RemarkCmt remarks))
where
contStr = do
void $ try $ ((string $ concat $ replicate (depth + 1) indentation) >> notFollowedBy parseMood)
Expand Down
32 changes: 16 additions & 16 deletions src/Pending.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Prelude hiding ((<>))

data PendingTree
= Node String Int Bool [PendingTree]
-- Name, Number of Comments, Is pending, Subtree
-- Name, Number of Remarks, Is pending, Subtree
deriving (Eq, Show)

data FormatTree
Expand Down Expand Up @@ -65,14 +65,14 @@ formatSubTrees ft (t : ts) =

formatSubTree :: (FormatTree -> FormatTree) -> PendingTree -> Doc
-- formatSubTree ft (Node "" _ _ _) = empty
formatSubTree ft (Node s cs _ ts) = text s <> formatTreeComments ft cs <> formatSubTrees ft ts
formatSubTree ft (Node s cs _ ts) = text s <> formatTreeRemarks ft cs <> formatSubTrees ft ts

formatTreeComments :: (FormatTree -> FormatTree) -> Int -> Doc
formatTreeComments _ 0 = empty
formatTreeComments ft cs =
linebreak <> showTree (ft TQuest) <> text (makePlural cs "impartial comment")
formatTreeRemarks :: (FormatTree -> FormatTree) -> Int -> Doc
formatTreeRemarks _ 0 = empty
formatTreeRemarks ft cs =
linebreak <> showTree (ft TQuest) <> text (makePlural cs "impartial remark")

size :: PendingTree -> ((Int, Int), Int) -- (Pending, Total), Comments
size :: PendingTree -> ((Int, Int), Int) -- (Pending, Total), Remarks
size (Node _ cs True []) = ((1, 1), cs)
size (Node _ cs False []) = ((0, 1), cs)
size (Node _ cs _ pt) = foldl tupAdd ((0, 0), cs) $ map size pt
Expand All @@ -93,8 +93,8 @@ trimPendingTree (Node s cs True ts) = Node s cs True (map trimPendingTree ts)

showTasks :: ((Int, Int), Int) -> String
showTasks ((n, s), 0) = " : " ++ show n ++ " of " ++ show s ++ " " ++ makePlural n "task" ++ " (" ++ showPercentage n s ++ ")"
showTasks ((0, _), m) = " : " ++ show m ++ " " ++ makePlural m "comment" ++ ")"
showTasks ((n, s), m) = " : " ++ show n ++ " of " ++ show s ++ " " ++ makePlural n "task" ++ " (" ++ showPercentage n s ++ ")" ++ " and " ++ show m ++ " " ++ makePlural m "comment"
showTasks ((0, _), m) = " : " ++ show m ++ " " ++ makePlural m "remark" ++ ")"
showTasks ((n, s), m) = " : " ++ show n ++ " of " ++ show s ++ " " ++ makePlural n "task" ++ " (" ++ showPercentage n s ++ ")" ++ " and " ++ show m ++ " " ++ makePlural m "remark"

showPercentage :: Int -> Int -> String
showPercentage n s = show (div (n * 100) (s)) ++ "%"
Expand All @@ -119,16 +119,16 @@ pendingJudgement (Judgement (Header (t, _, _), _, cs, subJs)) =
sub_pending = concatMap pendingJudgement subJs
has_pending = or $ map (\(Node _ _ b _) -> b) sub_pending

countImpartials :: [Comment] -> Int
countImpartials :: [Remark] -> Int
countImpartials = sum . (map countImpartial)

countImpartial :: Comment -> Int
countImpartial (Comment (Impartial, cps)) = 1 + (sum $ map countImpartialCP cps)
countImpartial (Comment (_, cps)) = sum $ map countImpartialCP cps
countImpartial :: Remark -> Int
countImpartial (Remark (Impartial, cps)) = 1 + (sum $ map countImpartialCP cps)
countImpartial (Remark (_, cps)) = sum $ map countImpartialCP cps

countImpartialCP :: CommentPart -> Int
countImpartialCP (CommentStr _) = 0
countImpartialCP (CommentCmt c) = countImpartial c
countImpartialCP :: RemarkPart -> Int
countImpartialCP (RemarkStr _) = 0
countImpartialCP (RemarkCmt c) = countImpartial c

findPending :: Maybe Int -> [Judgement] -> Maybe (String)
findPending detailLevel js =
Expand Down
28 changes: 14 additions & 14 deletions src/PrettyPrinter.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PrettyPrinter (ppJ_d, ppJs, ppPoints, ppComments, ppComment, ppPropExp) where
module PrettyPrinter (ppJ_d, ppJs, ppPoints, ppRemarks, ppRemark, ppPropExp) where

import Ast
-- use (<>) from Text.PrettyPrint
Expand All @@ -17,11 +17,11 @@ ppJs = render . vcat . intersperse (text "") . map (formatJudgement 1)
ppPoints :: Points -> String
ppPoints = render . pointsDoc

ppComments :: [Comment] -> String
ppComments = render . vcat . (map formatComment)
ppRemarks :: [Remark] -> String
ppRemarks = render . vcat . (map formatRemark)

ppComment :: Comment -> String
ppComment = render . formatComment
ppRemark :: Remark -> String
ppRemark = render . formatRemark

ppPropExp :: PropertyExp -> String
ppPropExp = render . propertyExpDoc
Expand All @@ -37,15 +37,15 @@ formatJudgement depth (Bonus (p, properties, comments)) =
<+> text "+"
<> pointsDoc (Given p)
$+$ (nest 2 $ vcat $ map formatProperty properties)
$+$ (nest 2 $ vcat $ map formatComment comments)
$+$ (nest 2 $ vcat $ map formatRemark comments)
formatJudgement depth (Feedback (properties, feedback)) =
(text $ replicate depth '#') <+> text "Feedback" <> colon
$+$ (nest 2 $ vcat $ map formatProperty properties)
$+$ (text feedback)
formatJudgement depth (Judgement (header, properties, comments, judgements)) =
formatHeader depth header
$+$ (nest 2 $ vcat $ map formatProperty properties)
$+$ (nest 2 $ vcat $ map formatComment comments)
$+$ (nest 2 $ vcat $ map formatRemark comments)
$+$ (vcat $ map (formatJudgement (depth + 1)) judgements)

formatHeader :: Int -> Header -> Doc
Expand All @@ -67,13 +67,13 @@ formatProperty (Property (name, value)) =

-- formatPMType :: PdfMarkType -> Doc
-- formatPMType (PMComment page loc) =
-- text "Comment" <> semicolon <+> text page <> semicolon <+> text loc
-- text "Remark" <> semicolon <+> text page <> semicolon <+> text loc
-- formatPMType (PMTickBox _ page loc) =
-- text "TickBox" <> semicolon <+> text page <> semicolon <+> text loc

formatComment :: Comment -> Doc
formatComment (Comment (mood, commentParts)) =
formatMood mood <+> (vcat $ map formatCommentPart commentParts)
formatRemark :: Remark -> Doc
formatRemark (Remark (mood, commentParts)) =
formatMood mood <+> (vcat $ map formatRemarkPart commentParts)

formatMood :: Mood -> Doc
formatMood Positive = text "+"
Expand All @@ -83,6 +83,6 @@ formatMood Impartial = text "?"
formatMood Warning = text "!"
formatMood Mixed = text "~"

formatCommentPart :: CommentPart -> Doc
formatCommentPart (CommentStr string) = text string
formatCommentPart (CommentCmt comment) = formatComment comment
formatRemarkPart :: RemarkPart -> Doc
formatRemarkPart (RemarkStr string) = text string
formatRemarkPart (RemarkCmt comment) = formatRemark comment
Loading