on master help sign in
Allow eof instead of eol for comments, closes idris-lang/Idris-dev#503
a88a918Ahmad Salim Al-Sibahi
src/Idris/Parser.hs+6−4
@@ -73,9 +73,11 @@ simpleWhiteSpace = satisfy isSpace *> pure ()
73-- | Checks if a charcter is end of line
73-- | Checks if a charcter is end of line
74isEol :: Char -> Bool
74isEol :: Char -> Bool
75isEol '\n' = True
75isEol '\n' = True
76−isEol '\0' = True -- Check eof too
77isEol _ = False
76isEol _ = False
78
77
78+eol :: MonadicParsing m => m ()
79+eol = (satisfy isEol *> pure ()) <|> lookAhead eof <?> "end of line"
80+
79-- | Checks if a character is a documentation comment marker
81-- | Checks if a character is a documentation comment marker
80isDocCommentMarker :: Char -> Bool
82isDocCommentMarker :: Char -> Bool
81isDocCommentMarker '|' = True
83isDocCommentMarker '|' = True
@@ -88,8 +90,8 @@ isDocCommentMarker _ = False
88 ;
90 ;
89 -}
91 -}
90singleLineComment :: MonadicParsing m => m ()
92singleLineComment :: MonadicParsing m => m ()
91−singleLineComment = try (string "--" *> satisfy isEol *> pure ())
93+singleLineComment = try (string "--" *> eol *> pure ())
92− <|> string "--" *> satisfy (not . isDocCommentMarker) *> many (satisfy (not . isEol)) *> (satisfy isEol <?> "end of line") *> pure ()
94+ <|> string "--" *> satisfy (not . isDocCommentMarker) *> many (satisfy (not . isEol)) *> eol *> pure ()
93 <?> ""
95 <?> ""
94
96
95{- | Consumes a multi-line comment
97{- | Consumes a multi-line comment
@@ -129,7 +131,7 @@ docComment :: MonadicParsing m => Char -> m String
129docComment marker | isDocCommentMarker marker = do dc <- docComment' marker; return (T.unpack $ T.strip $ T.pack dc)
131docComment marker | isDocCommentMarker marker = do dc <- docComment' marker; return (T.unpack $ T.strip $ T.pack dc)
130 | otherwise = fail "internal error: tried to parse a documentation comment with invalid marker"
132 | otherwise = fail "internal error: tried to parse a documentation comment with invalid marker"
131 where docComment' :: MonadicParsing m => Char -> m String
133 where docComment' :: MonadicParsing m => Char -> m String
132− docComment' marker = string "--" *> char marker *> many (satisfy (not . isEol)) <* satisfy isEol
134+ docComment' marker = string "--" *> char marker *> many (satisfy (not . isEol)) <* eol
133 <|> string "{-" *> char marker *> (manyTill anyChar (try (string "-}")) <?> "end of comment")
135 <|> string "{-" *> char marker *> (manyTill anyChar (try (string "-}")) <?> "end of comment")
134 <?> ""
136 <?> ""
135
137