How to parse comments with FParsec

前端 未结 1 1659
不知归路
不知归路 2021-01-12 04:37

I\'m attempting to parse lisp-style comments from an s-expression language with FParsec. I got a bit of help with parsing single-line comments in this previous thread - How

相关标签:
1条回答
  • 2021-01-12 04:53

    Try changing the bool argument for closeMultilineCommentStr to false

    (charsTillString closeMultilineCommentStr false System.Int32.MaxValue)
    

    Otherwise it will skip over the closeMultilineCommentStr string.

    To make it work with nested comments

    let rec multilineComment o=
        let ign x = charsTillString x false System.Int32.MaxValue
        between
            (pstring openMultilineCommentStr)
            (pstring closeMultilineCommentStr)
            (attempt (ign openMultilineCommentStr >>. multilineComment >>. ign closeMultilineCommentStr) <|> 
            ign closeMultilineCommentStr) <|o
    
    0 讨论(0)
提交回复
热议问题