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

Allow missing line break at eof #38

Merged
merged 1 commit into from
Jul 16, 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
14 changes: 7 additions & 7 deletions src/Parser/ImplParsec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ parseString input = parse parseRemarks "String" input
-- * Implementation of the parser
-------------------------------------------------------------------------------

endline :: MrkParser ()
endline = choice [void $ many1 newline, eof]

parseLine :: MrkParser String
parseLine = manyTill anyChar (many1 newline)
parseLine = manyTill anyChar endline

parseIndentation :: MrkParser ()
parseIndentation = string indentation >> pure ()

endline :: MrkParser ()
endline = void $ many1 newline

-- string :: String -> MrkParser ()
-- string s = sequence_ $ mapM char s

Expand Down Expand Up @@ -105,14 +105,14 @@ parseBonus _ = do
void $ char '+'
total <- parsePointsNum
endline
properties <- sepEndBy parseProperty newline
properties <- sepEndBy parseProperty endline
comments <- many $ parseComment 1
pure $ Bonus (total, properties, comments)

parseFeedback :: Int -> MrkParser Judgement
parseFeedback depth = do
endline
properties <- sepEndBy parseProperty newline
properties <- sepEndBy parseProperty endline
text <- manyTill anyChar $ try (lookAhead (parseJudgement depth))
pure $ Feedback (properties, text)
-- where
Expand Down Expand Up @@ -224,7 +224,7 @@ parsePropertyExp = choice [try funProp, try lookupPropChild, try lookupPropParen
pure (s:ss)
listH2 = do
-- spaces
s <- manyTill anyChar $ char '\n'
s <- manyTill anyChar $ endline
pure [s]
nolineBreak = do
c <- lookAhead anyChar
Expand Down
49 changes: 49 additions & 0 deletions test/Parser/BlackBoxTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,37 @@ unitTests = testGroup "Unit tests"
Right
[ Judgement (Header ("A",Given 0,0), [], [], [])
]
, testCase "Lone header line (no line break at eof)" $
parseString "# A: 0/0" @?=
Right
[ Judgement (Header ("A",Given 0,0), [], [], [])
]
, testCase "A couple same-depth header lines" $
parseString "# A: 0/0\n# B: 0/0\n" @?=
Right
[ Judgement (Header ("A",Given 0,0), [], [], [])
, Judgement (Header ("B",Given 0,0), [], [], [])
]
, testCase "A couple same-depth header lines (no line break at eof)" $
parseString "# A: 0/0\n# B: 0/0" @?=
Right
[ Judgement (Header ("A",Given 0,0), [], [], [])
, Judgement (Header ("B",Given 0,0), [], [], [])
]
, testCase "A simple hierarchy of headers" $
parseString "# A: 0/0\n## B: 0/0\n" @?=
Right
[ Judgement (Header ("A",Given 0,0), [], [],
[ Judgement (Header ("B",Given 0,0), [], [], [])
])
]
, testCase "A simple hierarchy of headers (no line break at eof)" $
parseString "# A: 0/0\n## B: 0/0" @?=
Right
[ Judgement (Header ("A",Given 0,0), [], [],
[ Judgement (Header ("B",Given 0,0), [], [], [])
])
]
, testCase "A couple simple hierarchies" $
parseString "# A: 0/0\n## B: 0/0\n# C: 0/0\n" @?=
Right
Expand All @@ -40,6 +58,37 @@ unitTests = testGroup "Unit tests"
])
, Judgement (Header ("C",Given 0,0), [], [], [])
]
, testCase "Simple bonus" $
parseString "# Bonus: +5\n" @?=
Right [Bonus (500, [], [])]
, testCase "Simple bonus (no line break at eof)" $
parseString "# Bonus: +5" @?=
Right [Bonus (500, [], [])]
, testCase "Bonus with props" $
parseString "# Bonus: +5\n :x:y\n" @?=
Right [Bonus (500,[Property ("x",Value "y")],[])]
, testCase "Bonus with props (no line break at eof)" $
parseString "# Bonus: +5\n :x:y" @?=
Right [Bonus (500,[Property ("x",Value "y")],[])]
, testCase "Judgement with comments (no line break at eof)" $
parseString "# A: 5/10\n - Bad indentation\n I'd say" @?=
Right
[
Judgement (Header ("A",Given 500,1000),[],[
Comment (Negative,[
CommentStr "Bad indentation",
CommentStr "I'd say"
])],[])
]
, testCase "Another judgement with comments (no line break at eof)" $
parseString "# A: 5/10\n - Bad indentation\n + Otherwise, OK" @?=
Right
[
Judgement (Header ("A",Given 500,1000),[],[
Comment (Negative,[CommentStr "Bad indentation"]),
Comment (Positive,[CommentStr "Otherwise, OK"])
],[])
]
]

qcTests :: TestTree
Expand Down