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