]> git.lizzy.rs Git - rust.git/blob - crates/ra_syntax/src/grammar.ron
Merge #1230
[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     ],
99     contextual_keywords: [
100         "auto",
101         "default",
102         "union",
103     ],
104     literals: [
105         "INT_NUMBER",
106         "FLOAT_NUMBER",
107         "CHAR",
108         "BYTE",
109         "STRING",
110         "RAW_STRING",
111         "BYTE_STRING",
112         "RAW_BYTE_STRING",
113     ],
114     tokens: [
115         "ERROR",
116         "IDENT",
117         "WHITESPACE",
118         "LIFETIME",
119         "COMMENT",
120         "SHEBANG",
121         "L_DOLLAR",
122         "R_DOLLAR",
123     ],
124     nodes: [
125         "SOURCE_FILE",
126
127         "STRUCT_DEF",
128         "ENUM_DEF",
129         "FN_DEF",
130         "RET_TYPE",
131         "EXTERN_CRATE_ITEM",
132         "MODULE",
133         "USE_ITEM",
134         "STATIC_DEF",
135         "CONST_DEF",
136         "TRAIT_DEF",
137         "IMPL_BLOCK",
138         "TYPE_ALIAS_DEF",
139         "MACRO_CALL",
140         "TOKEN_TREE",
141
142         "PAREN_TYPE",
143         "TUPLE_TYPE",
144         "NEVER_TYPE",
145         "PATH_TYPE",
146         "POINTER_TYPE",
147         "ARRAY_TYPE",
148         "SLICE_TYPE",
149         "REFERENCE_TYPE",
150         "PLACEHOLDER_TYPE",
151         "FN_POINTER_TYPE",
152         "FOR_TYPE",
153         "IMPL_TRAIT_TYPE",
154         "DYN_TRAIT_TYPE",
155
156         "REF_PAT",
157         "BIND_PAT",
158         "PLACEHOLDER_PAT",
159         "PATH_PAT",
160         "STRUCT_PAT",
161         "FIELD_PAT_LIST",
162         "FIELD_PAT",
163         "TUPLE_STRUCT_PAT",
164         "TUPLE_PAT",
165         "SLICE_PAT",
166         "RANGE_PAT",
167         "LITERAL_PAT",
168
169         // atoms
170         "TUPLE_EXPR",
171         "ARRAY_EXPR",
172         "PAREN_EXPR",
173         "PATH_EXPR",
174         "LAMBDA_EXPR",
175         "IF_EXPR",
176         "WHILE_EXPR",
177         "CONDITION",
178         "LOOP_EXPR",
179         "FOR_EXPR",
180         "CONTINUE_EXPR",
181         "BREAK_EXPR",
182         "LABEL",
183         "BLOCK_EXPR",
184         "RETURN_EXPR",
185         "MATCH_EXPR",
186         "MATCH_ARM_LIST",
187         "MATCH_ARM",
188         "MATCH_GUARD",
189         "STRUCT_LIT",
190         "NAMED_FIELD_LIST",
191         "NAMED_FIELD",
192
193         // postfix
194         "CALL_EXPR",
195         "INDEX_EXPR",
196         "METHOD_CALL_EXPR",
197         "FIELD_EXPR",
198         "TRY_EXPR",
199         "CAST_EXPR",
200
201         // unary
202         "REF_EXPR",
203         "PREFIX_EXPR",
204
205         "RANGE_EXPR", // just weird
206         "BIN_EXPR",
207
208         "BLOCK",
209         "EXTERN_BLOCK",
210         "EXTERN_ITEM_LIST",
211         "ENUM_VARIANT",
212         "NAMED_FIELD_DEF_LIST",
213         "NAMED_FIELD_DEF",
214         "POS_FIELD_DEF_LIST",
215         "POS_FIELD_DEF",
216         "ENUM_VARIANT_LIST",
217         "ITEM_LIST",
218         "ATTR",
219         "META_ITEM", // not an item actually
220         "USE_TREE",
221         "USE_TREE_LIST",
222         "PATH",
223         "PATH_SEGMENT",
224         "LITERAL",
225         "ALIAS",
226         "VISIBILITY",
227         "WHERE_CLAUSE",
228         "WHERE_PRED",
229         "ABI",
230         "NAME",
231         "NAME_REF",
232
233         "LET_STMT",
234         "EXPR_STMT",
235
236         "TYPE_PARAM_LIST",
237         "LIFETIME_PARAM",
238         "TYPE_PARAM",
239         "TYPE_ARG_LIST",
240         "LIFETIME_ARG",
241         "TYPE_ARG",
242         "ASSOC_TYPE_ARG",
243
244         "PARAM_LIST",
245         "PARAM",
246         "SELF_PARAM",
247         "ARG_LIST",
248         "TYPE_BOUND",
249         "TYPE_BOUND_LIST",
250
251         // macro related
252         "MACRO_ITEMS",
253         "MACRO_STMTS",
254     ],
255     ast: {
256         "SourceFile": (
257             traits: [ "ModuleItemOwner", "FnDefOwner" ],
258             collections: [
259                 ["modules", "Module"],
260             ]
261         ),
262         "FnDef": (
263             traits: [
264                 "VisibilityOwner",
265                 "NameOwner",
266                 "TypeParamsOwner",
267                 "AttrsOwner",
268                 "DocCommentsOwner"
269             ],
270             options: [ "ParamList", ["body", "Block"], "RetType" ],
271         ),
272         "RetType": (options: ["TypeRef"]),
273         "StructDef": (
274             traits: [
275                 "VisibilityOwner",
276                 "NameOwner",
277                 "TypeParamsOwner",
278                 "AttrsOwner",
279                 "DocCommentsOwner"
280             ]
281         ),
282         "NamedFieldDefList": (collections: [["fields", "NamedFieldDef"]]),
283         "NamedFieldDef": (
284             traits: [
285                 "VisibilityOwner",
286                 "NameOwner",
287                 "AttrsOwner",
288                 "DocCommentsOwner",
289                 "TypeAscriptionOwner"
290             ]
291         ),
292         "PosFieldDefList": (collections: [["fields", "PosFieldDef"]]),
293         "PosFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]),
294         "EnumDef": ( traits: [
295             "VisibilityOwner",
296             "NameOwner",
297             "TypeParamsOwner",
298             "AttrsOwner",
299             "DocCommentsOwner"
300         ], options: [["variant_list", "EnumVariantList"]] ),
301         "EnumVariantList": ( collections: [["variants", "EnumVariant"]] ),
302         "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner", "AttrsOwner"], options: ["Expr"] ),
303         "TraitDef": (
304             traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeParamsOwner", "TypeBoundsOwner"],
305             options: ["ItemList"]
306         ),
307         "Module": (
308             traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner" ],
309             options: [ "ItemList" ]
310         ),
311         "ItemList": (
312             collections: [["impl_items", "ImplItem"]],
313             traits: [ "FnDefOwner", "ModuleItemOwner" ],
314         ),
315         "ConstDef": (
316             traits: [
317                 "VisibilityOwner",
318                 "NameOwner",
319                 "TypeParamsOwner",
320                 "AttrsOwner",
321                 "DocCommentsOwner",
322                 "TypeAscriptionOwner",
323             ],
324             options: [ ["body","Expr"]],
325         ),
326         "StaticDef": (
327             traits: [
328                 "VisibilityOwner",
329                 "NameOwner",
330                 "TypeParamsOwner",
331                 "AttrsOwner",
332                 "DocCommentsOwner",
333                 "TypeAscriptionOwner",
334             ],
335             options: [ ["body","Expr"]],
336         ),
337         "TypeAliasDef": (
338             traits: [
339                 "VisibilityOwner",
340                 "NameOwner",
341                 "TypeParamsOwner",
342                 "AttrsOwner",
343                 "DocCommentsOwner",
344                 "TypeBoundsOwner",
345             ],
346             options: ["TypeRef"]
347         ),
348         "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner", "AttrsOwner"]),
349
350         "ParenType": (options: ["TypeRef"]),
351         "TupleType": ( collections: [["fields", "TypeRef"]] ),
352         "NeverType": (),
353         "PathType": (options: ["Path"]),
354         "PointerType": (options: ["TypeRef"]),
355         "ArrayType": ( options: ["TypeRef", "Expr"] ),
356         "SliceType": ( options: ["TypeRef"] ),
357         "ReferenceType": (options: ["TypeRef"]),
358         "PlaceholderType": (),
359         "FnPointerType": (options: ["ParamList", "RetType"]),
360         "ForType": (options: ["TypeRef"]),
361         "ImplTraitType": (
362             traits: ["TypeBoundsOwner"],
363         ),
364         "DynTraitType": (
365             traits: ["TypeBoundsOwner"],
366         ),
367
368         "TypeRef": ( enum: [
369             "ParenType",
370             "TupleType",
371             "NeverType",
372             "PathType",
373             "PointerType",
374             "ArrayType",
375             "SliceType",
376             "ReferenceType",
377             "PlaceholderType",
378             "FnPointerType",
379             "ForType",
380             "ImplTraitType",
381             "DynTraitType",
382         ]),
383
384         "NominalDef": (
385             enum: ["StructDef", "EnumDef"],
386             traits: [
387                 "NameOwner",
388                 "TypeParamsOwner",
389                 "AttrsOwner"
390             ],
391         ),
392         "ModuleItem": (
393             enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "TypeAliasDef", "ImplBlock",
394                    "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ]
395         ),
396         "ImplItem": (
397             enum: ["FnDef", "TypeAliasDef", "ConstDef"]
398         ),
399
400         "TupleExpr": (
401             collections: [["exprs", "Expr"]]
402         ),
403         "ArrayExpr": (
404             collections: [["exprs", "Expr"]]
405         ),
406         "ParenExpr": (options: ["Expr"]),
407         "PathExpr": (options: ["Path"]),
408         "LambdaExpr": (
409             options: [
410                 "ParamList",
411                 ["body", "Expr"],
412             ]
413         ),
414         "IfExpr": (
415             options: [ "Condition" ]
416         ),
417         "LoopExpr": (
418             traits: ["LoopBodyOwner"],
419         ),
420         "ForExpr": (
421             traits: ["LoopBodyOwner"],
422             options: [
423                 "Pat",
424                 ["iterable", "Expr"],
425             ]
426         ),
427         "WhileExpr": (
428             traits: ["LoopBodyOwner"],
429             options: [ "Condition" ]
430         ),
431         "ContinueExpr": (),
432         "BreakExpr": (options: ["Expr"]),
433         "Label": (),
434         "BlockExpr": (
435             options: [ "Block" ]
436         ),
437         "ReturnExpr": (options: ["Expr"]),
438         "MatchExpr": (
439             options: [ "Expr", "MatchArmList" ],
440         ),
441         "MatchArmList": (
442             collections: [ ["arms", "MatchArm"] ],
443             traits: [ "AttrsOwner" ]
444         ),
445         "MatchArm": (
446             options: [
447                 [ "guard", "MatchGuard" ],
448                 "Expr",
449             ],
450             collections: [ [ "pats", "Pat" ] ],
451             traits: [ "AttrsOwner" ]
452         ),
453         "MatchGuard": (options: ["Expr"]),
454         "StructLit": (options: ["Path", "NamedFieldList", ["spread", "Expr"]]),
455         "NamedFieldList": (collections: [ ["fields", "NamedField"] ]),
456         "NamedField": (options: ["NameRef", "Expr"]),
457         "CallExpr": (
458             traits: ["ArgListOwner"],
459             options: [ "Expr" ],
460         ),
461         "MethodCallExpr": (
462             traits: ["ArgListOwner"],
463             options: [ "Expr", "NameRef", "TypeArgList" ],
464         ),
465         "IndexExpr": (),
466         "FieldExpr": (options: ["Expr", "NameRef"]),
467         "TryExpr": (options: ["Expr"]),
468         "CastExpr": (options: ["Expr", "TypeRef"]),
469         "RefExpr": (options: ["Expr"]),
470         "PrefixExpr": (options: ["Expr"]),
471         "RangeExpr": (),
472         "BinExpr": (),
473
474         "Literal": (),
475
476         "Expr": (
477             enum: [
478                 "TupleExpr",
479                 "ArrayExpr",
480                 "ParenExpr",
481                 "PathExpr",
482                 "LambdaExpr",
483                 "IfExpr",
484                 "LoopExpr",
485                 "ForExpr",
486                 "WhileExpr",
487                 "ContinueExpr",
488                 "BreakExpr",
489                 "Label",
490                 "BlockExpr",
491                 "ReturnExpr",
492                 "MatchExpr",
493                 "StructLit",
494                 "CallExpr",
495                 "IndexExpr",
496                 "MethodCallExpr",
497                 "FieldExpr",
498                 "TryExpr",
499                 "CastExpr",
500                 "RefExpr",
501                 "PrefixExpr",
502                 "RangeExpr",
503                 "BinExpr",
504                 "Literal",
505                 "MacroCall",
506             ],
507         ),
508
509         "RefPat": ( options: [ "Pat" ]),
510         "BindPat": (
511             options: [ "Pat" ],
512             traits: ["NameOwner"]
513         ),
514         "PlaceholderPat": (),
515         "PathPat": ( options: [ "Path" ] ),
516         "StructPat": ( options: ["FieldPatList", "Path"] ),
517         "FieldPatList": (
518             collections: [
519                 ["field_pats", "FieldPat"],
520                 ["bind_pats", "BindPat"],
521             ]
522         ),
523         "FieldPat": (
524             traits: ["NameOwner"],
525             options: ["Pat"]
526         ),
527         "TupleStructPat": (
528             options: ["Path"],
529             collections: [["args", "Pat"]],
530         ),
531         "TuplePat": ( collections: [["args", "Pat"]] ),
532         "SlicePat": (),
533         "RangePat": (),
534         "LiteralPat": (options: ["Literal"]),
535
536         "Pat": (
537             enum: [
538                 "RefPat",
539                 "BindPat",
540                 "PlaceholderPat",
541                 "PathPat",
542                 "StructPat",
543                 "TupleStructPat",
544                 "TuplePat",
545                 "SlicePat",
546                 "RangePat",
547                 "LiteralPat",
548             ],
549         ),
550
551         "Visibility": (),
552         "Name": (),
553         "NameRef": (),
554         "MacroCall": (
555             traits: [ "NameOwner", "AttrsOwner" ],
556             options: [ "TokenTree", "Path" ],
557         ),
558         "Attr": ( options: [ ["value", "TokenTree"] ] ),
559         "TokenTree": (),
560         "TypeParamList": (
561             collections: [
562                 ["type_params", "TypeParam" ],
563                 ["lifetime_params", "LifetimeParam" ],
564             ]
565         ),
566         "TypeParam": ( traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner", "DefaultTypeParamOwner"] ),
567         "LifetimeParam": (
568             traits: ["AttrsOwner"],
569         ),
570         "TypeBound": (
571             options: [
572                 "TypeRef",
573             ]
574         ),
575         "TypeBoundList": (
576             collections: [
577                 ["bounds", "TypeBound"],
578             ]
579         ),
580         "WherePred": (
581             options: [
582                 "TypeRef",
583             ],
584             traits: [
585                 "TypeBoundsOwner",
586             ],
587         ),
588         "WhereClause": (
589             collections: [
590                 ["predicates", "WherePred"],
591             ],
592         ),
593         "ExprStmt": (
594             options: [ ["expr", "Expr"] ]
595         ),
596         "LetStmt": (
597             options: [
598                 ["pat", "Pat"],
599                 ["initializer", "Expr"],
600             ],
601             traits: [
602                 "TypeAscriptionOwner",
603             ]
604         ),
605         "Condition": (
606             options: [ "Pat", "Expr" ]
607         ),
608         "Stmt": (
609             enum: ["ExprStmt", "LetStmt"],
610         ),
611         "Block": (
612             options: [ "Expr" ],
613             collections: [
614                 ["statements", "Stmt"],
615             ],
616             traits: [
617                 "AttrsOwner",
618             ]
619         ),
620         "ParamList": (
621             options: [ "SelfParam" ],
622             collections: [
623                 ["params", "Param"]
624             ]
625         ),
626         "SelfParam": (
627             traits: [
628                 "TypeAscriptionOwner",
629             ]
630         ),
631         "Param": (
632             options: [ "Pat" ],
633             traits: [
634                 "TypeAscriptionOwner",
635             ]
636         ),
637         "UseItem": (
638             traits: ["AttrsOwner"],
639             options: [ "UseTree" ],
640         ),
641         "UseTree": (
642             options: [ "Path", "UseTreeList", "Alias" ]
643         ),
644         "Alias": (
645             traits: ["NameOwner"],
646         ),
647         "UseTreeList": (
648             collections: [["use_trees", "UseTree"]]
649         ),
650         "ExternCrateItem": (
651             options: ["NameRef", "Alias"],
652         ),
653         "ArgList": (
654             collections: [
655                 ["args", "Expr"]
656             ]
657         ),
658         "Path": (
659             options: [
660                 ["segment", "PathSegment"],
661                 ["qualifier", "Path"],
662             ]
663         ),
664         "PathSegment": (
665             options: [ "NameRef", "TypeArgList" ]
666         ),
667         "TypeArgList": (collections: [
668             ["type_args", "TypeArg"],
669             ["lifetime_args", "LifetimeArg"],
670             ["assoc_type_args", "AssocTypeArg"],
671         ]),
672         "TypeArg": (options: ["TypeRef"]),
673         "AssocTypeArg": (options: ["NameRef", "TypeRef"]),
674         "LifetimeArg": (),
675
676         "MacroItems": (
677             traits: [ "ModuleItemOwner", "FnDefOwner" ],
678         ),
679
680         "MacroStmts" : (
681             options: [ "Expr" ],
682             collections: [
683                 ["statements", "Stmt"],
684             ],
685         )
686     },
687 )