]> git.lizzy.rs Git - rust.git/blob - crates/ra_syntax/src/grammar.ron
Merge #1137
[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     ast: {
252         "SourceFile": (
253             traits: [ "ModuleItemOwner", "FnDefOwner" ],
254             collections: [
255                 ["modules", "Module"],
256             ]
257         ),
258         "FnDef": (
259             traits: [
260                 "VisibilityOwner",
261                 "NameOwner",
262                 "TypeParamsOwner",
263                 "AttrsOwner",
264                 "DocCommentsOwner"
265             ],
266             options: [ "ParamList", ["body", "Block"], "RetType" ],
267         ),
268         "RetType": (options: ["TypeRef"]),
269         "StructDef": (
270             traits: [
271                 "VisibilityOwner",
272                 "NameOwner",
273                 "TypeParamsOwner",
274                 "AttrsOwner",
275                 "DocCommentsOwner"
276             ]
277         ),
278         "NamedFieldDefList": (collections: [["fields", "NamedFieldDef"]]),
279         "NamedFieldDef": (
280             traits: [
281                 "VisibilityOwner",
282                 "NameOwner",
283                 "AttrsOwner",
284                 "DocCommentsOwner",
285                 "TypeAscriptionOwner"
286             ]
287         ),
288         "PosFieldDefList": (collections: [["fields", "PosFieldDef"]]),
289         "PosFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]),
290         "EnumDef": ( traits: [
291             "VisibilityOwner",
292             "NameOwner",
293             "TypeParamsOwner",
294             "AttrsOwner",
295             "DocCommentsOwner"
296         ], options: [["variant_list", "EnumVariantList"]] ),
297         "EnumVariantList": ( collections: [["variants", "EnumVariant"]] ),
298         "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner", "AttrsOwner"], options: ["Expr"] ),
299         "TraitDef": (
300             traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeParamsOwner", "TypeBoundsOwner"],
301             options: ["ItemList"]
302         ),
303         "Module": (
304             traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner" ],
305             options: [ "ItemList" ]
306         ),
307         "ItemList": (
308             collections: [["impl_items", "ImplItem"]],
309             traits: [ "FnDefOwner", "ModuleItemOwner" ],
310         ),
311         "ConstDef": (
312             traits: [
313                 "VisibilityOwner",
314                 "NameOwner",
315                 "TypeParamsOwner",
316                 "AttrsOwner",
317                 "DocCommentsOwner",
318                 "TypeAscriptionOwner",
319             ],
320             options: [ ["body","Expr"]],
321         ),
322         "StaticDef": (
323             traits: [
324                 "VisibilityOwner",
325                 "NameOwner",
326                 "TypeParamsOwner",
327                 "AttrsOwner",
328                 "DocCommentsOwner",
329                 "TypeAscriptionOwner",
330             ],
331             options: [ ["body","Expr"]],
332         ),
333         "TypeAliasDef": (
334             traits: [
335                 "VisibilityOwner",
336                 "NameOwner",
337                 "TypeParamsOwner",
338                 "AttrsOwner",
339                 "DocCommentsOwner",
340                 "TypeBoundsOwner",
341             ],
342             options: ["TypeRef"]
343         ),
344         "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner"]),
345
346         "ParenType": (options: ["TypeRef"]),
347         "TupleType": ( collections: [["fields", "TypeRef"]] ),
348         "NeverType": (),
349         "PathType": (options: ["Path"]),
350         "PointerType": (options: ["TypeRef"]),
351         "ArrayType": ( options: ["TypeRef", "Expr"] ),
352         "SliceType": ( options: ["TypeRef"] ),
353         "ReferenceType": (options: ["TypeRef"]),
354         "PlaceholderType": (),
355         "FnPointerType": (options: ["ParamList", "RetType"]),
356         "ForType": (options: ["TypeRef"]),
357         "ImplTraitType": (
358             traits: ["TypeBoundsOwner"],
359         ),
360         "DynTraitType": (
361             traits: ["TypeBoundsOwner"],
362         ),
363
364         "TypeRef": ( enum: [
365             "ParenType",
366             "TupleType",
367             "NeverType",
368             "PathType",
369             "PointerType",
370             "ArrayType",
371             "SliceType",
372             "ReferenceType",
373             "PlaceholderType",
374             "FnPointerType",
375             "ForType",
376             "ImplTraitType",
377             "DynTraitType",
378         ]),
379
380         "NominalDef": (
381             enum: ["StructDef", "EnumDef"],
382             traits: [
383                 "NameOwner",
384                 "TypeParamsOwner",
385                 "AttrsOwner"
386             ],
387         ),
388         "ModuleItem": (
389             enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "TypeAliasDef", "ImplBlock",
390                    "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ]
391         ),
392         "ImplItem": (
393             enum: ["FnDef", "TypeAliasDef", "ConstDef"]
394         ),
395
396         "TupleExpr": (
397             collections: [["exprs", "Expr"]]
398         ),
399         "ArrayExpr": (
400             collections: [["exprs", "Expr"]]
401         ),
402         "ParenExpr": (options: ["Expr"]),
403         "PathExpr": (options: ["Path"]),
404         "LambdaExpr": (
405             options: [
406                 "ParamList",
407                 ["body", "Expr"],
408             ]
409         ),
410         "IfExpr": (
411             options: [ "Condition" ]
412         ),
413         "LoopExpr": (
414             traits: ["LoopBodyOwner"],
415         ),
416         "ForExpr": (
417             traits: ["LoopBodyOwner"],
418             options: [
419                 "Pat",
420                 ["iterable", "Expr"],
421             ]
422         ),
423         "WhileExpr": (
424             traits: ["LoopBodyOwner"],
425             options: [ "Condition" ]
426         ),
427         "ContinueExpr": (),
428         "BreakExpr": (options: ["Expr"]),
429         "Label": (),
430         "BlockExpr": (
431             options: [ "Block" ]
432         ),
433         "ReturnExpr": (options: ["Expr"]),
434         "MatchExpr": (
435             options: [ "Expr", "MatchArmList" ],
436         ),
437         "MatchArmList": (
438             collections: [ ["arms", "MatchArm"] ],
439             traits: [ "AttrsOwner" ]
440         ),
441         "MatchArm": (
442             options: [
443                 [ "guard", "MatchGuard" ],
444                 "Expr",
445             ],
446             collections: [ [ "pats", "Pat" ] ],
447             traits: [ "AttrsOwner" ]
448         ),
449         "MatchGuard": (options: ["Expr"]),
450         "StructLit": (options: ["Path", "NamedFieldList", ["spread", "Expr"]]),
451         "NamedFieldList": (collections: [ ["fields", "NamedField"] ]),
452         "NamedField": (options: ["NameRef", "Expr"]),
453         "CallExpr": (
454             traits: ["ArgListOwner"],
455             options: [ "Expr" ],
456         ),
457         "MethodCallExpr": (
458             traits: ["ArgListOwner"],
459             options: [ "Expr", "NameRef", "TypeArgList" ],
460         ),
461         "IndexExpr": (),
462         "FieldExpr": (options: ["Expr", "NameRef"]),
463         "TryExpr": (options: ["Expr"]),
464         "CastExpr": (options: ["Expr", "TypeRef"]),
465         "RefExpr": (options: ["Expr"]),
466         "PrefixExpr": (options: ["Expr"]),
467         "RangeExpr": (),
468         "BinExpr": (),
469
470         "Literal": (),
471
472         "Expr": (
473             enum: [
474                 "TupleExpr",
475                 "ArrayExpr",
476                 "ParenExpr",
477                 "PathExpr",
478                 "LambdaExpr",
479                 "IfExpr",
480                 "LoopExpr",
481                 "ForExpr",
482                 "WhileExpr",
483                 "ContinueExpr",
484                 "BreakExpr",
485                 "Label",
486                 "BlockExpr",
487                 "ReturnExpr",
488                 "MatchExpr",
489                 "StructLit",
490                 "CallExpr",
491                 "IndexExpr",
492                 "MethodCallExpr",
493                 "FieldExpr",
494                 "TryExpr",
495                 "CastExpr",
496                 "RefExpr",
497                 "PrefixExpr",
498                 "RangeExpr",
499                 "BinExpr",
500                 "Literal",
501                 "MacroCall",
502             ],
503         ),
504
505         "RefPat": ( options: [ "Pat" ]),
506         "BindPat": (
507             options: [ "Pat" ],
508             traits: ["NameOwner"]
509         ),
510         "PlaceholderPat": (),
511         "PathPat": ( options: [ "Path" ] ),
512         "StructPat": ( options: ["FieldPatList", "Path"] ),
513         "FieldPatList": (
514             collections: [
515                 ["field_pats", "FieldPat"],
516                 ["bind_pats", "BindPat"],
517             ]
518         ),
519         "FieldPat": (
520             traits: ["NameOwner"],
521             options: ["Pat"]
522         ),
523         "TupleStructPat": (
524             options: ["Path"],
525             collections: [["args", "Pat"]],
526         ),
527         "TuplePat": ( collections: [["args", "Pat"]] ),
528         "SlicePat": (),
529         "RangePat": (),
530         "LiteralPat": (options: ["Literal"]),
531
532         "Pat": (
533             enum: [
534                 "RefPat",
535                 "BindPat",
536                 "PlaceholderPat",
537                 "PathPat",
538                 "StructPat",
539                 "TupleStructPat",
540                 "TuplePat",
541                 "SlicePat",
542                 "RangePat",
543                 "LiteralPat",
544             ],
545         ),
546
547         "Visibility": (),
548         "Name": (),
549         "NameRef": (),
550         "MacroCall": (
551             traits: [ "NameOwner", "AttrsOwner" ],
552             options: [ "TokenTree", "Path" ],
553         ),
554         "Attr": ( options: [ ["value", "TokenTree"] ] ),
555         "TokenTree": (),
556         "TypeParamList": (
557             collections: [
558                 ["type_params", "TypeParam" ],
559                 ["lifetime_params", "LifetimeParam" ],
560             ]
561         ),
562         "TypeParam": ( traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner"] ),
563         "LifetimeParam": (
564             traits: ["AttrsOwner"],
565         ),
566         "TypeBound": (
567             options: [
568                 "TypeRef",
569             ]
570         ),
571         "TypeBoundList": (
572             collections: [
573                 ["bounds", "TypeBound"],
574             ]
575         ),
576         "WherePred": (
577             options: [
578                 "TypeRef",
579             ],
580             traits: [
581                 "TypeBoundsOwner",
582             ],
583         ),
584         "WhereClause": (
585             collections: [
586                 ["predicates", "WherePred"],
587             ],
588         ),
589         "ExprStmt": (
590             options: [ ["expr", "Expr"] ]
591         ),
592         "LetStmt": (
593             options: [
594                 ["pat", "Pat"],
595                 ["initializer", "Expr"],
596             ],
597             traits: [
598                 "TypeAscriptionOwner",
599             ]
600         ),
601         "Condition": (
602             options: [ "Pat", "Expr" ]
603         ),
604         "Stmt": (
605             enum: ["ExprStmt", "LetStmt"],
606         ),
607         "Block": (
608             options: [ "Expr" ],
609             collections: [
610                 ["statements", "Stmt"],
611             ],
612             traits: [
613                 "AttrsOwner",
614             ]
615         ),
616         "ParamList": (
617             options: [ "SelfParam" ],
618             collections: [
619                 ["params", "Param"]
620             ]
621         ),
622         "SelfParam": (
623             traits: [
624                 "TypeAscriptionOwner",
625             ]
626         ),
627         "Param": (
628             options: [ "Pat" ],
629             traits: [
630                 "TypeAscriptionOwner",
631             ]
632         ),
633         "UseItem": (
634             traits: ["AttrsOwner"],
635             options: [ "UseTree" ],
636         ),
637         "UseTree": (
638             options: [ "Path", "UseTreeList", "Alias" ]
639         ),
640         "Alias": (
641             traits: ["NameOwner"],
642         ),
643         "UseTreeList": (
644             collections: [["use_trees", "UseTree"]]
645         ),
646         "ExternCrateItem": (
647             options: ["NameRef", "Alias"],
648         ),
649         "ArgList": (
650             collections: [
651                 ["args", "Expr"]
652             ]
653         ),
654         "Path": (
655             options: [
656                 ["segment", "PathSegment"],
657                 ["qualifier", "Path"],
658             ]
659         ),
660         "PathSegment": (
661             options: [ "NameRef", "TypeArgList" ]
662         ),
663         "TypeArgList": (collections: [
664             ["type_args", "TypeArg"],
665             ["lifetime_args", "LifetimeArg"],
666             ["assoc_type_args", "AssocTypeArg"],
667         ]),
668         "TypeArg": (options: ["TypeRef"]),
669         "AssocTypeArg": (options: ["NameRef", "TypeRef"]),
670         "LifetimeArg": (),
671     },
672 )