callmekohei's blog

callmekoheiのひとりごと

FParsecのメモ

たんなる雑記メモですっ

#r @"./packages/FParsec/lib/portable-net45+netcore45+wpa81+wp8/FParsecCS.dll"
#r @"./packages/FParsec/lib/portable-net45+netcore45+wpa81+wp8/FParsec.dll"
open FParsec

"hello world" |> run (many letter) |> printfn "%A"
/// Success: ['h'; 'e'; 'l'; 'l'; 'o']

"hello world" |> run (manyChars letter) |> printfn "%A"
/// Success: "hello"

"hello world" |> run ( sepBy (manyChars letter) (pchar ' ')) |> printfn "%A"
/// Success: ["hello"; "world"]

"hello, world"
|> run (sepBy ( manyChars letter ) ( pstring "," .>> spaces ))
|> fun x -> match x with Success (lst,_,_) -> lst | _ -> []
|> printfn "%A"
/// ["hello"; "world"]

"hello00 world99"
|> run (sepBy (manyChars (letter <|> digit)) (pchar ' ')) |> printfn "%A"
/// Success: ["hello00"; "world99"]

"hello00 world99"
|> run (sepBy ( (manyChars letter) .>> (manyChars digit) ) (pchar ' ')) |> printfn "%A"
/// Success: ["hello"; "world"]