1syntax! {
2 precedence: {
6 PREC_CLOSER = 6,
7 PREC_SEMICOLON = 8,
8 PREC_COMMA = 10,
9 PREC_CONTROL = 12,
10 PREC_LOOP_CLAUSE = 16,
11 PREC_COLLECTION = 56,
12 PREC_APPLICATION_RIGHT = 61,
13 PREC_APPLICATION = 62,
14 PREC_QUOTE = 74,
15 }
16
17 tokens {
21 [->] [<-] [=] [=>] { infix } (14, R)
22 [>>] { bin, aug } (14, R)
23 [<<] { bin, pref, aug } (18, L)
24 [|-] { bin, pref, aug } (20, L)
25 [===>] { bin, aug } (22, R)
26 [<===] { bin, pref } (22, R)
27 [<==>] { bin, aug } (24, R)
28 [==>] { bin, aug } (26, R)
29 [<==] { bin, pref } (26, R)
30 [or] { bin } (28, R)
31 [??] { bin, pref, aug } (28, R)
32 [xor] { bin } (30, R)
33 [and] { bin } (32, R)
34 [not] { pref } (34)
35 [!=] [=!=] [==] [===] { bin } (36, R)
36 [<] [<=] [>] [>=] [?] { bin, pref } (36, R)
37 [~] { bin, pref, aug } (36, R)
38 [||] { bin, aug } (38, L)
39 [:] { bin, aug } (40, R)
40 [|] { bin, aug } (42, L)
41 [^^] { bin, aug } (44, L)
42 [&] { bin, aug } (46, L)
43 [..] [..<] { bin, aug } (48, L)
44 [++] { bin, aug } (50, L)
45 [+] [-] { bin, pref, aug } (50, L)
46 ["·"] { bin, aug } (52, L)
47 [**] ["⊠"] ["⧢"] { bin, aug } (54, L)
48 [%] [/] [/ /] { bin, aug } (58, L)
49 [*] { bin, pref, aug } (58, L)
50 ["\\"] ["\\\\"] { bin, aug } (58, R)
51 [@] { bin, aug } (60, R)
52 [(*)] { post } (64)
53 [@@] [@@?] { bin, aug } (66, L)
54 [^*] [^~] [_*] [_~] { post } (68)
55 [#?] [.] [.?] { bin } (70, L)
56 [^<] [^<=] [^>] [^>=] { bin } (70, L)
57 [_<] [_<=] [_>] [_>=] { bin } (70, L)
58 [^] [^**] [_] [|_] { bin, aug } (70, L)
59 [#] { bin, pref } (70, L, 61)
60 [!] [^!] [_!] { post } (72)
61
62
63 [else] [then] [do] [list] [except] (12)
64 [when] [of] [in] [from] [to] (16)
65 [break] [continue] [return] [catch] [throw] [trap]
66 [if] [while] [try]
67 [TEST] [time] [timing] [elapsedTime] [elapsedTiming]
68 [breakpoint] [profile] [shield] [step] [finish]
69 (PREC_APPLICATION, PREC_CONTROL)
70 [for] [new]
71 (PREC_APPLICATION, PREC_LOOP_CLAUSE)
72 [symbol] [global] [local] [threadLocal] [threadVariable]
73 (PREC_APPLICATION, PREC_QUOTE)
74 [;] (PREC_SEMICOLON)
75 [,] (PREC_COMMA)
76 }
77
78 #[operator(prefix)]
79 enum PrefixOperator {}
80
81 #[operator(binary)]
82 enum BinaryOperator {}
83
84 #[operator(postfix)]
85 enum PostfixOperator {}
86
87 #[leaf(qualified)]
90 struct Symbol;
91 #[leaf(empty)]
92 struct Empty;
93 #[leaf(adj)]
94 struct Adj;
95 #[leaf(eoc)]
96 struct EOC;
97 #[leaf(eof)]
98 struct EOF;
99 struct EscapeSequence;
100 #[leaf(float)]
101 struct FloatLiteral;
102 #[leaf(integer)]
103 struct IntegerLiteral;
104 struct RawStringContent;
105 struct StringContent;
106
107 #[comments]
111 #[cell_stream]
112 struct SourceFile {
113 cells: Lines<Cell>,
114 eof: EOF
115 }
116
117 #[comments]
118 struct Cell {
119 content: ExprPack,
120 semicolon: Token![;]?,
121 eoc: EOC,
122 }
123
124 enum Component {
125 Expr,
126 Empty
127 }
128
129 struct ExprPack {
130 pack: Punctuated<Component>
131 }
132
133 struct Statement {
134 content: ExprPack,
135 semicolon: Token![;]
136 }
137
138
139 #[delimiter(bracket)]
140 struct Array {
141 statements: Vec<Statement>,
142 elements: ExprPack?
143 }
144
145 #[delimiter(brace)]
146 struct List {
147 statements: Vec<Statement>,
148 elements: ExprPack?
149 }
150
151 #[delimiter(angle_bar)]
152 struct AngleBarList {
153 statements: Vec<Statement>,
154 elements: ExprPack?
155 }
156
157 #[delimiter(parenthesis)]
158 struct Sequence {
159 statements: Vec<Statement>,
160 elements: ExprPack?
161 }
162
163 #[delimiter(parenthesis)]
164 struct Holder {
165 muted: Vec<Statement>,
166 value: Expr?,
167 }
168
169 #[literal(string)]
170 struct StringLiteral {
171 elements: Vec<StringElement>,
172 }
173
174 #[literal(raw_string)]
175 struct RawStringLiteral {
176 elements: Vec<RawStringElement>,
177 }
178
179 struct BinaryExpr {
180 left_operand: Expr,
181 operator: BinaryOperator,
182 right_operand: Expr,
183 }
184
185 struct AdjacentExpr {
186 left_operand: Expr,
187 operator: Adj,
188 right_operand: Expr,
189 }
190
191 struct PrefixExpr {
192 operator: PrefixOperator,
193 operand: Expr,
194 }
195
196 struct PostfixExpr {
197 operand: Expr,
198 operator: PostfixOperator,
199 }
200
201
202
203 enum LambdaParameters {
204 Variadic(Symbol),
205 FixedArity(Delimited<Punctuated<Symbol>?>)
206 }
207
208 struct LambdaExpression {
209 parameters: LambdaParameters,
210 operator: Token![->],
211 body: Expr,
212 }
213
214 struct GlobalBinding {
215 variable: Symbol,
216 operator: Token![=],
217 value: Expr,
218 }
219
220 struct LocalBinding {
221 variable: Symbol,
222 operator: Token![:=],
223 value: Expr,
224 }
225
226
227 struct TypeAnnotation {
228 typical_value: Expr,
229 operator: Token![=>]
230 }
231
232
233 struct OperatorAssignment {
234 argument_expr: OperatorExpr,
235 operator: Token![=],
236 value_expr: Expr,
237 }
238
239
240 struct OperatorInstallation {
241 domain_expr: OperatorExpr,
242 assign_op: Token![:=],
243 typical_value: TypeAnnotation?,
244 function: Expr,
245 }
246
247 struct MethodInstallation {
248 method: Expr,
249 signature: Expr,
250 assign_op: Token![:=],
251 typical_value: TypeAnnotation?,
252 function: Expr,
253 }
254
255 struct NewInstallation {
256 new_statement: NewStatement,
257 operator: Token![:=],
258 function: Expr,
259 }
260
261
262 enum Installation {
263 MethodInstallation,
264 OperatorInstallation,
265 NewInstallation,
266 }
267
268 enum AssignmentPackComponent {
269 AssignmentPack,
270 Empty,
271 Symbol,
272 OperatorExpr,
273 }
274
275 struct AssignmentPack*(
276 Delimited<Punctuated<AssignmentPackComponent>?>)
277
278
279 struct GlobalParallelAssignment {
280 argument_pack: AssignmentPack,
281 operator: Token![=],
282 value: Expr,
283 }
284
285 struct LocalParallelAssignment {
286 argument_pack: AssignmentPack,
287 operator: Token![:=],
288 value: Expr,
289 }
290
291
292
293 enum SimpleBinding {
294 GlobalBinding,
295 LocalBinding,
296 }
297
298 enum ParallelAssignment {
299 GlobalParallelAssignment,
300 LocalParallelAssignment,
301 }
302
303 struct EvaluatedAssignment {
304 evaluated_domain: Expr,
305 operator: Token![<-],
306 value: Expr,
307 }
308
309 struct OptionExpression {
310 key: Expr,
311 operator: Token![=>],
312 value: Expr,
313 }
314
315 enum Assignment {
316 SimpleBinding,
317 ParallelAssignment,
318 EvaluatedAssignment,
319 Installation,
320 OperatorAssignment,
321 }
322
323
324
325 struct ThenClause {
326 then_token: Token![then],
327 expr: Expr,
328 }
329
330 struct ElseClause {
331 else_token: Token![else],
332 expr: Expr
333 }
334
335 struct IfStatement {
336 if_token: Token![if],
337 condition: Expr,
338 then_clause: ThenClause,
339 else_clause: ElseClause?,
340 }
341
342 struct RangeBoundFrom {
343 from_token: Token![from],
344 value: Expr,
345 }
346
347 struct RangeBoundTo {
348 to_token: Token![to],
349 value: Expr,
350 }
351
352 struct IterRange {
353 lower_bound: RangeBoundFrom?,
354 upper_bound: RangeBoundTo?,
355 }
356
357 struct IterIn {
358 in_token: Token![in],
359 collection: Expr,
360 }
361
362 struct WhenCondition {
363 when_token: Token![when],
364 condition: Expr,
365 }
366
367 struct ListStep {
368 list_token: Token![list],
369 expr: Expr,
370 }
371
372 struct DoStep {
373 do_token: Token![do],
374 statement: Expr,
375 }
376
377 struct LoopBody {
378 list_step: ListStep?,
379 do_step: DoStep?,
380 }
381
382 enum IterationDomain {
383 IterRange,
384 IterIn,
385 }
386
387 struct ForLoop {
388 for_token: Token![for],
389 variable: Symbol,
390 iteration_domain: IterationDomain?,
391 when_condition: WhenCondition?,
392 body: LoopBody,
393 }
394
395 struct WhileLoop {
396 while_token: Token![while],
397 condition: Expr,
398 body: LoopBody,
399 }
400
401 struct OfClass {
402 of_token: Token![of],
403 parent: Expr,
404 }
405
406 struct FromInstance {
407 from_token: Token![from],
408 instance: Expr,
409 }
410
411 struct NewStatement {
412 new_token: Token![new],
413 class: Expr,
414 parent_class: OfClass?,
415 instance: FromInstance?,
416 }
417
418
419 enum ProfilingModifier {
420 Token![elapsedTime],
421 Token![elapsedTiming],
422 Token![profile],
423 Token![time],
424 Token![timing],
425 }
426
427
428 struct ProfilingExpr {
429 profiling_modifier: ProfilingModifier,
430 value: Expr,
431 }
432
433 enum DebugKeyword {
434 Token![TEST],
435 Token![step],
436 Token![finish],
437 Token![shield],
438 Token![breakpoint],
439 }
440
441 struct DebugExpr {
442 debug_token: DebugKeyword,
443 value: Expr?,
444 }
445
446
447 struct BreakExpr {
448 break_token: Token![break],
449 value: Expr?,
450 }
451
452 struct ContinueExpr {
453 continue_token: Token![continue],
454 value: Expr?,
455 }
456
457 struct ReturnExpr {
458 return_token: Token![return],
459 value: Expr?,
460 }
461
462 enum ControlFlow {
463 BreakExpr,
464 ContinueExpr,
465 ReturnExpr,
466 }
467
468 struct Catch {
469 catch_token: Token![catch],
470 value: Expr,
471 }
472
473 struct Throw {
474 throw_token: Token![throw],
475 value: Expr,
476 }
477
478 struct Trap {
479 trap_token: Token![trap],
480 value: Expr,
481 }
482
483 struct ExceptDo {
484 except_token: Token![except],
485 exception: Symbol,
486 do_token: Token![do],
487 value: Expr,
488 }
489
490 enum TryFallback {
491 ElseClause,
492 ExceptDo,
493 }
494
495 struct TryStatement {
496 try_token: Token![try],
497 value: Expr,
498 on_success: ThenClause?,
499 fallback: TryFallback?
500 }
501
502 enum QuoteSpecifier {
503 Token![symbol],
504 Token![local],
505 Token![global],
506 Token![threadVariable],
507 Token![threadLocal],
508 }
509
510 struct QuoteExpression {
511 specifier: QuoteSpecifier,
512 symbol: Symbol,
513 }
514
515 enum StringElement {
516 EscapeSequence,
517 StringContent,
518 }
519
520 enum RawStringElement {
521 EscapeSequence,
522 RawStringContent,
523 }
524
525 enum Collection {
526 Sequence,
527 List,
528 Array,
529 AngleBarList,
530 }
531
532 enum OperatorExpr {
533 AdjacentExpr,
534 BinaryExpr,
535 PrefixExpr,
536 PostfixExpr,
537 }
538
539 enum Literal {
540 FloatLiteral,
541 IntegerLiteral,
542 RawStringLiteral,
543 StringLiteral,
544 }
545
546 enum Expr* {
547 Literal,
548 Collection,
549 Holder,
550 OperatorExpr,
551 Assignment,
552 OptionExpression,
553 LambdaExpression,
554 IfStatement,
555 ForLoop,
556 WhileLoop,
557 TryStatement,
558 QuoteExpression,
559 NewStatement,
560 ControlFlow,
561 Catch,
562 Throw,
563 Trap,
564 DebugExpr,
565 ProfilingExpr,
566 Symbol,
567 }
568}