如何从另一个字符串中解析出一个简单的字符串。
在 FParsec 教程中,给出了以下代码:
let str s = pstring s
let floatBetweenBrackets = str "[" >>. pfloat .>> str "]"
我不想解析 backets 之间的浮点数,而是解析表达式中的字符串。
某事。像:
Location := LocationKeyWord path EOL
给定一个辅助函数
let test p s =
match run p s with
| Success(result,_,_) -> printfn "%A" result
| Failure(message,_,_) -> eprintfn "%A" message
还有一个解析器功能:let pLocation = ...
当我打电话test pLocation "Location /root/somepath"
它应该打印"/root/somepath"
我的第一次尝试是修改教程代码如下:
let pLocation = str "Location " >>. str
但这给了我一个错误:
Error 244 Typeerror. Expected:
Parser<'a,'b>
Given:
string -> Parser<string,'c>
The type CharStream<'a> doesn't match with the Type string