我有这么多:
comment :: GenParser Char st ()
comment =
(string "--" >> manyTill anyChar newline >> spaces >> return ()) <|>
(string "/*" >> manyTill anyChar (string "*/") >> spaces >> return ())
eatComments :: GenParser Char st String
eatComments = do
xs <- many (do
optional comment
x <- manyTill anyChar (try comment)
return x)
return $ intercalate " " xs
如果输入以注释结尾,则此方法有效,但如果以其他内容结尾,则失败。在这种情况下,错误消息就像
No match (line 13, column 1):
unexpected end of input
expecting "--" or "/*"
因此,解析器正在寻找eof
到达时的注释。我需要一些帮助来找到正确的组合器,我需要在所有可能的情况下吃掉所有的评论。