Last active
January 18, 2022 19:10
-
-
Save canac/7946f87c7a2ade69a6e502040bcdec55 to your computer and use it in GitHub Desktop.
nearly.js grammar
This file contains hidden or 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
@{% | |
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