Skip to content

Instantly share code, notes, and snippets.

@PollRobots
Created January 18, 2013 04:04
Show Gist options
  • Save PollRobots/4562262 to your computer and use it in GitHub Desktop.
Save PollRobots/4562262 to your computer and use it in GitHub Desktop.
let printPeg expr =
let rec pegToString = function
| Terminal x -> "\"" + x + "\""
| NonTerminal x -> x
| Epsilon -> "<epsilon>"
| Sequence x -> List.map pegToString >> List.reduce (fun a b -> a + " " + b) <| x
| Choice x -> List.map pegToString >> List.reduce (fun a b -> a + " / " + b) <| x
| ZeroOrMore x -> pegToString x + "*"
| OneOrMore x -> pegToString x + "+"
| Optional x -> pegToString x + "?"
| And x -> "&" + pegToString x
| Not x -> "!" + pegToString x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment