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