Skip to content

Instantly share code, notes, and snippets.

@PollRobots
Last active December 12, 2015 01:18
Show Gist options
  • Save PollRobots/4689911 to your computer and use it in GitHub Desktop.
Save PollRobots/4689911 to your computer and use it in GitHub Desktop.
// unary <- ([!&] unary) / (atom [*+?])?
let parseUnary _ = function
| Production [TerminalSymbol "!"; Parsed x] -> Parsed <| Not x
| Production [TerminalSymbol "&"; Parsed x] -> Parsed <| And x
| Production [Parsed x; TerminalSymbol "*"] -> Parsed <| ZeroOrMore x
| Production [Parsed x; TerminalSymbol "+"] -> Parsed <| OneOrMore x
| Production [Parsed x; TerminalSymbol "?"] -> Parsed <| Optional x
| Production [Parsed _ as x; EmptyMatch] -> x
| x -> unexpected x
let unaryRule = GrammarRule<Expression>(Choice [Sequence [TerminalOneOf "!&"; NonTerminal "unary"];
Sequence [NonTerminal "atom"; Optional(TerminalOneOf "*+?")]], parseUnary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment