]> git.lizzy.rs Git - rust.git/blob - crates/ra_syntax/src/grammar.ron
Allow non-path default type parameters
[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": (
591             options: [("default_type", "TypeRef")],
592             traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner"],
593         ),
594         "LifetimeParam": (
595             traits: ["AttrsOwner"],
596         ),
597         "TypeBound": (
598             options: [
599                 "TypeRef",
600             ]
601         ),
602         "TypeBoundList": (
603             collections: [
604                 ("bounds", "TypeBound"),
605             ]
606         ),
607         "WherePred": (
608             options: [
609                 "TypeRef",
610             ],
611             traits: [
612                 "TypeBoundsOwner",
613             ],
614         ),
615         "WhereClause": (
616             collections: [
617                 ("predicates", "WherePred"),
618             ],
619         ),
620         "ExprStmt": (
621             options: [ ["expr", "Expr"] ]
622         ),
623         "LetStmt": (
624             options: [
625                 ["pat", "Pat"],
626                 ["initializer", "Expr"],
627             ],
628             traits: [
629                 "TypeAscriptionOwner",
630             ]
631         ),
632         "Condition": (
633             options: [ "Pat", "Expr" ]
634         ),
635         "Stmt": (
636             enum: ["ExprStmt", "LetStmt"],
637         ),
638         "Block": (
639             options: [ "Expr" ],
640             collections: [
641                 ("statements", "Stmt"),
642             ],
643             traits: [
644                 "AttrsOwner",
645             ]
646         ),
647         "ParamList": (
648             options: [ "SelfParam" ],
649             collections: [
650                 ("params", "Param"),
651             ]
652         ),
653         "SelfParam": (
654             traits: [
655                 "TypeAscriptionOwner",
656                                 "AttrsOwner",
657             ]
658         ),
659         "Param": (
660             options: [ "Pat" ],
661             traits: [
662                 "TypeAscriptionOwner",
663                                 "AttrsOwner",
664             ]
665         ),
666         "UseItem": (
667             traits: ["AttrsOwner"],
668             options: [ "UseTree" ],
669         ),
670         "UseTree": (
671             options: [ "Path", "UseTreeList", "Alias" ]
672         ),
673         "Alias": (
674             traits: ["NameOwner"],
675         ),
676         "UseTreeList": (
677             collections: [("use_trees", "UseTree")]
678         ),
679         "ExternCrateItem": (
680             traits: ["AttrsOwner"],
681             options: ["NameRef", "Alias"],
682         ),
683         "ArgList": (
684             collections: [
685                 ("args", "Expr"),
686             ]
687         ),
688         "Path": (
689             options: [
690                 ["segment", "PathSegment"],
691                 ["qualifier", "Path"],
692             ]
693         ),
694         "PathSegment": (
695             options: [ "NameRef", "TypeArgList", "ParamList", "RetType", "PathType" ]
696         ),
697         "TypeArgList": (collections: [
698             ("type_args", "TypeArg"),
699             ("lifetime_args", "LifetimeArg"),
700             ("assoc_type_args", "AssocTypeArg"),
701         ]),
702         "TypeArg": (options: ["TypeRef"]),
703         "AssocTypeArg": (options: ["NameRef", "TypeRef"]),
704         "LifetimeArg": (),
705
706         "MacroItems": (
707             traits: [ "ModuleItemOwner", "FnDefOwner" ],
708         ),
709
710         "MacroStmts" : (
711             options: [ "Expr" ],
712             collections: [
713                 ("statements", "Stmt"),
714             ],
715         )
716     },
717 )