-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree-sitter-janet.ebnf
212 lines (156 loc) · 3.66 KB
/
tree-sitter-janet.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//
// From tree-sitter-janet/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
source_file ::=
_expr*
line_comment ::=
( '#' '.'* )
_expr ::=
_literals
| _identifier
| _special_forms
| _shorthand
| _specials
| array
| sqr_array
| tuple
| sqr_tuple
| struct
| table
| peg_set
tuple ::=
'(' _expr* ')'
sqr_tuple ::=
'[' _expr* ']'
array ::=
'@(' _expr* ')'
sqr_array ::=
'@[' _expr* ']'
struct ::=
'{' _struct_tables_commom* '}'
table ::=
'@{' _struct_tables_commom* '}'
_struct_tables_commom ::=
_expr _expr
peg_set ::=
'(' 'set' ( str_literal | long_str_literal | quote | short_quote ) ')'
_special_forms ::=
def
| var
| quote
| splice
| quasiquote
| unquote
| break
| set
| if
| do
| while
| fn
| upscope
def ::=
'(' 'def' _expr metadata* _expr ')'
var ::=
'(' 'var' _expr metadata* _expr ')'
quote ::=
'(' 'quote' _expr? ')'
splice ::=
'(' 'splice' _expr? ')'
quasiquote ::=
'(' 'quasiquote' _expr? ')'
unquote ::=
'(' 'unquote' _expr? ')'
break ::=
'(' 'break' _expr? ')'
set ::=
'(' 'set' _expr _expr ')'
if ::=
'(' 'if' _expr _expr _expr? ')'
do ::=
'(' 'do' body? ')'
while ::=
'(' 'while' _expr _expr* ')'
fn ::=
'(' 'fn' _name? _parameters body? ')'
upscope ::=
'(' 'upscope' body? ')'
_parameters ::=
_identifier | quote | splice | quasiquote | unquote | short_quote | short_splice | short_quasiquote | short_unquote | parameters | tuple_parameters
parameters ::=
'[' _expr* ( ( variadic_marker | optional_marker | keys_marker ) _expr* )? ']'
tuple_parameters ::=
'(' _expr* ( ( variadic_marker | optional_marker | keys_marker ) _expr* )? ')'
variadic_marker ::=
'&'
optional_marker ::=
'&opt'
keys_marker ::=
'&keys'
_shorthand ::=
short_quote
| short_splice
| short_quasiquote
| short_unquote
| short_fn
short_quote ::=
"'" _expr
short_splice ::=
';' _expr
short_quasiquote ::=
'~' _expr
short_unquote ::=
',' _expr
short_fn ::=
'|' _expr
_specials ::=
extra_defs
extra_defs ::=
'(' ( 'defn' | 'defn-' | 'varfn' | 'varfn-' | 'defmacro' | 'defmacro-' ) _name metadata* _parameters body? ')'
_literals ::=
bool_literal
| nil_literal
| number_literal
| str_literal
| long_str_literal
| buffer_literal
| long_buffer_literal
str_literal ::=
( '"' ( [^"\]+ | '\'[^xu] | '\u'[0-9a-fA-F]'{4}' | '\u{'[0-9a-fA-F]+'}' | '\x'[0-9a-fA-F]'{2}' )* '"' )
long_str_literal ::=
_long_str
buffer_literal ::=
( '@"' ( [^"\]+ | '\'[^xu] | '\u'[0-9a-fA-F]'{4}' | '\u{'[0-9a-fA-F]+'}' | '\x'[0-9a-fA-F]'{2}' )* '"' )
long_buffer_literal ::=
_long_buffer
number_literal ::=
[-+]?([0-9][_0-9]*|[0-9][_0-9]*'.'[_0-9]*|'.'[_0-9]+)([eE&][+-]?[0-9]+)?
| [-+]?'0x'([_0-9a-fA-F]+|[_0-9a-fA-F]+'.'[_0-9a-fA-F]*|'.'[_0-9a-fA-F]+)('&'[+-]?[0-9a-fA-F]+)?
| [-+]?[0-9][0-9]?'r'([_a-zA-Z_]+|[_a-zA-Z_]+'.'[_a-zA-Z_]*|'.'[_a-zA-Z_]+)('&'[+-]?[a-zA-Z_]+)?
bool_literal ::=
'true'
| 'false'
nil_literal ::=
'nil'
escape_sequence ::=
( '\'[^xu] | '\u'[0-9a-fA-F]'{4}' | '\u{'[0-9a-fA-F]+'}' | '\x'[0-9a-fA-F]'{2}' )
metadata ::=
keyword | str_literal | long_str_literal | struct | quote | splice | quasiquote | unquote | short_quote | short_splice | short_quasiquote | short_unquote
_name ::=
_identifier | quote | splice | quasiquote | unquote | short_quote | short_splice | short_quasiquote | short_unquote
doc_str ::=
str_literal
| long_str_literal
body ::=
_expr+
_identifier ::=
symbol
| keyword
keyword ::=
':'[^({#x5B"'|`;,~#x5D} #x09#x0A#x0B#x0C#x0D)]*
symbol ::=
[^({#x5B"'|`;,~#x5D} #x09#x0A#x0B#x0C#x0D):][^({#x5B"'|`;,~#x5D} #x09#x0A#x0B#x0C#x0D)]*