Skip to content

Instantly share code, notes, and snippets.

@menduz

menduz/clojure.ebnf

Created Aug 19, 2019
Embed
What would you like to do?
{ws=explicit}
Document ::= WS* Forms EOF {ws=implicit}
Form ::= (&"(" List | &"[" Vector | &"{" Map| &"#{" Set| &"'" Quote| &"`" Backtick| &"@" Deref| &"~@" UnquoteSplicing| &"~" Unquote| &"#(" Lambda| !';' Symbol| &":" Keyword | Literal | Discard | Dispatch | Regex) {pin=1,fragment=true}
Forms ::= (Form WS* | Comment WS*)* {fragment=true}
List ::= OPEN_PAREN WS* Forms? WS* CLOSE_PAREN {pin=1,recoverUntil=CLOSE_PAREN}
Vector ::= OPEN_ARRAY WS* Forms? WS* CLOSE_ARRAY {pin=1,recoverUntil=CLOSE_ARRAY}
Map ::= OPEN_BRACKET WS* Forms? WS* CLOSE_BRACKET {pin=1,recoverUntil=CLOSE_BRACKET}
Set ::= "#{" WS* Forms? WS* "}" {pin=1,recoverUntil=CLOSE_BRACKET}
Quote ::= "'" Form {pin=1}
Backtick ::= "`" Form {pin=1}
Deref ::= "@" Form {pin=1}
Lambda ::= "#(" WS* Forms? WS* ")" {pin=1,recoverUntil=CLOSE_ARRAY}
Discard ::= "#_" Form {pin=1}
Dispatch ::= "#" Symbol WS* Form {pin=2}
Regex ::= "#" String {pin=2}
UnquoteSplicing ::= "~@" Form {pin=1}
Unquote ::= "~" Form {pin=1}
Literal ::= PostfixNumber | String | ParamName {fragment=true}
PostfixNumber ::= (HexLiteral | Number) Symbol? {pin=1,simplifyWhenOneChildren=true}
Number ::= !('0x') ("0" | [1-9] [0-9]*) ("." [0-9]+)? (("e" | "E") ( "-" | "+" )? ("0" | [1-9] [0-9]*))? {pin=2}
NegNumber ::= '-'? Number {pin=2}
HexLiteral ::= "0x" [0-9A-Fa-f]+ {pin=1}
String ::= '"' (!'"' [#x0-#xFFFF])* '"'
Keyword ::= ':' SYMBOL_REST* {pin=1}
Symbol ::= NOT_SYMBOL_START SYMBOL_REST* '#'? {pin=1}
ParamName ::= '%' ([1-9][0-9]*)? {pin=1}
NOT_SYMBOL_START ::= !([0-9^`'"#~@:%;,]|'['|'{'|'('|')'|'}'|']'|[#x20#x09#x0A#x0D]) [#x00-#xFFFF]
SYMBOL_REST ::= !([`'"#~@:%;,]|'['|'{'|'('|')'|'}'|']'|[#x20#x09#x0A#x0D]) [#x00-#xFFFF]
Comment ::= ';' (![#x0A#x0D] [#x00-#xFFFF])* (EOL|EOF)
OPEN_PAREN ::= '('
CLOSE_PAREN ::= ')'
OPEN_ARRAY ::= '['
CLOSE_ARRAY ::= ']'
OPEN_BRACKET ::= '{'
CLOSE_BRACKET ::= '}'
WS ::= [#x20#x09#x0A#x0D,]+ {fragment=true}
EOL ::= [#x0A#x0D]+
NEW_LINE ::= [#x20#x09]* (EOL | Comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.