Skip to content

Commit

Permalink
Parse trailling comma & multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
kanghyojun committed Apr 12, 2018
1 parent 6684371 commit afd38bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/Nirum/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -652,15 +652,16 @@ imports forwardNames = do
spaces
char '('
spaces
idents <- many' [] $ \ importNames' -> do
idents <- many' [] $ \ importNames' -> try $ do
let forwardNames' = [ i | (_, i, _) <- importNames' ] ++
forwardNames
unless (L.null importNames') $ do
string' ","
spaces
i <- importName forwardNames'
spaces
return i
importName forwardNames'
when (L.null idents) $ fail "parentheses cannot be empty"
void $ optional $ string' ","
spaces
char ')'
spaces
char ';'
Expand Down
2 changes: 1 addition & 1 deletion test/Nirum/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ service method-dups (
, Import ["foo", "bar"] "b" "b" empty
]
specify "import names can have a trailing comma" $
parse' "import foo.bar (a, b,);" `shouldBeRight`
parse' "import foo.bar (a, b,) ;" `shouldBeRight`
[ Import ["foo", "bar"] "a" "a" empty
, Import ["foo", "bar"] "b" "b" empty
]
Expand Down

0 comments on commit afd38bf

Please sign in to comment.