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