]> git.lizzy.rs Git - rust.git/blob - crates/ra_syntax/src/grammar.ron
Add `ModuleItemsOwner` to `Block`
[rust.git] / crates / ra_syntax / src / grammar.ron
1 // Stores definitions which must be used in multiple places
2 // See `cargo xtask codegen` (defined in xtasks/src/main.rs)
3 Grammar(
4     punct: [
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         (".", "DOT"),
29         ("..", "DOTDOT"),
30         ("...", "DOTDOTDOT"),
31         ("..=", "DOTDOTEQ"),
32         (":", "COLON"),
33         ("::", "COLONCOLON"),
34         ("=", "EQ"),
35         ("==", "EQEQ"),
36         ("=>", "FAT_ARROW"),
37         ("!", "EXCL"),
38         ("!=", "NEQ"),
39         ("-", "MINUS"),
40         ("->", "THIN_ARROW"),
41         ("<=", "LTEQ"),
42         (">=", "GTEQ"),
43         ("+=", "PLUSEQ"),
44         ("-=", "MINUSEQ"),
45         ("|=", "PIPEEQ"),
46         ("&=", "AMPEQ"),
47         ("^=", "CARETEQ"),
48         ("/=", "SLASHEQ"),
49         ("*=", "STAREQ"),
50         ("%=", "PERCENTEQ"),
51         ("&&", "AMPAMP"),
52         ("||", "PIPEPIPE"),
53         ("<<", "SHL"),
54         (">>", "SHR"),
55         ("<<=", "SHLEQ"),
56         (">>=", "SHREQ"),
57     ],
58     keywords: [
59         "async",
60         "use",
61         "fn",
62         "struct",
63         "enum",
64         "trait",
65         "impl",
66         "dyn",
67         "true",
68         "false",
69         "as",
70         "extern",
71         "crate",
72         "mod",
73         "pub",
74         "self",
75         "super",
76         "in",
77         "where",
78         "for",
79         "loop",
80         "while",
81         "continue",
82         "break",
83         "if",
84         "else",
85         "match",
86         "const",
87         "static",
88         "mut",
89         "unsafe",
90         "type",
91         "ref",
92         "let",
93         "move",
94         "return",
95         "try",
96         "box",
97         "await"
98     ],
99     contextual_keywords: [
100         "auto",
101         "default",
102         "existential",
103         "union",
104     ],
105     literals: [
106         "INT_NUMBER",
107         "FLOAT_NUMBER",
108         "CHAR",
109         "BYTE",
110         "STRING",
111         "RAW_STRING",
112         "BYTE_STRING",
113         "RAW_BYTE_STRING",
114     ],
115     tokens: [
116         "ERROR",
117         "IDENT",
118         "WHITESPACE",
119         "LIFETIME",
120         "COMMENT",
121         "SHEBANG",
122         "L_DOLLAR",
123         "R_DOLLAR",
124     ],
125     nodes: [
126         "SOURCE_FILE",
127
128         "STRUCT_DEF",
129         "UNION_DEF",
130         "ENUM_DEF",
131         "FN_DEF",
132         "RET_TYPE",
133         "EXTERN_CRATE_ITEM",
134         "MODULE",
135         "USE_ITEM",
136         "STATIC_DEF",
137         "CONST_DEF",
138         "TRAIT_DEF",
139         "IMPL_BLOCK",
140         "TYPE_ALIAS_DEF",
141         "MACRO_CALL",
142         "TOKEN_TREE",
143
144         "PAREN_TYPE",
145         "TUPLE_TYPE",
146         "NEVER_TYPE",
147         "PATH_TYPE",
148         "POINTER_TYPE",
149         "ARRAY_TYPE",
150         "SLICE_TYPE",
151         "REFERENCE_TYPE",
152         "PLACEHOLDER_TYPE",
153         "FN_POINTER_TYPE",
154         "FOR_TYPE",
155         "IMPL_TRAIT_TYPE",
156         "DYN_TRAIT_TYPE",
157
158         "REF_PAT",
159         "BOX_PAT",
160         "BIND_PAT",
161         "PLACEHOLDER_PAT",
162         "DOT_DOT_PAT",
163         "PATH_PAT",
164         "RECORD_PAT",
165         "RECORD_FIELD_PAT_LIST",
166         "RECORD_FIELD_PAT",
167         "TUPLE_STRUCT_PAT",
168         "TUPLE_PAT",
169         "SLICE_PAT",
170         "RANGE_PAT",
171         "LITERAL_PAT",
172
173         // atoms
174         "TUPLE_EXPR",
175         "ARRAY_EXPR",
176         "PAREN_EXPR",
177         "PATH_EXPR",
178         "LAMBDA_EXPR",
179         "IF_EXPR",
180         "WHILE_EXPR",
181         "CONDITION",
182         "LOOP_EXPR",
183         "FOR_EXPR",
184         "CONTINUE_EXPR",
185         "BREAK_EXPR",
186         "LABEL",
187         "BLOCK_EXPR",
188         "RETURN_EXPR",
189         "MATCH_EXPR",
190         "MATCH_ARM_LIST",
191         "MATCH_ARM",
192         "MATCH_GUARD",
193         "RECORD_LIT",
194         "RECORD_FIELD_LIST",
195         "RECORD_FIELD",
196         "TRY_BLOCK_EXPR",
197         "BOX_EXPR",
198
199         // postfix
200         "CALL_EXPR",
201         "INDEX_EXPR",
202         "METHOD_CALL_EXPR",
203         "FIELD_EXPR",
204         "AWAIT_EXPR",
205         "TRY_EXPR",
206         "CAST_EXPR",
207
208         // unary
209         "REF_EXPR",
210         "PREFIX_EXPR",
211
212         "RANGE_EXPR", // just weird
213         "BIN_EXPR",
214
215         "BLOCK",
216         "EXTERN_BLOCK",
217         "EXTERN_ITEM_LIST",
218         "ENUM_VARIANT",
219         "RECORD_FIELD_DEF_LIST",
220         "RECORD_FIELD_DEF",
221         "TUPLE_FIELD_DEF_LIST",
222         "TUPLE_FIELD_DEF",
223         "ENUM_VARIANT_LIST",
224         "ITEM_LIST",
225         "ATTR",
226         "META_ITEM", // not an item actually
227         "USE_TREE",
228         "USE_TREE_LIST",
229         "PATH",
230         "PATH_SEGMENT",
231         "LITERAL",
232         "ALIAS",
233         "VISIBILITY",
234         "WHERE_CLAUSE",
235         "WHERE_PRED",
236         "ABI",
237         "NAME",
238         "NAME_REF",
239
240         "LET_STMT",
241         "EXPR_STMT",
242
243         "TYPE_PARAM_LIST",
244         "LIFETIME_PARAM",
245         "TYPE_PARAM",
246         "TYPE_ARG_LIST",
247         "LIFETIME_ARG",
248         "TYPE_ARG",
249         "ASSOC_TYPE_ARG",
250
251         "PARAM_LIST",
252         "PARAM",
253         "SELF_PARAM",
254         "ARG_LIST",
255         "TYPE_BOUND",
256         "TYPE_BOUND_LIST",
257
258         // macro related
259         "MACRO_ITEMS",
260         "MACRO_STMTS",
261     ],
262     ast: {
263         "SourceFile": (
264             traits: [ "ModuleItemOwner", "FnDefOwner" ],
265             collections: [
266                 ("modules", "Module"),
267             ]
268         ),
269         "FnDef": (
270             traits: [
271                 "VisibilityOwner",
272                 "NameOwner",
273                 "TypeParamsOwner",
274                 "AttrsOwner",
275                 "DocCommentsOwner"
276             ],
277             options: [ "ParamList", ["body", "BlockExpr"], "RetType" ],
278         ),
279         "RetType": (options: ["TypeRef"]),
280         "StructDef": (
281             traits: [
282                 "VisibilityOwner",
283                 "NameOwner",
284                 "TypeParamsOwner",
285                 "AttrsOwner",
286                 "DocCommentsOwner"
287             ]
288         ),
289         "UnionDef": (
290             traits: [
291                 "VisibilityOwner",
292                 "NameOwner",
293                 "TypeParamsOwner",
294                 "AttrsOwner",
295                 "DocCommentsOwner"
296             ],
297             options: ["RecordFieldDefList"],
298         ),
299         "RecordFieldDefList": (collections: [("fields", "RecordFieldDef")]),
300         "RecordFieldDef": (
301             traits: [
302                 "VisibilityOwner",
303                 "NameOwner",
304                 "AttrsOwner",
305                 "DocCommentsOwner",
306                 "TypeAscriptionOwner"
307             ]
308         ),
309         "TupleFieldDefList": (collections: [("fields", "TupleFieldDef")]),
310         "TupleFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]),
311         "EnumDef": ( traits: [
312             "VisibilityOwner",
313             "NameOwner",
314             "TypeParamsOwner",
315             "AttrsOwner",
316             "DocCommentsOwner"
317         ], options: [["variant_list", "EnumVariantList"]] ),
318         "EnumVariantList": ( collections: [("variants", "EnumVariant")] ),
319         "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner", "AttrsOwner"], options: ["Expr"] ),
320         "TraitDef": (
321             traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeParamsOwner", "TypeBoundsOwner"],
322             options: ["ItemList"]
323         ),
324         "Module": (
325             traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner" ],
326             options: [ "ItemList" ]
327         ),
328         "ItemList": (
329             collections: [("impl_items", "ImplItem")],
330             traits: [ "FnDefOwner", "ModuleItemOwner" ],
331         ),
332         "ConstDef": (
333             traits: [
334                 "VisibilityOwner",
335                 "NameOwner",
336                 "TypeParamsOwner",
337                 "AttrsOwner",
338                 "DocCommentsOwner",
339                 "TypeAscriptionOwner",
340             ],
341             options: [ ["body","Expr"]],
342         ),
343         "StaticDef": (
344             traits: [
345                 "VisibilityOwner",
346                 "NameOwner",
347                 "TypeParamsOwner",
348                 "AttrsOwner",
349                 "DocCommentsOwner",
350                 "TypeAscriptionOwner",
351             ],
352             options: [ ["body","Expr"]],
353         ),
354         "TypeAliasDef": (
355             traits: [
356                 "VisibilityOwner",
357                 "NameOwner",
358                 "TypeParamsOwner",
359                 "AttrsOwner",
360                 "DocCommentsOwner",
361                 "TypeBoundsOwner",
362             ],
363             options: ["TypeRef"]
364         ),
365         "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner", "AttrsOwner"]),
366
367         "ParenType": (options: ["TypeRef"]),
368         "TupleType": ( collections: [("fields", "TypeRef")] ),
369         "NeverType": (),
370         "PathType": (options: ["Path"]),
371         "PointerType": (options: ["TypeRef"]),
372         "ArrayType": ( options: ["TypeRef", "Expr"] ),
373         "SliceType": ( options: ["TypeRef"] ),
374         "ReferenceType": (options: ["TypeRef"]),
375         "PlaceholderType": (),
376         "FnPointerType": (options: ["ParamList", "RetType"]),
377         "ForType": (options: ["TypeRef"]),
378         "ImplTraitType": (
379             traits: ["TypeBoundsOwner"],
380         ),
381         "DynTraitType": (
382             traits: ["TypeBoundsOwner"],
383         ),
384
385         "TypeRef": ( enum: [
386             "ParenType",
387             "TupleType",
388             "NeverType",
389             "PathType",
390             "PointerType",
391             "ArrayType",
392             "SliceType",
393             "ReferenceType",
394             "PlaceholderType",
395             "FnPointerType",
396             "ForType",
397             "ImplTraitType",
398             "DynTraitType",
399         ]),
400
401         "NominalDef": (
402             enum: ["StructDef", "EnumDef", "UnionDef"],
403             traits: [
404                 "NameOwner",
405                 "TypeParamsOwner",
406                 "AttrsOwner"
407             ],
408         ),
409         "ModuleItem": (
410             enum: ["StructDef", "UnionDef", "EnumDef", "FnDef", "TraitDef", "TypeAliasDef", "ImplBlock",
411                    "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ],
412             traits: ["AttrsOwner"],
413         ),
414         "ImplItem": (
415             enum: ["FnDef", "TypeAliasDef", "ConstDef"],
416             traits: ["AttrsOwner"]
417         ),
418
419         "TupleExpr": (
420             collections: [("exprs", "Expr")]
421         ),
422         "ArrayExpr": (
423             collections: [("exprs", "Expr")]
424         ),
425         "ParenExpr": (options: ["Expr"]),
426         "PathExpr": (options: ["Path"]),
427         "LambdaExpr": (
428             options: [
429                 "ParamList",
430                 ["body", "Expr"],
431             ]
432         ),
433         "IfExpr": (
434             options: [ "Condition" ]
435         ),
436         "LoopExpr": (
437             traits: ["LoopBodyOwner"],
438         ),
439         "TryBlockExpr": (
440             options: [["body", "BlockExpr"]],
441         ),
442         "ForExpr": (
443             traits: ["LoopBodyOwner"],
444             options: [
445                 "Pat",
446                 ["iterable", "Expr"],
447             ]
448         ),
449         "WhileExpr": (
450             traits: ["LoopBodyOwner"],
451             options: [ "Condition" ]
452         ),
453         "ContinueExpr": (),
454         "BreakExpr": (options: ["Expr"]),
455         "Label": (),
456         "BlockExpr": (
457             options: [ "Block" ]
458         ),
459         "ReturnExpr": (options: ["Expr"]),
460         "MatchExpr": (
461             options: [ "Expr", "MatchArmList" ],
462         ),
463         "MatchArmList": (
464             collections: [ ("arms", "MatchArm") ],
465             traits: [ "AttrsOwner" ]
466         ),
467         "MatchArm": (
468             options: [
469                 [ "guard", "MatchGuard" ],
470                 "Expr",
471             ],
472             collections: [ ("pats", "Pat") ],
473             traits: [ "AttrsOwner" ]
474         ),
475         "MatchGuard": (options: ["Expr"]),
476         "RecordLit": (options: ["Path", "RecordFieldList"]),
477         "RecordFieldList": (
478             collections: [ ("fields", "RecordField") ],
479             options: [["spread", "Expr"]]
480         ),
481         "RecordField": (options: ["NameRef", "Expr"]),
482         "CallExpr": (
483             traits: ["ArgListOwner"],
484             options: [ "Expr" ],
485         ),
486         "MethodCallExpr": (
487             traits: ["ArgListOwner"],
488             options: [ "Expr", "NameRef", "TypeArgList" ],
489         ),
490         "IndexExpr": (),
491         "FieldExpr": (options: ["Expr", "NameRef"]),
492         "AwaitExpr": (options: ["Expr"]),
493         "TryExpr": (options: ["Expr"]),
494         "CastExpr": (options: ["Expr", "TypeRef"]),
495         "RefExpr": (options: ["Expr"]),
496         "PrefixExpr": (options: ["Expr"]),
497         "BoxExpr": (options: ["Expr"]),
498         "RangeExpr": (),
499         "BinExpr": (),
500
501         "Literal": (),
502
503         "Expr": (
504             enum: [
505                 "TupleExpr",
506                 "ArrayExpr",
507                 "ParenExpr",
508                 "PathExpr",
509                 "LambdaExpr",
510                 "IfExpr",
511                 "LoopExpr",
512                 "ForExpr",
513                 "WhileExpr",
514                 "ContinueExpr",
515                 "BreakExpr",
516                 "Label",
517                 "BlockExpr",
518                 "ReturnExpr",
519                 "MatchExpr",
520                 "RecordLit",
521                 "CallExpr",
522                 "IndexExpr",
523                 "MethodCallExpr",
524                 "FieldExpr",
525                 "AwaitExpr",
526                 "TryExpr",
527                 "TryBlockExpr",
528                 "CastExpr",
529                 "RefExpr",
530                 "PrefixExpr",
531                 "RangeExpr",
532                 "BinExpr",
533                 "Literal",
534                 "MacroCall",
535                 "BoxExpr",
536             ],
537         ),
538
539         "RefPat": ( options: [ "Pat" ]),
540         "BoxPat": ( options: [ "Pat" ]),
541         "BindPat": (
542             options: [ "Pat" ],
543             traits: ["NameOwner"]
544         ),
545         "PlaceholderPat": (),
546         "DotDotPat": (),
547         "PathPat": ( options: [ "Path" ] ),
548         "RecordPat": ( options: ["RecordFieldPatList", "Path"] ),
549         "RecordFieldPatList": (
550             collections: [
551                 ("record_field_pats", "RecordFieldPat"),
552                 ("bind_pats", "BindPat"),
553             ]
554         ),
555         "RecordFieldPat": (
556             traits: ["NameOwner"],
557             options: ["Pat"]
558         ),
559         "TupleStructPat": (
560             options: ["Path"],
561             collections: [("args", "Pat")],
562         ),
563         "TuplePat": ( collections: [("args", "Pat")] ),
564         "SlicePat": (),
565         "RangePat": (),
566         "LiteralPat": (options: ["Literal"]),
567
568         "Pat": (
569             enum: [
570                 "RefPat",
571                 "BoxPat",
572                 "BindPat",
573                 "PlaceholderPat",
574                 "DotDotPat",
575                 "PathPat",
576                 "RecordPat",
577                 "TupleStructPat",
578                 "TuplePat",
579                 "SlicePat",
580                 "RangePat",
581                 "LiteralPat",
582             ],
583         ),
584
585         "Visibility": (),
586         "Name": (),
587         "NameRef": (),
588         "MacroCall": (
589             traits: [ "NameOwner", "AttrsOwner","DocCommentsOwner" ],
590             options: [ "TokenTree", "Path" ],
591         ),
592         "AttrInput": ( enum: [ "Literal", "TokenTree" ] ),
593         "Attr": ( options: [ "Path", [ "input", "AttrInput" ] ] ),
594         "TokenTree": (),
595         "TypeParamList": (
596             collections: [
597                 ("type_params", "TypeParam" ),
598                 ("lifetime_params", "LifetimeParam" ),
599             ]
600         ),
601         "TypeParam": (
602             options: [("default_type", "TypeRef")],
603             traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner"],
604         ),
605         "LifetimeParam": (
606             traits: ["AttrsOwner"],
607         ),
608         "TypeBound": (
609             options: [
610                 "TypeRef",
611             ]
612         ),
613         "TypeBoundList": (
614             collections: [
615                 ("bounds", "TypeBound"),
616             ]
617         ),
618         "WherePred": (
619             options: [
620                 "TypeRef",
621             ],
622             traits: [
623                 "TypeBoundsOwner",
624             ],
625         ),
626         "WhereClause": (
627             collections: [
628                 ("predicates", "WherePred"),
629             ],
630         ),
631         "ExprStmt": (
632             options: [ ["expr", "Expr"] ]
633         ),
634         "LetStmt": (
635             options: [
636                 ["pat", "Pat"],
637                 ["initializer", "Expr"],
638             ],
639             traits: [
640                 "TypeAscriptionOwner",
641             ]
642         ),
643         "Condition": (
644             options: [ "Pat", "Expr" ]
645         ),
646         "Stmt": (
647             enum: ["ExprStmt", "LetStmt"],
648         ),
649         "Block": (
650             options: [ "Expr" ],
651             collections: [
652                 ("statements", "Stmt"),
653             ],
654             traits: [
655                 "AttrsOwner",
656                 "ModuleItemOwner",
657             ]
658         ),
659         "ParamList": (
660             options: [ "SelfParam" ],
661             collections: [
662                 ("params", "Param"),
663             ]
664         ),
665         "SelfParam": (
666             traits: [
667                 "TypeAscriptionOwner",
668                 "AttrsOwner",
669             ]
670         ),
671         "Param": (
672             options: [ "Pat" ],
673             traits: [
674                 "TypeAscriptionOwner",
675                 "AttrsOwner",
676             ]
677         ),
678         "UseItem": (
679             traits: ["AttrsOwner"],
680             options: [ "UseTree" ],
681         ),
682         "UseTree": (
683             options: [ "Path", "UseTreeList", "Alias" ]
684         ),
685         "Alias": (
686             traits: ["NameOwner"],
687         ),
688         "UseTreeList": (
689             collections: [("use_trees", "UseTree")]
690         ),
691         "ExternCrateItem": (
692             traits: ["AttrsOwner"],
693             options: ["NameRef", "Alias"],
694         ),
695         "ArgList": (
696             collections: [
697                 ("args", "Expr"),
698             ]
699         ),
700         "Path": (
701             options: [
702                 ["segment", "PathSegment"],
703                 ["qualifier", "Path"],
704             ]
705         ),
706         "PathSegment": (
707             options: [ "NameRef", "TypeArgList", "ParamList", "RetType", "PathType" ]
708         ),
709         "TypeArgList": (collections: [
710             ("type_args", "TypeArg"),
711             ("lifetime_args", "LifetimeArg"),
712             ("assoc_type_args", "AssocTypeArg"),
713         ]),
714         "TypeArg": (options: ["TypeRef"]),
715         "AssocTypeArg": (options: ["NameRef", "TypeRef"]),
716         "LifetimeArg": (),
717
718         "MacroItems": (
719             traits: [ "ModuleItemOwner", "FnDefOwner" ],
720         ),
721
722         "MacroStmts" : (
723             options: [ "Expr" ],
724             collections: [
725                 ("statements", "Stmt"),
726             ],
727         )
728     },
729 )