Last active
March 18, 2018 15:31
-
-
Save shanecharles/17d5c99208ea8333a4172db8502e3140 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "packages/FParsec/lib/net40-client/FParsecCS.dll" | |
#r "packages/FParsec/lib/net40-client/FParsec.dll" | |
open FParsec | |
type Operation = | |
| Spin of int | |
| Exchange of int * int | |
| Partner of char * char | |
type ParserState = unit | |
let pspin : Parser<Operation,ParserState> = | |
pchar 's' >>. pint32 |>> Spin | |
let pexchange = | |
pchar 'x' | |
>>. tuple2 (pint32 .>> pchar '/') pint32 | |
|>> Exchange | |
let ppartner = | |
pchar 'p' | |
>>. tuple2 (asciiLetter .>> pchar '/') asciiLetter | |
|>> Partner | |
let parseOperation = choice [ pspin; pexchange; ppartner ] | |
let parseOperations = run (sepBy parseOperation (pstring ",")) | |
"po/k,x4/0,s12,x7/6" |> parseOperations | |
// Success: [Partner ('o','k'); Exchange (4,0); Spin 12; Exchange (7,6)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment