Skip to content

Instantly share code, notes, and snippets.

@canac
Last active January 18, 2022 19:10
Show Gist options
  • Save canac/7946f87c7a2ade69a6e502040bcdec55 to your computer and use it in GitHub Desktop.
Save canac/7946f87c7a2ade69a6e502040bcdec55 to your computer and use it in GitHub Desktop.
nearly.js grammar
@{%
const moo = require("moo");
const lexer = moo.compile({
ws: / +/,
label: /"[\w\d ]+?"/,
not: '!',
and: '&&',
or: '||',
lparen: '(',
rparen: ')',
});
%}
@lexer lexer
main -> binary
parentheses -> %lparen binary %rparen | %label
unary -> %not parentheses
| parentheses
binary -> binary %ws %and %ws unary
| binary %ws %or %ws unary
| unary
ws -> %ws {% x => null %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment