我正在尝试使用FParsec从s表达式语言解析lisp样式的注释.我在前一个线程中解析单行注释得到了一些帮助 - 如何将FParsec解析器转换为解析空格
虽然这已经解决了,但我仍然需要解析多行注释.这是当前的代码 -
/// Read whitespace character as a string.
let spaceAsStr = anyOf whitespaceChars |>> fun chr -> string chr
/// Read a line comment.
let lineComment = pchar lineCommentChar >>. restOfLine true
/// Read a multiline comment.
/// TODO: make multiline comments nest.
let multilineComment =
between
(pstring openMultilineCommentStr)
(pstring closeMultilineCommentStr)
(charsTillString closeMultilineCommentStr true System.Int32.MaxValue)
/// Read whitespace text.
let whitespace =
lineComment <|>
multilineComment <|>
spaceAsStr
/// Skip any white space characters.
let skipWhitespace = …Run Code Online (Sandbox Code Playgroud)