-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree-sitter-r.ebnf
212 lines (152 loc) · 4.06 KB
/
tree-sitter-r.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-r/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
program ::=
( _expression ( '\n' | ';' )? )*
_definition ::=
function_definition
| lambda_function
function_definition ::=
'function' formal_parameters _expression
lambda_function ::=
'\\' formal_parameters _expression
if ::=
'if' '(' _expression ')' _expression ( 'else' _expression )?
while ::=
'while' '(' _expression ')' _expression
repeat ::=
'repeat' _expression
for ::=
'for' '(' identifier 'in' _expression ')' _expression
switch ::=
'switch' '(' _expression ',' arguments ')'
formal_parameters ::=
'(' ( _formal_parameter ( ',' _formal_parameter )* ','? )? ')'
default_parameter ::=
identifier '=' _expression
_formal_parameter ::=
identifier
| default_parameter
| dots
block ::=
'{' _expression* '}'
arguments ::=
( _argument | ',' )+
default_argument ::=
( identifier | string | dots ) '=' _expression?
_argument ::=
_expression | default_argument
call ::=
_expression '(' arguments? ')'
_assignment ::=
equals_assignment
| left_assignment
| left_assignment2
| right_assignment
| super_assignment
| super_right_assignment
left_assignment ::=
_expression '<-' _expression
left_assignment2 ::=
_expression ':=' _expression
equals_assignment ::=
_expression '=' _expression
super_assignment ::=
_expression '<<-' _expression
super_right_assignment ::=
_expression '->>' _expression
right_assignment ::=
_expression '->' _expression
brace_list ::=
'{' ( _expression ( '\n' | ';' )? )* '}'
paren_list ::=
'(' _expression* ')'
subset ::=
_expression '[' arguments? ']'
subset2 ::=
_expression '[[' arguments? ']]'
dollar ::=
_expression '$' ( identifier | string )
slot ::=
_expression '@' identifier
namespace_get ::=
identifier '::' identifier
namespace_get_internal ::=
identifier ':::' identifier
help ::=
_expression '?' _expression
dots ::=
'...'
placeholder ::=
'_'
pipe_placeholder_argument ::=
identifier '=' placeholder
_pipe_rhs_argument ::=
_expression | default_argument | pipe_placeholder_argument
pipe_rhs_arguments ::=
( _pipe_rhs_argument | ',' )+
pipe_rhs ::=
_expression '(' pipe_rhs_arguments? ')'
pipe ::=
_expression '|>' pipe_rhs
unary ::=
( '-' | '+' ) _expression
| '!' _expression
| '~' _expression
| '?' _expression
binary ::=
_expression ( '+' | '-' ) _expression
| _expression ( '*' | '/' ) _expression
| _expression '^' _expression
| _expression ( '<' | '>' | '<=' | '>=' | '==' | '!=' ) _expression
| _expression ( '||' | '|' ) _expression
| _expression ( '&&' | '&' ) _expression
| _expression special _expression
| _expression ':' _expression
| _expression '~' _expression
break ::=
'break'
next ::=
'next'
true ::=
'TRUE'
false ::=
'FALSE'
null ::=
'NULL'
inf ::=
'Inf'
nan ::=
'NaN'
na ::=
'NA'
| 'NA_character_'
| 'NA_complex_'
| 'NA_integer_'
| 'NA_real_'
_expression ::=
identifier | integer | float | complex | string | call | function_definition | lambda_function | _assignment | brace_list | paren_list | binary | unary | pipe | subset | subset2 | dollar | slot | namespace_get | namespace_get_internal | help | if | for | while | repeat | switch | break | next | true | false | null | inf | nan | na | dots
identifier ::=
[.\p{XID_Start}][._\p{XID_Continue}]*
| '`' ( [^`\#x0A]+|'\#x0D'?'#x0A' | escape_sequence )* '`'
integer ::=
( ( '0x' | '0X' ) [A-Fa-f0-9]+ | [0-9]+ ) 'L'
float ::=
[0-9]+ '.'? [0-9]+? ( [eE][\+-]? [0-9]+ )? | [0-9]+? '.' [0-9]+ ( [eE][\+-]? [0-9]+ )? | [0-9]+ [eE][\+-]? [0-9]+ | ( '0x' | '0X' ) [A-Fa-f0-9]+
complex ::=
float 'i'
comment ::=
'#' '.'*
string ::=
_raw_string_literal
| '"' ( [^"\#x0A]+|'\#x0D'?'#x0A' | escape_sequence )* '"'
| "'" ( [^'\#x0A]+|"\#x0D"?"#x0A" | escape_sequence )* "'"
special ::=
'%' ( [^%\#x0A]+|'\#x0D'?'#x0A' | escape_sequence )* '%'
escape_sequence ::=
( '\\' ( [^xu0-7] | [0-7]'{1,3}' | 'x'[0-9a-fA-F]'{2}' | 'u'[0-9a-fA-F]'{4}' | 'u{'[0-9a-fA-F]+'}' ) )