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