forked from mingodad/plgh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree-sitter-fennel.ebnf
111 lines (58 loc) · 4.66 KB
/
tree-sitter-fennel.ebnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Grammar originally from https://github.com/TravonteD/tree-sitter-fennel
Converted by excuting:
qjs json2ebnf.js
Then manualy fixing the problems reported by https://www.bottlecaps.de/rr/ui in a way to allow visualization (correctnes is not the priority now)
*/
program ::= ( ( _statement ) )*
_statement ::= ( require | function_call | _function | _expression | _variable_declaration | _iterator | _conditional | hash_function_definition | do_statement | comment )
_function ::= ( function_definition | lambda_definition )
_variable_declaration ::= ( let_definition | local_definition | var_definition | global_definition | set | tset )
_iterator ::= ( each | for | while )
_conditional ::= ( if_statement | when_statement | match_statement )
require ::= ( '(' 'require' ( ( field | string ) )* ')' )
do_statement ::= ( '(' 'do' ( _statement )* ')' )
when_statement ::= ( '(' 'when' ( _statement )* ')' )
if_statement ::= ( '(' 'if' ( _statement )* ')' )
match_statement ::= ( '(' 'match' ( _statement )* ')' )
each ::= ( '(' 'each' each_clause ( _statement )* ')' )
each_clause ::= ( '[' identifier identifier function_call ']' )
for ::= ( '(' 'for' for_clause ( _statement )* ')' )
for_clause ::= ( '[' identifier _statement _statement ( _statement )? ']' )
while ::= ( '(' 'while' ( _statement ) ( _statement )* ')' )
let_definition ::= ( '(' 'let' assignments ( _statement )* ')' )
local_definition ::= ( '(' 'local' ( assignment | multi_value_assignment ) ')' )
var_definition ::= ( '(' 'var' ( assignment | multi_value_assignment ) ')' )
global_definition ::= ( '(' 'global' ( assignment | multi_value_assignment ) ')' )
set ::= ( '(' 'set' ( assignment | multi_value_assignment ) ')' )
tset ::= ( '(' 'tset' ( ( table | identifier ) )? ( identifier | field | string ) ( _statement ) ')' )
assignments ::= ( '[' ( ( multi_value_assignment | assignment ) )* ']' )
assignment ::= ( ( identifier | field_expression ) _statement )
multi_value_assignment ::= ( value_list _statement )
value_list ::= ( '(' ( ( identifier | field_expression ) )* ')' )
hash_function_definition ::= ( ( '(' 'hashfn' ( _statement )* ')' ) | ( '#' ( function_call | identifier | sequential_table ) ) )
function_definition ::= ( '(' 'fn' _function_body ')' )
lambda_definition ::= ( '(' ( 'lambda' | 'λ' ) _function_body ')' )
_function_body ::= ( ( ( identifier ) )? parameters ( ( _statement )* ) )
parameters ::= ( '[' ( _expression )* ']' )
function_call ::= ( '(' ( ( field_expression | identifier | ( _operator ) | ( _keyword ) ) ) ( ( _statement )* )? ')' )
sequential_table ::= ( '[' ( _statement )* ']' )
table ::= ( '{' ( ( ( string | field | identifier ) _statement ) )* '}' )
_expression ::= ( field_expression | quoted_value | unquoted_value | number | field | identifier | string | table | sequential_table | boolean | nil | ( _keyword ) )
escape_character ::= ('\n'|'\"')
string ::= ( '"' ( ('\"')|([.]) )* '"' )
quoted_value ::= ( ( "'" | '`' ) _statement )
unquoted_value ::= ( ( ',' ) identifier )
field_expression ::= ( ( ( identifier | ( _keyword ) ) ( ( ( '.' identifier ) )+ ) ) )
_operator ::= ( _arithmetic_operator | _comparison_operator | _boolean_operator | _threading_macro | _misc_operator | ( colon ) )
_arithmetic_operator ::= ( '+' | '-' | '*' | '%' | '/' | '//' | '^' )
_comparison_operator ::= ( '>' | '<' | '>=' | '<=' | '=' | 'not=' )
_threading_macro ::= ( '->' | '->>' | '-?>' | '-?>>' )
_boolean_operator ::= ( 'and' | 'or' | 'not' )
_misc_operator ::= ( '..' | '.' | '...' )
boolean ::= ( 'true' | 'false' )
nil ::= ( 'nil' )
_keyword ::= ( '_ENV' | '_G' | '_VERSION' | 'arg' | 'assert' | 'collectgarbage' | 'coroutine' | 'debug' | 'dofile' | 'doto' | 'error' | 'eval-compiler' | 'gensym' | 'getmetatable' | 'import-macros' | 'in-scope?' | 'include' | 'ipairs' | 'list' | 'list?' | 'load' | 'loadfile' | 'loadstring' | 'macro' | 'macrodebug' | 'macroexpand' | 'macros' | 'multi-sym?' | 'next' | 'pairs' | 'package' | 'pcall' | 'print' | 'rawequal' | 'rawget' | 'rawlen' | 'rawset' | 'require-macros' | 'select' | 'sequence?' | 'setmetatable' | 'sym' | 'sym?' | 'table?' | 'tonumber' | 'tostring' | 'type' | 'unpack' | 'varg?' | 'xpcall' | 'string' | 'table' )
identifier ::= ([_\?A-Za-z][_\?\-A-Za-z0-9\!]*)|('$'([1-9])?)
number ::= ([-])?[0-9]+('.'[\d]+)?
comment ::= ';'[^\n]*