]> git.lizzy.rs Git - rust.git/blob - crates/ra_syntax/src/grammar.ron
add await to syntax, parser for await_expr
[rust.git] / crates / ra_syntax / src / grammar.ron
1 // Stores definitions which must be used in multiple places
2 // See `cargo gen-syntax` (defined in crates/tools/src/main.rs)
3 Grammar(
4     single_byte_tokens: [
5         [";", "SEMI"],
6         [",", "COMMA"],
7         ["(", "L_PAREN"],
8         [")", "R_PAREN"],
9         ["{", "L_CURLY"],
10         ["}", "R_CURLY"],
11         ["[", "L_BRACK"],
12         ["]", "R_BRACK"],
13         ["<", "L_ANGLE"],
14         [">", "R_ANGLE"],
15         ["@", "AT"],
16         ["#", "POUND"],
17         ["~", "TILDE"],
18         ["?", "QUESTION"],
19         ["$", "DOLLAR"],
20         ["&", "AMP"],
21         ["|", "PIPE"],
22         ["+", "PLUS"],
23         ["*", "STAR"],
24         ["/", "SLASH"],
25         ["^", "CARET"],
26         ["%", "PERCENT"],
27         ["_", "UNDERSCORE"],
28     ],
29     // Tokens for which the longest match must be chosen (e.g. `..` is a DOTDOT, but `.` is a DOT)
30     multi_byte_tokens: [
31         [".", "DOT"],
32         ["..", "DOTDOT"],
33         ["...", "DOTDOTDOT"],
34         ["..=", "DOTDOTEQ"],
35         [":", "COLON"],
36         ["::", "COLONCOLON"],
37         ["=", "EQ"],
38         ["==", "EQEQ"],
39         ["=>", "FAT_ARROW"],
40         ["!", "EXCL"],
41         ["!=", "NEQ"],
42         ["-", "MINUS"],
43         ["->", "THIN_ARROW"],
44         ["<=", "LTEQ"],
45         [">=", "GTEQ"],
46         ["+=", "PLUSEQ"],
47         ["-=", "MINUSEQ"],
48         ["|=", "PIPEEQ"],
49         ["&=", "AMPEQ"],
50         ["^=", "CARETEQ"],
51         ["/=", "SLASHEQ"],
52         ["*=", "STAREQ"],
53         ["%=", "PERCENTEQ"],
54         ["&&", "AMPAMP"],
55         ["||", "PIPEPIPE"],
56         ["<<", "SHL"],
57         [">>", "SHR"],
58         ["<<=", "SHLEQ"],
59         [">>=", "SHREQ"],
60     ],
61     keywords: [
62         "async",
63         "use",
64         "fn",
65         "struct",
66         "enum",
67         "trait",
68         "impl",
69         "dyn",
70         "true",
71         "false",
72         "as",
73         "extern",
74         "crate",
75         "mod",
76         "pub",
77         "self",
78         "super",
79         "in",
80         "where",
81         "for",
82         "loop",
83         "while",
84         "continue",
85         "break",
86         "if",
87         "else",
88         "match",
89         "const",
90         "static",
91         "mut",
92         "unsafe",
93         "type",
94         "ref",
95         "let",
96         "move",
97         "return",
98         "try",
99         "box",
100         "await"
101     ],
102     contextual_keywords: [
103         "auto",
104         "default",
105         "existential",
106         "union",
107     ],
108     literals: [
109         "INT_NUMBER",
110         "FLOAT_NUMBER",
111         "CHAR",
112         "BYTE",
113         "STRING",
114         "RAW_STRING",
115         "BYTE_STRING",
116         "RAW_BYTE_STRING",
117     ],
118     tokens: [
119         "ERROR",
120         "IDENT",
121         "WHITESPACE",
122         "LIFETIME",
123         "COMMENT",
124         "SHEBANG",
125         "L_DOLLAR",
126         "R_DOLLAR",
127     ],
128     nodes: [
129         "SOURCE_FILE",
130
131         "STRUCT_DEF",
132         "ENUM_DEF",
133         "FN_DEF",
134         "RET_TYPE",
135         "EXTERN_CRATE_ITEM",
136         "MODULE",
137         "USE_ITEM",
138         "STATIC_DEF",
139         "CONST_DEF",
140         "TRAIT_DEF",
141         "IMPL_BLOCK",
142         "TYPE_ALIAS_DEF",
143         "MACRO_CALL",
144         "TOKEN_TREE",
145
146         "PAREN_TYPE",
147         "TUPLE_TYPE",
148         "NEVER_TYPE",
149         "PATH_TYPE",
150         "POINTER_TYPE",
151         "ARRAY_TYPE",
152         "SLICE_TYPE",
153         "REFERENCE_TYPE",
154         "PLACEHOLDER_TYPE",
155         "FN_POINTER_TYPE",
156         "FOR_TYPE",
157         "IMPL_TRAIT_TYPE",
158         "DYN_TRAIT_TYPE",
159
160         "REF_PAT",
161         "BIND_PAT",
162         "PLACEHOLDER_PAT",
163         "PATH_PAT",
164         "STRUCT_PAT",
165         "FIELD_PAT_LIST",
166         "FIELD_PAT",
167         "TUPLE_STRUCT_PAT",
168         "TUPLE_PAT",
169         "SLICE_PAT",
170         "RANGE_PAT",
171         "LITERAL_PAT",
172
173         // atoms
174         "TUPLE_EXPR",
175         "ARRAY_EXPR",
176         "PAREN_EXPR",
177         "PATH_EXPR",
178         "LAMBDA_EXPR",
179         "IF_EXPR",
180         "WHILE_EXPR",
181         "CONDITION",
182         "LOOP_EXPR",
183         "FOR_EXPR",
184         "CONTINUE_EXPR",
185         "BREAK_EXPR",
186         "LABEL",
187         "BLOCK_EXPR",
188         "RETURN_EXPR",
189         "MATCH_EXPR",
190         "MATCH_ARM_LIST",
191         "MATCH_ARM",
192         "MATCH_GUARD",
193         "STRUCT_LIT",
194         "NAMED_FIELD_LIST",
195         "NAMED_FIELD",
196         "TRY_BLOCK_EXPR",
197         "BOX_EXPR",
198
199         // postfix
200         "CALL_EXPR",
201         "INDEX_EXPR",
202         "METHOD_CALL_EXPR",
203         "FIELD_EXPR",
204         "AWAIT_EXPR",
205         "TRY_EXPR",
206         "CAST_EXPR",
207
208         // unary
209         "REF_EXPR",
210         "PREFIX_EXPR",
211
212         "RANGE_EXPR", // just weird
213         "BIN_EXPR",
214
215         "BLOCK",
216         "EXTERN_BLOCK",
217         "EXTERN_ITEM_LIST",
218         "ENUM_VARIANT",
219         "NAMED_FIELD_DEF_LIST",
220         "NAMED_FIELD_DEF",
221         "POS_FIELD_DEF_LIST",
222         "POS_FIELD_DEF",
223         "ENUM_VARIANT_LIST",
224         "ITEM_LIST",
225         "ATTR",
226         "META_ITEM", // not an item actually
227         "USE_TREE",
228         "USE_TREE_LIST",
229         "PATH",
230         "PATH_SEGMENT",
231         "LITERAL",
232         "ALIAS",
233         "VISIBILITY",
234         "WHERE_CLAUSE",
235         "WHERE_PRED",
236         "ABI",
237         "NAME",
238         "NAME_REF",
239
240         "LET_STMT",
241         "EXPR_STMT",
242
243         "TYPE_PARAM_LIST",
244         "LIFETIME_PARAM",
245         "TYPE_PARAM",
246         "TYPE_ARG_LIST",
247         "LIFETIME_ARG",
248         "TYPE_ARG",
249         "ASSOC_TYPE_ARG",
250
251         "PARAM_LIST",
252         "PARAM",
253         "SELF_PARAM",
254         "ARG_LIST",
255         "TYPE_BOUND",
256         "TYPE_BOUND_LIST",
257
258         // macro related
259         "MACRO_ITEMS",
260         "MACRO_STMTS",
261     ],
262     ast: {
263         "SourceFile": (
264             traits: [ "ModuleItemOwner", "FnDefOwner" ],
265             collections: [
266                 ["modules", "Module"],
267             ]
268         ),
269         "FnDef": (
270             traits: [
271                 "VisibilityOwner",
272                 "NameOwner",
273                 "TypeParamsOwner",
274                 "AttrsOwner",
275                 "DocCommentsOwner"
276             ],
277             options: [ "ParamList", ["body", "Block"], "RetType" ],
278         ),
279         "RetType": (options: ["TypeRef"]),
280         "StructDef": (
281             traits: [
282                 "VisibilityOwner",
283                 "NameOwner",
284                 "TypeParamsOwner",
285                 "AttrsOwner",
286                 "DocCommentsOwner"
287             ]
288         ),
289         "NamedFieldDefList": (collections: [["fields", "NamedFieldDef"]]),
290         "NamedFieldDef": (
291             traits: [
292                 "VisibilityOwner",
293                 "NameOwner",
294                 "AttrsOwner",
295                 "DocCommentsOwner",
296                 "TypeAscriptionOwner"
297             ]
298         ),
299         "PosFieldDefList": (collections: [["fields", "PosFieldDef"]]),
300         "PosFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]),
301         "EnumDef": ( traits: [
302             "VisibilityOwner",
303             "NameOwner",
304             "TypeParamsOwner",
305             "AttrsOwner",
306             "DocCommentsOwner"
307         ], options: [["variant_list", "EnumVariantList"]] ),
308         "EnumVariantList": ( collections: [["variants", "EnumVariant"]] ),
309         "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner", "AttrsOwner"], options: ["Expr"] ),
310         "TraitDef": (
311             traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeParamsOwner", "TypeBoundsOwner"],
312             options: ["ItemList"]
313         ),
314         "Module": (
315             traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner" ],
316             options: [ "ItemList" ]
317         ),
318         "ItemList": (
319             collections: [["impl_items", "ImplItem"]],
320             traits: [ "FnDefOwner", "ModuleItemOwner" ],
321         ),
322         "ConstDef": (
323             traits: [
324                 "VisibilityOwner",
325                 "NameOwner",
326                 "TypeParamsOwner",
327                 "AttrsOwner",
328                 "DocCommentsOwner",
329                 "TypeAscriptionOwner",
330             ],
331             options: [ ["body","Expr"]],
332         ),
333         "StaticDef": (
334             traits: [
335                 "VisibilityOwner",
336                 "NameOwner",
337                 "TypeParamsOwner",
338                 "AttrsOwner",
339                 "DocCommentsOwner",
340                 "TypeAscriptionOwner",
341             ],
342             options: [ ["body","Expr"]],
343         ),
344         "TypeAliasDef": (
345             traits: [
346                 "VisibilityOwner",
347                 "NameOwner",
348                 "TypeParamsOwner",
349                 "AttrsOwner",
350                 "DocCommentsOwner",
351                 "TypeBoundsOwner",
352             ],
353             options: ["TypeRef"]
354         ),
355         "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner", "AttrsOwner"]),
356
357         "ParenType": (options: ["TypeRef"]),
358         "TupleType": ( collections: [["fields", "TypeRef"]] ),
359         "NeverType": (),
360         "PathType": (options: ["Path"]),
361         "PointerType": (options: ["TypeRef"]),
362         "ArrayType": ( options: ["TypeRef", "Expr"] ),
363         "SliceType": ( options: ["TypeRef"] ),
364         "ReferenceType": (options: ["TypeRef"]),
365         "PlaceholderType": (),
366         "FnPointerType": (options: ["ParamList", "RetType"]),
367         "ForType": (options: ["TypeRef"]),
368         "ImplTraitType": (
369             traits: ["TypeBoundsOwner"],
370         ),
371         "DynTraitType": (
372             traits: ["TypeBoundsOwner"],
373         ),
374
375         "TypeRef": ( enum: [
376             "ParenType",
377             "TupleType",
378             "NeverType",
379             "PathType",
380             "PointerType",
381             "ArrayType",
382             "SliceType",
383             "ReferenceType",
384             "PlaceholderType",
385             "FnPointerType",
386             "ForType",
387             "ImplTraitType",
388             "DynTraitType",
389         ]),
390
391         "NominalDef": (
392             enum: ["StructDef", "EnumDef"],
393             traits: [
394                 "NameOwner",
395                 "TypeParamsOwner",
396                 "AttrsOwner"
397             ],
398         ),
399         "ModuleItem": (
400             enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "TypeAliasDef", "ImplBlock",
401                    "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ]
402         ),
403         "ImplItem": (
404             enum: ["FnDef", "TypeAliasDef", "ConstDef"]
405         ),
406
407         "TupleExpr": (
408             collections: [["exprs", "Expr"]]
409         ),
410         "ArrayExpr": (
411             collections: [["exprs", "Expr"]]
412         ),
413         "ParenExpr": (options: ["Expr"]),
414         "PathExpr": (options: ["Path"]),
415         "LambdaExpr": (
416             options: [
417                 "ParamList",
418                 ["body", "Expr"],
419             ]
420         ),
421         "IfExpr": (
422             options: [ "Condition" ]
423         ),
424         "LoopExpr": (
425             traits: ["LoopBodyOwner"],
426         ),
427         "TryBlockExpr": (
428             traits: ["TryBlockBodyOwner"],
429         ),
430         "ForExpr": (
431             traits: ["LoopBodyOwner"],
432             options: [
433                 "Pat",
434                 ["iterable", "Expr"],
435             ]
436         ),
437         "WhileExpr": (
438             traits: ["LoopBodyOwner"],
439             options: [ "Condition" ]
440         ),
441         "ContinueExpr": (),
442         "BreakExpr": (options: ["Expr"]),
443         "Label": (),
444         "BlockExpr": (
445             options: [ "Block" ]
446         ),
447         "ReturnExpr": (options: ["Expr"]),
448         "MatchExpr": (
449             options: [ "Expr", "MatchArmList" ],
450         ),
451         "MatchArmList": (
452             collections: [ ["arms", "MatchArm"] ],
453             traits: [ "AttrsOwner" ]
454         ),
455         "MatchArm": (
456             options: [
457                 [ "guard", "MatchGuard" ],
458                 "Expr",
459             ],
460             collections: [ [ "pats", "Pat" ] ],
461             traits: [ "AttrsOwner" ]
462         ),
463         "MatchGuard": (options: ["Expr"]),
464         "StructLit": (options: ["Path", "NamedFieldList"]),
465         "NamedFieldList": (
466             collections: [ ["fields", "NamedField"] ],
467             options: [["spread", "Expr"]]
468         ),
469         "NamedField": (options: ["NameRef", "Expr"]),
470         "CallExpr": (
471             traits: ["ArgListOwner"],
472             options: [ "Expr" ],
473         ),
474         "MethodCallExpr": (
475             traits: ["ArgListOwner"],
476             options: [ "Expr", "NameRef", "TypeArgList" ],
477         ),
478         "IndexExpr": (),
479         "FieldExpr": (options: ["Expr", "NameRef"]),
480         "TryExpr": (options: ["Expr"]),
481         "CastExpr": (options: ["Expr", "TypeRef"]),
482         "RefExpr": (options: ["Expr"]),
483         "PrefixExpr": (options: ["Expr"]),
484         "RangeExpr": (),
485         "BinExpr": (),
486
487         "Literal": (),
488
489         "Expr": (
490             enum: [
491                 "TupleExpr",
492                 "ArrayExpr",
493                 "ParenExpr",
494                 "PathExpr",
495                 "LambdaExpr",
496                 "IfExpr",
497                 "LoopExpr",
498                 "ForExpr",
499                 "WhileExpr",
500                 "ContinueExpr",
501                 "BreakExpr",
502                 "Label",
503                 "BlockExpr",
504                 "ReturnExpr",
505                 "MatchExpr",
506                 "StructLit",
507                 "CallExpr",
508                 "IndexExpr",
509                 "MethodCallExpr",
510                 "FieldExpr",
511                 "TryExpr",
512                 "TryBlockExpr",
513                 "CastExpr",
514                 "RefExpr",
515                 "PrefixExpr",
516                 "RangeExpr",
517                 "BinExpr",
518                 "Literal",
519                 "MacroCall",
520             ],
521         ),
522
523         "RefPat": ( options: [ "Pat" ]),
524         "BindPat": (
525             options: [ "Pat" ],
526             traits: ["NameOwner"]
527         ),
528         "PlaceholderPat": (),
529         "PathPat": ( options: [ "Path" ] ),
530         "StructPat": ( options: ["FieldPatList", "Path"] ),
531         "FieldPatList": (
532             collections: [
533                 ["field_pats", "FieldPat"],
534                 ["bind_pats", "BindPat"],
535             ]
536         ),
537         "FieldPat": (
538             traits: ["NameOwner"],
539             options: ["Pat"]
540         ),
541         "TupleStructPat": (
542             options: ["Path"],
543             collections: [["args", "Pat"]],
544         ),
545         "TuplePat": ( collections: [["args", "Pat"]] ),
546         "SlicePat": (),
547         "RangePat": (),
548         "LiteralPat": (options: ["Literal"]),
549
550         "Pat": (
551             enum: [
552                 "RefPat",
553                 "BindPat",
554                 "PlaceholderPat",
555                 "PathPat",
556                 "StructPat",
557                 "TupleStructPat",
558                 "TuplePat",
559                 "SlicePat",
560                 "RangePat",
561                 "LiteralPat",
562             ],
563         ),
564
565         "Visibility": (),
566         "Name": (),
567         "NameRef": (),
568         "MacroCall": (
569             traits: [ "NameOwner", "AttrsOwner","DocCommentsOwner" ],
570             options: [ "TokenTree", "Path" ],
571         ),
572         "Attr": ( options: [ ["value", "TokenTree"] ] ),
573         "TokenTree": (),
574         "TypeParamList": (
575             collections: [
576                 ["type_params", "TypeParam" ],
577                 ["lifetime_params", "LifetimeParam" ],
578             ]
579         ),
580         "TypeParam": ( traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner", "DefaultTypeParamOwner"] ),
581         "LifetimeParam": (
582             traits: ["AttrsOwner"],
583         ),
584         "TypeBound": (
585             options: [
586                 "TypeRef",
587             ]
588         ),
589         "TypeBoundList": (
590             collections: [
591                 ["bounds", "TypeBound"],
592             ]
593         ),
594         "WherePred": (
595             options: [
596                 "TypeRef",
597             ],
598             traits: [
599                 "TypeBoundsOwner",
600             ],
601         ),
602         "WhereClause": (
603             collections: [
604                 ["predicates", "WherePred"],
605             ],
606         ),
607         "ExprStmt": (
608             options: [ ["expr", "Expr"] ]
609         ),
610         "LetStmt": (
611             options: [
612                 ["pat", "Pat"],
613                 ["initializer", "Expr"],
614             ],
615             traits: [
616                 "TypeAscriptionOwner",
617             ]
618         ),
619         "Condition": (
620             options: [ "Pat", "Expr" ]
621         ),
622         "Stmt": (
623             enum: ["ExprStmt", "LetStmt"],
624         ),
625         "Block": (
626             options: [ "Expr" ],
627             collections: [
628                 ["statements", "Stmt"],
629             ],
630             traits: [
631                 "AttrsOwner",
632             ]
633         ),
634         "ParamList": (
635             options: [ "SelfParam" ],
636             collections: [
637                 ["params", "Param"]
638             ]
639         ),
640         "SelfParam": (
641             traits: [
642                 "TypeAscriptionOwner",
643             ]
644         ),
645         "Param": (
646             options: [ "Pat" ],
647             traits: [
648                 "TypeAscriptionOwner",
649             ]
650         ),
651         "UseItem": (
652             traits: ["AttrsOwner"],
653             options: [ "UseTree" ],
654         ),
655         "UseTree": (
656             options: [ "Path", "UseTreeList", "Alias" ]
657         ),
658         "Alias": (
659             traits: ["NameOwner"],
660         ),
661         "UseTreeList": (
662             collections: [["use_trees", "UseTree"]]
663         ),
664         "ExternCrateItem": (
665             options: ["NameRef", "Alias"],
666         ),
667         "ArgList": (
668             collections: [
669                 ["args", "Expr"]
670             ]
671         ),
672         "Path": (
673             options: [
674                 ["segment", "PathSegment"],
675                 ["qualifier", "Path"],
676             ]
677         ),
678         "PathSegment": (
679             options: [ "NameRef", "TypeArgList" ]
680         ),
681         "TypeArgList": (collections: [
682             ["type_args", "TypeArg"],
683             ["lifetime_args", "LifetimeArg"],
684             ["assoc_type_args", "AssocTypeArg"],
685         ]),
686         "TypeArg": (options: ["TypeRef"]),
687         "AssocTypeArg": (options: ["NameRef", "TypeRef"]),
688         "LifetimeArg": (),
689
690         "MacroItems": (
691             traits: [ "ModuleItemOwner", "FnDefOwner" ],            
692         ),
693
694         "MacroStmts" : (
695             options: [ "Expr" ],
696             collections: [
697                 ["statements", "Stmt"],
698             ],
699         )
700     },
701 )