]> git.lizzy.rs Git - rust.git/blob - crates/ra_syntax/src/grammar.ron
Pass attributes as token tree to DefCollector
[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     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         ),
406
407         "TupleExpr": (
408             collections: [("exprs", "Expr")]
409         ),
410         "ArrayExpr": (
411             collections: [("exprs", "Expr")]
412         ),
413         "ParenExpr": (options: ["Expr"]),
414         "PathExpr": (options: ["Path"]),
415         "LambdaExpr": (
416             options: [
417                 "ParamList",
418                 ["body", "Expr"],
419             ]
420         ),
421         "IfExpr": (
422             options: [ "Condition" ]
423         ),
424         "LoopExpr": (
425             traits: ["LoopBodyOwner"],
426         ),
427         "TryBlockExpr": (
428             options: [["body", "BlockExpr"]],
429         ),
430         "ForExpr": (
431             traits: ["LoopBodyOwner"],
432             options: [
433                 "Pat",
434                 ["iterable", "Expr"],
435             ]
436         ),
437         "WhileExpr": (
438             traits: ["LoopBodyOwner"],
439             options: [ "Condition" ]
440         ),
441         "ContinueExpr": (),
442         "BreakExpr": (options: ["Expr"]),
443         "Label": (),
444         "BlockExpr": (
445             options: [ "Block" ]
446         ),
447         "ReturnExpr": (options: ["Expr"]),
448         "MatchExpr": (
449             options: [ "Expr", "MatchArmList" ],
450         ),
451         "MatchArmList": (
452             collections: [ ("arms", "MatchArm") ],
453             traits: [ "AttrsOwner" ]
454         ),
455         "MatchArm": (
456             options: [
457                 [ "guard", "MatchGuard" ],
458                 "Expr",
459             ],
460             collections: [ ("pats", "Pat") ],
461             traits: [ "AttrsOwner" ]
462         ),
463         "MatchGuard": (options: ["Expr"]),
464         "RecordLit": (options: ["Path", "RecordFieldList"]),
465         "RecordFieldList": (
466             collections: [ ("fields", "RecordField") ],
467             options: [["spread", "Expr"]]
468         ),
469         "RecordField": (options: ["NameRef", "Expr"]),
470         "CallExpr": (
471             traits: ["ArgListOwner"],
472             options: [ "Expr" ],
473         ),
474         "MethodCallExpr": (
475             traits: ["ArgListOwner"],
476             options: [ "Expr", "NameRef", "TypeArgList" ],
477         ),
478         "IndexExpr": (),
479         "FieldExpr": (options: ["Expr", "NameRef"]),
480         "AwaitExpr": (options: ["Expr"]),
481         "TryExpr": (options: ["Expr"]),
482         "CastExpr": (options: ["Expr", "TypeRef"]),
483         "RefExpr": (options: ["Expr"]),
484         "PrefixExpr": (options: ["Expr"]),
485         "BoxExpr": (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                 "BoxExpr",
524             ],
525         ),
526
527         "RefPat": ( options: [ "Pat" ]),
528         "BoxPat": ( options: [ "Pat" ]),
529         "BindPat": (
530             options: [ "Pat" ],
531             traits: ["NameOwner"]
532         ),
533         "PlaceholderPat": (),
534         "DotDotPat": (),
535         "PathPat": ( options: [ "Path" ] ),
536         "RecordPat": ( options: ["RecordFieldPatList", "Path"] ),
537         "RecordFieldPatList": (
538             collections: [
539                 ("record_field_pats", "RecordFieldPat"),
540                 ("bind_pats", "BindPat"),
541             ]
542         ),
543         "RecordFieldPat": (
544             traits: ["NameOwner"],
545             options: ["Pat"]
546         ),
547         "TupleStructPat": (
548             options: ["Path"],
549             collections: [("args", "Pat")],
550         ),
551         "TuplePat": ( collections: [("args", "Pat")] ),
552         "SlicePat": (),
553         "RangePat": (),
554         "LiteralPat": (options: ["Literal"]),
555
556         "Pat": (
557             enum: [
558                 "RefPat",
559                 "BoxPat",
560                 "BindPat",
561                 "PlaceholderPat",
562                 "DotDotPat",
563                 "PathPat",
564                 "RecordPat",
565                 "TupleStructPat",
566                 "TuplePat",
567                 "SlicePat",
568                 "RangePat",
569                 "LiteralPat",
570             ],
571         ),
572
573         "Visibility": (),
574         "Name": (),
575         "NameRef": (),
576         "MacroCall": (
577             traits: [ "NameOwner", "AttrsOwner","DocCommentsOwner" ],
578             options: [ "TokenTree", "Path" ],
579         ),
580         "AttrInput": ( enum: [ "Literal", "TokenTree" ] ),
581         "Attr": ( options: [ "Path", [ "input", "AttrInput" ] ] ),
582         "TokenTree": (),
583         "TypeParamList": (
584             collections: [
585                 ("type_params", "TypeParam" ),
586                 ("lifetime_params", "LifetimeParam" ),
587             ]
588         ),
589         "TypeParam": ( traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner", "DefaultTypeParamOwner"] ),
590         "LifetimeParam": (
591             traits: ["AttrsOwner"],
592         ),
593         "TypeBound": (
594             options: [
595                 "TypeRef",
596             ]
597         ),
598         "TypeBoundList": (
599             collections: [
600                 ("bounds", "TypeBound"),
601             ]
602         ),
603         "WherePred": (
604             options: [
605                 "TypeRef",
606             ],
607             traits: [
608                 "TypeBoundsOwner",
609             ],
610         ),
611         "WhereClause": (
612             collections: [
613                 ("predicates", "WherePred"),
614             ],
615         ),
616         "ExprStmt": (
617             options: [ ["expr", "Expr"] ]
618         ),
619         "LetStmt": (
620             options: [
621                 ["pat", "Pat"],
622                 ["initializer", "Expr"],
623             ],
624             traits: [
625                 "TypeAscriptionOwner",
626             ]
627         ),
628         "Condition": (
629             options: [ "Pat", "Expr" ]
630         ),
631         "Stmt": (
632             enum: ["ExprStmt", "LetStmt"],
633         ),
634         "Block": (
635             options: [ "Expr" ],
636             collections: [
637                 ("statements", "Stmt"),
638             ],
639             traits: [
640                 "AttrsOwner",
641             ]
642         ),
643         "ParamList": (
644             options: [ "SelfParam" ],
645             collections: [
646                 ("params", "Param"),
647             ]
648         ),
649         "SelfParam": (
650             traits: [
651                 "TypeAscriptionOwner",
652                                 "AttrsOwner",
653             ]
654         ),
655         "Param": (
656             options: [ "Pat" ],
657             traits: [
658                 "TypeAscriptionOwner",
659                                 "AttrsOwner",
660             ]
661         ),
662         "UseItem": (
663             traits: ["AttrsOwner"],
664             options: [ "UseTree" ],
665         ),
666         "UseTree": (
667             options: [ "Path", "UseTreeList", "Alias" ]
668         ),
669         "Alias": (
670             traits: ["NameOwner"],
671         ),
672         "UseTreeList": (
673             collections: [("use_trees", "UseTree")]
674         ),
675         "ExternCrateItem": (
676             traits: ["AttrsOwner"],
677             options: ["NameRef", "Alias"],
678         ),
679         "ArgList": (
680             collections: [
681                 ("args", "Expr"),
682             ]
683         ),
684         "Path": (
685             options: [
686                 ["segment", "PathSegment"],
687                 ["qualifier", "Path"],
688             ]
689         ),
690         "PathSegment": (
691             options: [ "NameRef", "TypeArgList", "ParamList", "RetType", "PathType" ]
692         ),
693         "TypeArgList": (collections: [
694             ("type_args", "TypeArg"),
695             ("lifetime_args", "LifetimeArg"),
696             ("assoc_type_args", "AssocTypeArg"),
697         ]),
698         "TypeArg": (options: ["TypeRef"]),
699         "AssocTypeArg": (options: ["NameRef", "TypeRef"]),
700         "LifetimeArg": (),
701
702         "MacroItems": (
703             traits: [ "ModuleItemOwner", "FnDefOwner" ],
704         ),
705
706         "MacroStmts" : (
707             options: [ "Expr" ],
708             collections: [
709                 ("statements", "Stmt"),
710             ],
711         )
712     },
713 )