-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrl.sable
556 lines (416 loc) · 13.4 KB
/
drl.sable
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
Package drlc;
Helpers
all = [0 .. 127];
digit = ['0' .. '9'];
letter = [['a' .. 'z'] + ['A' .. 'Z']];
decimal_integer = (digit | '_')* digit (digit | '_')*;
binary_digit = '0' | '1';
binary_integer = ('0b' | '0B') (binary_digit | '_')* binary_digit (binary_digit | '_')*;
octal_digit = ['0' .. '7'];
octal_integer = ('0o' | '0O') (octal_digit | '_')* octal_digit (octal_digit | '_')*;
hexadecimal_digit = [digit + [['a' .. 'f'] + ['A' .. 'F']]];
hexadecimal_integer = ('0x' | '0X') (hexadecimal_digit | '_')* hexadecimal_digit (hexadecimal_digit | '_')*;
integer = decimal_integer | binary_integer | octal_integer | hexadecimal_integer;
lf = 10;
cr = 13;
eol = lf | cr lf?;
apostrophe = 39;
quote = 34;
hex_escape = 'x' hexadecimal_digit hexadecimal_digit;
escape_char = '\' ('0' | 't' | 'b' | 'n' | 'r' | 'f' | apostrophe | quote | '\' | hex_escape);
c_char = [all - [apostrophe + ['\' + [lf + cr]]]] | escape_char;
s_char = [all - [quote + ['\' + [lf + cr]]]] | escape_char;
s_char_sequence = s_char*;
not_eol = [all - [lf + cr]];
not_star = [all - '*'];
not_star_slash = [not_star - '/'];
line_comment = '//' not_eol* eol?;
block_comment = '/*' not_star* '*'+ (not_star_slash not_star* '*'+)* '/';
Tokens
path_separator = '::';
arrow = '->';
l_par = '(';
r_par = ')';
l_bracket = '[';
r_bracket = ']';
l_brace = '{';
r_brace = '}';
comma = ',';
colon = ':';
semicolon = ';';
full_stop = '.';
question_mark = '?';
equals = '=';
plus_equals = '+=';
and_equals = '&=';
or_equals = '|=';
xor_equals = '^=';
minus_equals = '-=';
left_shift_equals = '<<=';
right_shift_equals = '>>=';
left_rotate_equals = '<<<=';
right_rotate_equals = '>>>=';
multiply_equals = '*=';
divide_equals = '/=';
remainder_equals = '%=';
logical_and = '&&';
logical_or = '||';
equal_to = '==';
not_equal_to = '!=';
less_than = '<';
less_or_equal = '<=';
more_than = '>';
more_or_equal = '>=';
plus = '+';
and = '&';
or = '|';
xor = '^';
minus = '-';
left_shift = '<<';
right_shift = '>>';
left_rotate = '<<<';
right_rotate = '>>>';
multiply = '*';
divide = '/';
remainder = '%';
not = '!';
mod = 'mod';
use = 'use';
root = 'root';
super = 'super';
self = 'self';
fn = 'fn';
alias = 'alias';
struct = 'struct';
const = 'const';
let = 'let';
as = 'as';
static = 'static';
mut = 'mut';
conditional_branch_keyword = 'if' | 'unless';
else = 'else';
loop = 'loop';
conditional_iterative_keyword = 'while' | 'until';
do = 'do';
exit = 'exit';
return = 'return';
continue = 'continue';
break = 'break';
sizeof = 'sizeof';
null_value = 'null';
bool_value = 'false' | 'true';
name = letter (digit | letter | '_')*;
int_value = integer ('I' | 'i');
nat_value = integer ('N' | 'n');
word_value = integer;
char_value = apostrophe c_char apostrophe;
string_literal = quote s_char_sequence quote;
blank = (' ' | 9 | 11 | eol)+;
comment = line_comment | block_comment;
Ignored Tokens
blank,
comment;
Productions
module =
static_section*;
static_section =
{module_declaration} module_declaration |
{module_definition} module_definition |
{use_declaration} use_declaration |
{function_definition} function_definition |
{type_alias_definition} type_alias_definition |
{struct_definition} struct_definition |
{constant_definition} constant_definition |
{variable_declaration} variable_declaration |
{empty_section} empty_section;
runtime_section =
{static_section} static_section |
{scoped_section} scoped_section |
{expression_statement} expression_statement |
{conditional_section} conditional_section |
{iterative_section} iterative_section;
/* SECTION SPECIFICATIONS */
module_declaration =
mod name semicolon;
module_definition =
mod name l_brace module r_brace;
use_declaration =
use use_tree semicolon;
use_tree =
{nested} path_prefix* l_brace use_tree_list? r_brace |
{wildcard} path_prefix* multiply |
{leaf} path_prefix* path_segment use_alias?;
path_prefix =
path_segment path_separator;
use_tree_list =
use_tree use_tree_list_tail* comma?;
use_tree_list_tail =
comma use_tree;
use_alias =
as name;
function_definition =
fn name l_par declarator_list? r_par return_type? l_brace scoped_body r_brace;
type_alias_definition =
alias name equals type semicolon;
struct_definition =
struct name l_brace declarator_list? r_brace;
constant_definition =
const name type_annotation? equals expression semicolon;
variable_declaration =
{excluding_initialization} let declarator semicolon |
{including_initialization} let declarator equals expression semicolon;
empty_section =
semicolon;
scoped_section =
l_brace scoped_body r_brace;
expression_statement =
expression semicolon;
conditional_section =
conditional_branch_keyword brace_expression l_brace scoped_body r_brace else_section?;
else_section =
{excluding_branch} else l_brace scoped_body r_brace |
{including_branch} else conditional_section;
iterative_section =
{loop} label? loop l_brace scoped_body r_brace |
{conditional} label? conditional_iterative_keyword brace_expression l_brace scoped_body r_brace |
{do_conditional} label? do l_brace scoped_body r_brace conditional_iterative_keyword expression semicolon;
scoped_body =
runtime_section* stop_statement?;
stop_statement =
{exit} exit expression? semicolon dead_section* |
{return} return expression? semicolon dead_section* |
{continue} continue name? semicolon dead_section* |
{break} break name? semicolon dead_section*;
dead_section =
{dead0} runtime_section |
{dead1} exit expression? semicolon |
{dead2} return expression? semicolon |
{dead3} continue name? semicolon |
{dead4} break name? semicolon;
/* COMPONENT SPECIFICATIONS */
type =
{raw} raw_type |
{address_of} and mut? type |
{double_address_of} logical_and mut? type;
raw_type =
{nominal} path |
{array} l_bracket type semicolon expression r_bracket |
{tuple} l_par tuple_type_list? r_par |
{function} fn l_par type_list? r_par return_type?;
tuple_type_list =
tuple_type_list_head+ type?;
tuple_type_list_head =
type comma;
type_list =
type type_list_tail* comma?;
type_list_tail =
comma type;
return_type =
arrow type;
type_annotation =
colon type;
path =
path_segment path_tail*;
path_tail =
path_separator path_segment;
path_segment =
{root} root |
{super} super |
{self} self |
{name} name;
declarator =
variable_modifier* name type_annotation?;
variable_modifier =
{static} static |
{mut} mut;
declarator_list =
declarator declarator_list_tail* comma?;
declarator_list_tail =
comma declarator;
label =
name colon;
expression =
{prioritized} assignment_expression |
{closure} closure_declarator_list closure_body;
closure_declarator_list =
{standard} [l_or]:or declarator_list? [r_or]:or |
{logical_or} logical_or;
closure_body =
{expression} expression |
{block} return_type? l_brace scoped_body r_brace;
assignment_expression =
{prioritized} ternary_expression |
{assignment} unary_expression assignment_op expression;
ternary_expression =
{prioritized} logical_expression |
{ternary} logical_expression question_mark expression colon ternary_expression;
logical_expression =
{prioritized} equality_expression |
{binary} logical_expression logical_binary_op equality_expression;
equality_expression =
{prioritized} comparative_expression |
{binary} equality_expression equality_binary_op comparative_expression;
comparative_expression =
{prioritized} additive_expression |
{binary} comparative_expression comparative_binary_op additive_expression;
additive_expression =
{prioritized} multiplicative_expression |
{binary} additive_expression additive_binary_op multiplicative_expression;
multiplicative_expression =
{prioritized} shift_expression |
{binary} multiplicative_expression multiplicative_binary_op shift_expression;
shift_expression =
{prioritized} cast_expression |
{binary} shift_expression shift_binary_op cast_expression;
cast_expression =
{prioritized} unary_expression |
{cast} unary_expression as type;
unary_expression =
{prioritized} suffix_expression |
{unary} unary_op unary_expression |
{dereference} multiply unary_expression |
{address_of} and mut? unary_expression |
{double_address_of} logical_and mut? unary_expression;
suffix_expression =
{prioritized} call_expression |
{index} suffix_expression l_bracket expression r_bracket |
{member} suffix_expression full_stop member |
{method} suffix_expression full_stop path l_par expression_list? r_par;
call_expression =
{prioritized} compound_expression |
{call} call_expression l_par expression_list? r_par;
compound_expression =
{parentheses} parentheses_expression |
{primary} primary_expression |
{array_list} l_bracket expression_list? r_bracket |
{array_repeat} l_bracket expression semicolon [constant]:expression r_bracket |
{tuple} l_par tuple_expression_list? r_par |
{struct} path l_brace struct_expression_list? r_brace;
parentheses_expression =
l_par expression r_par;
primary_expression =
{scalar} scalar |
{path} path;
expression_list =
expression expression_list_tail* comma?;
expression_list_tail =
comma expression;
tuple_expression_list =
tuple_expression_list_head+ expression?;
tuple_expression_list_head =
expression comma;
struct_expression_list =
{basic} expression_list |
{labelled} labelled_expression_list;
labelled_expression_list =
labelled_expression labelled_expression_list_tail* comma?;
labelled_expression_list_tail =
comma labelled_expression;
labelled_expression =
label expression;
member =
{name} name |
{word} word_value;
scalar =
{null} null_value |
{bool} bool_value |
{int} int_value |
{nat} nat_value |
{word} word_value |
{char} char_value |
{string} string_literal |
{sizeof} sizeof type;
brace_expression =
{prioritized} brace_assignment_expression |
{closure} closure_declarator_list brace_expression;
brace_assignment_expression =
{prioritized} brace_ternary_expression |
{assignment} brace_unary_expression assignment_op brace_expression;
brace_ternary_expression =
{prioritized} brace_logical_expression |
{ternary} brace_logical_expression question_mark expression colon brace_ternary_expression;
brace_logical_expression =
{prioritized} brace_equality_expression |
{binary} brace_logical_expression logical_binary_op brace_equality_expression;
brace_equality_expression =
{prioritized} brace_comparative_expression |
{binary} brace_equality_expression equality_binary_op brace_comparative_expression;
brace_comparative_expression =
{prioritized} brace_additive_expression |
{binary} brace_comparative_expression comparative_binary_op brace_additive_expression;
brace_additive_expression =
{prioritized} brace_multiplicative_expression |
{binary} brace_additive_expression additive_binary_op brace_multiplicative_expression;
brace_multiplicative_expression =
{prioritized} brace_shift_expression |
{binary} brace_multiplicative_expression multiplicative_binary_op brace_shift_expression;
brace_shift_expression =
{prioritized} brace_cast_expression |
{binary} brace_shift_expression shift_binary_op brace_cast_expression;
brace_cast_expression =
{prioritized} brace_unary_expression |
{cast} brace_unary_expression as type;
brace_unary_expression =
{prioritized} brace_suffix_expression |
{unary} unary_op brace_unary_expression |
{dereference} multiply brace_unary_expression |
{address_of} and mut? brace_unary_expression |
{double_address_of} logical_and mut? brace_unary_expression;
brace_suffix_expression =
{prioritized} brace_call_expression |
{index} brace_suffix_expression l_bracket expression r_bracket |
{member} brace_suffix_expression full_stop member |
{method} brace_suffix_expression full_stop path l_par expression_list? r_par;
brace_call_expression =
{prioritized} brace_compound_expression |
{call} brace_call_expression l_par expression_list? r_par;
brace_compound_expression =
{parentheses} parentheses_expression |
{primary} primary_expression |
{array_list} l_bracket expression_list? r_bracket |
{array_repeat} l_bracket expression semicolon [constant]:expression r_bracket |
{tuple} l_par tuple_expression_list? r_par;
/* OPERATION SPECIFICATIONS */
assignment_op =
{equals} equals |
{plus} plus_equals |
{and} and_equals |
{or} or_equals |
{xor} xor_equals |
{minus} minus_equals |
{multiply} multiply_equals |
{divide} divide_equals |
{remainder} remainder_equals |
{left_shift} left_shift_equals |
{right_shift} right_shift_equals |
{left_rotate} left_rotate_equals |
{right_rotate} right_rotate_equals;
logical_binary_op =
{logical_and} logical_and |
{logical_or} logical_or;
equality_binary_op =
{equal_to} equal_to |
{not_equal_to} not_equal_to;
comparative_binary_op =
{less_than} less_than |
{less_or_equal} less_or_equal |
{more_than} more_than |
{more_or_equal} more_or_equal;
additive_binary_op =
{plus} plus |
{and} and |
{or} or |
{xor} xor |
{minus} minus;
multiplicative_binary_op =
{multiply} multiply |
{divide} divide |
{remainder} remainder;
shift_binary_op =
{left_shift} left_shift |
{right_shift} right_shift |
{left_rotate} left_rotate |
{right_rotate} right_rotate;
unary_op =
{minus} minus |
{not} not;