別の文字列から単純な文字列を解析するにはどうすればよいですか。
FParsec チュートリアルには、次のコードが示されています。
let str s = pstring s
let floatBetweenBrackets = str "[" >>. pfloat .>> str "]"
バケット間のフロートを解析したくはありませんが、式内の文字列を解析したくありません。
通り。お気に入り:
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