我正在实现一个解析器,它使用 FParsec 将注释视为空白。看起来它需要一个简单的解析器转换,但我还不知道如何实现它。
这是我试图进行类型检查的代码 -
let whitespaceTextChars = " \t\r\n"
/// Read whitespace characters.
let whitespaceText = many (anyOf whitespaceTextChars)
/// Read a line comment.
let lineComment = pchar lineCommentChar >>. restOfLine true
/// Skip any white space characters.
let skipWhitespace = skipMany (lineComment <|> whitespaceText)
/// Skip at least one white space character.
let skipWhitespace1 = skipMany1 (lineComment <|> whitespaceText)
错误出现在两个参数的第二个参数上<|>
运营商(超过whitespaceText
)。错误是 -
Error 1 Type mismatch. Expecting a Parser<string,'a> but given a Parser<char list,'a> The type 'string' does not match the type 'char list'
Error 2 Type mismatch. Expecting a Parser<string,'a> but given a Parser<char list,'a> The type 'string' does not match the type 'char list'
看来我需要转换一个Parser<char list, 'a>
to a Parser<string, 'a>
。或者,因为我只是跳过它们,所以我可以将它们都转换为Parser<unit, 'a>
。但是,我不知道如何编写该代码。它是一些简单的 lambda 表达式吗?
Cheers!
let whitespaceText = manyChars (anyOf whitespaceTextChars)
or
let whitespaceText = many (anyOf whitespaceTextChars) |>> fun cs -> System.String (Array.ofList cs)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)