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