]> git.lizzy.rs Git - rust.git/blob - crates/ra_syntax/src/grammar.ron
Add trait ast::TypeBoundsOwner
[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         "IntNumber": ( traits: ["AstToken"] ),
467         "FloatNumber": ( traits: ["AstToken"] ),
468         "String": ( traits: ["AstToken"] ),
469         "RawString": ( traits: ["AstToken"] ),
470         "Byte": ( traits: ["AstToken"] ),
471         "RawByteString": ( traits: ["AstToken"] ),
472         "ByteString": ( traits: ["AstToken"] ),
473         "Char": ( traits: ["AstToken"] ),
474         "TrueKw": ( traits: ["AstToken"] ),
475         "FalseKw": ( traits: ["AstToken"] ),
476         "LiteralExpr": (
477             enum: [
478                 "String",
479                 "ByteString",
480                 "RawString",
481                 "RawByteString",
482                 "Char",
483                 "Byte",
484                 "IntNumber",
485                 "FloatNumber",
486                 "TrueKw",
487                 "FalseKw",
488             ]
489         ),
490         "Literal": (options: ["LiteralExpr"]),
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                 "StructLit",
510                 "CallExpr",
511                 "IndexExpr",
512                 "MethodCallExpr",
513                 "FieldExpr",
514                 "TryExpr",
515                 "CastExpr",
516                 "RefExpr",
517                 "PrefixExpr",
518                 "RangeExpr",
519                 "BinExpr",
520                 "Literal",
521             ],
522         ),
523
524         "RefPat": ( options: [ "Pat" ]),
525         "BindPat": (
526             options: [ "Pat" ],
527             traits: ["NameOwner"]
528         ),
529         "PlaceholderPat": (),
530         "PathPat": ( options: [ "Path" ] ),
531         "StructPat": ( options: ["FieldPatList", "Path"] ),
532         "FieldPatList": (
533             collections: [
534                 ["field_pats", "FieldPat"],
535                 ["bind_pats", "BindPat"],
536             ]
537         ),
538         "FieldPat": (
539             traits: ["NameOwner"],
540             options: ["Pat"]
541         ),
542         "TupleStructPat": (
543             options: ["Path"],
544             collections: [["args", "Pat"]],
545         ),
546         "TuplePat": ( collections: [["args", "Pat"]] ),
547         "SlicePat": (),
548         "RangePat": (),
549         "LiteralPat": (options: ["Literal"]),
550
551         "Pat": (
552             enum: [
553                 "RefPat",
554                 "BindPat",
555                 "PlaceholderPat",
556                 "PathPat",
557                 "StructPat",
558                 "TupleStructPat",
559                 "TuplePat",
560                 "SlicePat",
561                 "RangePat",
562                 "LiteralPat",
563             ],
564         ),
565
566         "Visibility": (),
567         "Name": (),
568         "NameRef": (),
569         "MacroCall": (
570             traits: [ "NameOwner", "AttrsOwner" ],
571             options: [ "TokenTree", "Path" ],
572         ),
573         "Attr": ( options: [ ["value", "TokenTree"] ] ),
574         "TokenTree": (),
575         "TypeParamList": (
576             collections: [
577                 ["type_params", "TypeParam" ],
578                 ["lifetime_params", "LifetimeParam" ],
579             ]
580         ),
581         "TypeParam": ( traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner"] ),
582         "LifetimeParam": (
583             options: [ "Lifetime"],
584             traits: ["AttrsOwner"],
585         ),
586         "Lifetime": ( traits: ["AstToken"] ),
587         "TypeBound": (
588             options: [
589                 "TypeRef",
590                 "Lifetime",
591             ]
592         ),
593         "TypeBoundList": (
594             collections: [
595                 ["bounds", "TypeBound"],
596             ]
597         ),
598         "WhereClause": (),
599         "ExprStmt": (
600             options: [ ["expr", "Expr"] ]
601         ),
602         "LetStmt": (
603             options: [
604                 ["pat", "Pat"],
605                 ["initializer", "Expr"],
606             ],
607             traits: [
608                 "TypeAscriptionOwner",
609             ]
610         ),
611         "Condition": (
612             options: [ "Pat", "Expr" ]
613         ),
614         "Stmt": (
615             enum: ["ExprStmt", "LetStmt"],
616         ),
617         "Block": (
618             options: [ "Expr" ],
619             collections: [
620                 ["statements", "Stmt"],
621             ],
622             traits: [
623                 "AttrsOwner",
624             ]
625         ),
626         "ParamList": (
627             options: [ "SelfParam" ],
628             collections: [
629                 ["params", "Param"]
630             ]
631         ),
632         "SelfParam": (
633             options: ["SelfKw"],
634             traits: [
635                 "TypeAscriptionOwner",
636             ]
637         ),
638         "SelfKw": (),
639         "Param": (
640             options: [ "Pat" ],
641             traits: [
642                 "TypeAscriptionOwner",
643             ]
644         ),
645         "UseItem": (
646             traits: ["AttrsOwner"],
647             options: [ "UseTree" ],
648         ),
649         "UseTree": (
650             options: [ "Path", "UseTreeList", "Alias" ]
651         ),
652         "Alias": (
653             traits: ["NameOwner"],
654         ),
655         "UseTreeList": (
656             collections: [["use_trees", "UseTree"]]
657         ),
658         "ExternCrateItem": (
659             options: ["NameRef", "Alias"],
660         ),
661         "ArgList": (
662             collections: [
663                 ["args", "Expr"]
664             ]
665         ),
666         "Path": (
667             options: [
668                 ["segment", "PathSegment"],
669                 ["qualifier", "Path"],
670             ]
671         ),
672         "PathSegment": (
673             options: [ "NameRef", "TypeArgList" ]
674         ),
675         "TypeArgList": (collections: [
676             ["type_args", "TypeArg"],
677             ["lifetime_args", "LifetimeArg"],
678             ["assoc_type_args", "AssocTypeArg"],
679         ]),
680         "TypeArg": (options: ["TypeRef"]),
681         "AssocTypeArg": (options: ["NameRef", "TypeRef"]),
682         "LifetimeArg": (options: ["Lifetime"]),
683         "Comment": ( traits: ["AstToken"] ),
684         "Whitespace": ( traits: ["AstToken"] ),
685     },
686 )