Skip to content

Instantly share code, notes, and snippets.

@pdubroy
Last active January 13, 2016 15:24
Show Gist options
  • Save pdubroy/984ad6e3ecf181b1c15c to your computer and use it in GitHub Desktop.
Save pdubroy/984ad6e3ecf181b1c15c to your computer and use it in GitHub Desktop.
Ohm declarative binding syntax
// `ident <- env` means parse an identifier only if it exists in env.
Expr<env>
= LetExpr<env>
| WhereExpr<env>
| ident <- env
LetExpr<env>
= "letseq" LetSeqBindingsAndBody<env>
| "letrec" LetRecBindingsAndBody<env>
| "letpar" LetParBindingsAndBody<env>
// `ident -> env'` means parse an identifier, and add it to a new environment
// named `env'` which delegates to `env`.
LetSeqBindingsAndBody<env>
= ident -> env' "=" expr<env> "," LetSeqBindingsAndBody<env'>
| ident -> env' "=" expr<env> "in" Expr<env'>
LetRecBindingsAndBody<env>
= ident -> env' "=" expr<env'> "," LetRecBindingsAndBody<env'>
| ident -> env' "=" expr<env'> "in" Expr<env'>
LetParBindingsAndBody<env>
= ident -> env' "=" expr<env> "," LetParBindingsAndBody<env> // Uh oh, env' is never passed on...
| ident -> env' "=" expr<env> "in" Expr<env'>
WhereExpr<env>
= Expr<env'> "where" WhereSeqBindings<env> // This also doesn't work, as Expr needs the env produced by the deepest invocation of WhereSeqBindings
WhereSeqBindings = ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment