on master help sign in
Actually parse documentation strings

They were previously being ignored by the parser. This patch causes them to be saved.

commitc712ddb732b3ddffe8ba08a36d4f97fe478d3e1b authorDavid Raymond Christiansen <david@davidchristiansen.dk> dateSun 16 Feb 2014, 18:58 (13 years ago) parent2c9a945
3 files changed+26−8
src/Idris/ParseData.hs+1−1 src/Idris/ParseHelpers.hs+23−6 src/Idris/Parser.hs+2−1
src/Idris/ParseData.hs+1−1
@@ -182,7 +182,7 @@ simpleConstructor syn
182182 fc <- getFC
183183 args <- many (do notEndApp
184184 simpleExpr syn)
185− doc <- option "" (docComment '^')
185+ doc <- option "" (try $ docComment '^')
186186 return (doc, cn, args, fc, [])
187187 <?> "constructor"
188188
src/Idris/ParseHelpers.hs+23−6
@@ -78,7 +78,10 @@ isDocCommentMarker _ = False
7878 -}
7979singleLineComment :: MonadicParsing m => m ()
8080singleLineComment = try (string "--" *> eol *> pure ())
81− <|> string "--" *> satisfy (not . isDocCommentMarker) *> many (satisfy (not . isEol)) *> eol *> pure ()
81+ <|> try (string "--" *> many simpleWhiteSpace *>
82+ satisfy (not . isDocCommentMarker) *>
83+ many (satisfy (not . isEol)) *>
84+ eol *> pure ())
8285 <?> ""
8386
8487{- | Consumes a multi-line comment
@@ -122,12 +125,26 @@ multiLineComment = try (string "{-" *> (string "-}") *> pure ())
122125@
123126 -}
124127docComment :: MonadicParsing m => Char -> m String
125−docComment marker | isDocCommentMarker marker = do dc <- docComment' marker; return (T.unpack $ T.strip $ T.pack dc)
126− | otherwise = fail "internal error: tried to parse a documentation comment with invalid marker"
128+docComment marker | isDocCommentMarker marker = do dc <- docComment' marker
129+ return (T.unpack $ T.strip $ T.pack dc)
130+ | otherwise = fail "internal error: tried to parse a documentation comment with invalid marker"
127131 where docComment' :: MonadicParsing m => Char -> m String
128− docComment' marker = string "--" *> char marker *> many (satisfy (not . isEol)) <* eol
129− <|> string "{-" *> char marker *> (manyTill anyChar (try (string "-}")) <?> "end of comment")
130− <?> ""
132+ docComment' marker = (do string "--"
133+ many (satisfy isSpace)
134+ char marker
135+ res <- many (satisfy (not . isEol))
136+ eol
137+ rest <- many (do string "--"
138+ stuff <- many (satisfy (not . isEol))
139+ eol
140+ return stuff)
141+ someSpace
142+ return (res ++ concat rest))-- ++ concat rest))
143+ <|> (do string "{-"
144+ many (satisfy isSpace)
145+ char marker
146+ (manyTill anyChar (try (string "-}")) <?> "end of comment"))
147+ <?> ""
131148
132149-- | Parses some white space
133150whiteSpace :: MonadicParsing m => m ()
src/Idris/Parser.hs+2−1
@@ -312,9 +312,10 @@ fnDecl syn = try (do notEndBlock
312312fnDecl' :: SyntaxInfo -> IdrisParser PDecl
313313fnDecl' syn = checkFixity $
314314 do (doc, fc, opts', n, acc) <- try (do
315− doc <- option "" (docComment '|')
316315 pushIndent
317316 ist <- get
317+ doc <- option "" (docComment '|')
318+ ist <- get
318319 let initOpts = if default_total ist
319320 then [TotalFn]
320321 else []