]> git.lizzy.rs Git - rust.git/blob - crates/ra_syntax/src/grammar.ron
Merge #1163
[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         "L_DOLLAR",
122         "R_DOLLAR",
123     ],
124     nodes: [
125         "SOURCE_FILE",
126
127         "STRUCT_DEF",
128         "ENUM_DEF",
129         "FN_DEF",
130         "RET_TYPE",
131         "EXTERN_CRATE_ITEM",
132         "MODULE",
133         "USE_ITEM",
134         "STATIC_DEF",
135         "CONST_DEF",
136         "TRAIT_DEF",
137         "IMPL_BLOCK",
138         "TYPE_ALIAS_DEF",
139         "MACRO_CALL",
140         "TOKEN_TREE",
141
142         "PAREN_TYPE",
143         "TUPLE_TYPE",
144         "NEVER_TYPE",
145         "PATH_TYPE",
146         "POINTER_TYPE",
147         "ARRAY_TYPE",
148         "SLICE_TYPE",
149         "REFERENCE_TYPE",
150         "PLACEHOLDER_TYPE",
151         "FN_POINTER_TYPE",
152         "FOR_TYPE",
153         "IMPL_TRAIT_TYPE",
154         "DYN_TRAIT_TYPE",
155
156         "REF_PAT",
157         "BIND_PAT",
158         "PLACEHOLDER_PAT",
159         "PATH_PAT",
160         "STRUCT_PAT",
161         "FIELD_PAT_LIST",
162         "FIELD_PAT",
163         "TUPLE_STRUCT_PAT",
164         "TUPLE_PAT",
165         "SLICE_PAT",
166         "RANGE_PAT",
167         "LITERAL_PAT",
168
169         // atoms
170         "TUPLE_EXPR",
171         "ARRAY_EXPR",
172         "PAREN_EXPR",
173         "PATH_EXPR",
174         "LAMBDA_EXPR",
175         "IF_EXPR",
176         "WHILE_EXPR",
177         "CONDITION",
178         "LOOP_EXPR",
179         "FOR_EXPR",
180         "CONTINUE_EXPR",
181         "BREAK_EXPR",
182         "LABEL",
183         "BLOCK_EXPR",
184         "RETURN_EXPR",
185         "MATCH_EXPR",
186         "MATCH_ARM_LIST",
187         "MATCH_ARM",
188         "MATCH_GUARD",
189         "STRUCT_LIT",
190         "NAMED_FIELD_LIST",
191         "NAMED_FIELD",
192
193         // postfix
194         "CALL_EXPR",
195         "INDEX_EXPR",
196         "METHOD_CALL_EXPR",
197         "FIELD_EXPR",
198         "TRY_EXPR",
199         "CAST_EXPR",
200
201         // unary
202         "REF_EXPR",
203         "PREFIX_EXPR",
204
205         "RANGE_EXPR", // just weird
206         "BIN_EXPR",
207
208         "BLOCK",
209         "EXTERN_BLOCK",
210         "EXTERN_ITEM_LIST",
211         "ENUM_VARIANT",
212         "NAMED_FIELD_DEF_LIST",
213         "NAMED_FIELD_DEF",
214         "POS_FIELD_DEF_LIST",
215         "POS_FIELD_DEF",
216         "ENUM_VARIANT_LIST",
217         "ITEM_LIST",
218         "ATTR",
219         "META_ITEM", // not an item actually
220         "USE_TREE",
221         "USE_TREE_LIST",
222         "PATH",
223         "PATH_SEGMENT",
224         "LITERAL",
225         "ALIAS",
226         "VISIBILITY",
227         "WHERE_CLAUSE",
228         "WHERE_PRED",
229         "ABI",
230         "NAME",
231         "NAME_REF",
232
233         "LET_STMT",
234         "EXPR_STMT",
235
236         "TYPE_PARAM_LIST",
237         "LIFETIME_PARAM",
238         "TYPE_PARAM",
239         "TYPE_ARG_LIST",
240         "LIFETIME_ARG",
241         "TYPE_ARG",
242         "ASSOC_TYPE_ARG",
243
244         "PARAM_LIST",
245         "PARAM",
246         "SELF_PARAM",
247         "ARG_LIST",
248         "TYPE_BOUND",
249         "TYPE_BOUND_LIST",
250
251         // macro related
252         "MACRO_ITEMS",
253         "MACRO_STMTS",
254     ],
255     ast: {
256         "SourceFile": (
257             traits: [ "ModuleItemOwner", "FnDefOwner" ],
258             collections: [
259                 ["modules", "Module"],
260             ]
261         ),
262         "FnDef": (
263             traits: [
264                 "VisibilityOwner",
265                 "NameOwner",
266                 "TypeParamsOwner",
267                 "AttrsOwner",
268                 "DocCommentsOwner"
269             ],
270             options: [ "ParamList", ["body", "Block"], "RetType" ],
271         ),
272         "RetType": (options: ["TypeRef"]),
273         "StructDef": (
274             traits: [
275                 "VisibilityOwner",
276                 "NameOwner",
277                 "TypeParamsOwner",
278                 "AttrsOwner",
279                 "DocCommentsOwner"
280             ]
281         ),
282         "NamedFieldDefList": (collections: [["fields", "NamedFieldDef"]]),
283         "NamedFieldDef": (
284             traits: [
285                 "VisibilityOwner",
286                 "NameOwner",
287                 "AttrsOwner",
288                 "DocCommentsOwner",
289                 "TypeAscriptionOwner"
290             ]
291         ),
292         "PosFieldDefList": (collections: [["fields", "PosFieldDef"]]),
293         "PosFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]),
294         "EnumDef": ( traits: [
295             "VisibilityOwner",
296             "NameOwner",
297             "TypeParamsOwner",
298             "AttrsOwner",
299             "DocCommentsOwner"
300         ], options: [["variant_list", "EnumVariantList"]] ),
301         "EnumVariantList": ( collections: [["variants", "EnumVariant"]] ),
302         "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner", "AttrsOwner"], options: ["Expr"] ),
303         "TraitDef": (
304             traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeParamsOwner", "TypeBoundsOwner"],
305             options: ["ItemList"]
306         ),
307         "Module": (
308             traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner" ],
309             options: [ "ItemList" ]
310         ),
311         "ItemList": (
312             collections: [["impl_items", "ImplItem"]],
313             traits: [ "FnDefOwner", "ModuleItemOwner" ],
314         ),
315         "ConstDef": (
316             traits: [
317                 "VisibilityOwner",
318                 "NameOwner",
319                 "TypeParamsOwner",
320                 "AttrsOwner",
321                 "DocCommentsOwner",
322                 "TypeAscriptionOwner",
323             ],
324             options: [ ["body","Expr"]],
325         ),
326         "StaticDef": (
327             traits: [
328                 "VisibilityOwner",
329                 "NameOwner",
330                 "TypeParamsOwner",
331                 "AttrsOwner",
332                 "DocCommentsOwner",
333                 "TypeAscriptionOwner",
334             ],
335             options: [ ["body","Expr"]],
336         ),
337         "TypeAliasDef": (
338             traits: [
339                 "VisibilityOwner",
340                 "NameOwner",
341                 "TypeParamsOwner",
342                 "AttrsOwner",
343                 "DocCommentsOwner",
344                 "TypeBoundsOwner",
345             ],
346             options: ["TypeRef"]
347         ),
348         "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner", "AttrsOwner"]),
349
350         "ParenType": (options: ["TypeRef"]),
351         "TupleType": ( collections: [["fields", "TypeRef"]] ),
352         "NeverType": (),
353         "PathType": (options: ["Path"]),
354         "PointerType": (options: ["TypeRef"]),
355         "ArrayType": ( options: ["TypeRef", "Expr"] ),
356         "SliceType": ( options: ["TypeRef"] ),
357         "ReferenceType": (options: ["TypeRef"]),
358         "PlaceholderType": (),
359         "FnPointerType": (options: ["ParamList", "RetType"]),
360         "ForType": (options: ["TypeRef"]),
361         "ImplTraitType": (
362             traits: ["TypeBoundsOwner"],
363         ),
364         "DynTraitType": (
365             traits: ["TypeBoundsOwner"],
366         ),
367
368         "TypeRef": ( enum: [
369             "ParenType",
370             "TupleType",
371             "NeverType",
372             "PathType",
373             "PointerType",
374             "ArrayType",
375             "SliceType",
376             "ReferenceType",
377             "PlaceholderType",
378             "FnPointerType",
379             "ForType",
380             "ImplTraitType",
381             "DynTraitType",
382         ]),
383
384         "NominalDef": (
385             enum: ["StructDef", "EnumDef"],
386             traits: [
387                 "NameOwner",
388                 "TypeParamsOwner",
389                 "AttrsOwner"
390             ],
391         ),
392         "ModuleItem": (
393             enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "TypeAliasDef", "ImplBlock",
394                    "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ]
395         ),
396         "ImplItem": (
397             enum: ["FnDef", "TypeAliasDef", "ConstDef"]
398         ),
399
400         "TupleExpr": (
401             collections: [["exprs", "Expr"]]
402         ),
403         "ArrayExpr": (
404             collections: [["exprs", "Expr"]]
405         ),
406         "ParenExpr": (options: ["Expr"]),
407         "PathExpr": (options: ["Path"]),
408         "LambdaExpr": (
409             options: [
410                 "ParamList",
411                 ["body", "Expr"],
412             ]
413         ),
414         "IfExpr": (
415             options: [ "Condition" ]
416         ),
417         "LoopExpr": (
418             traits: ["LoopBodyOwner"],
419         ),
420         "ForExpr": (
421             traits: ["LoopBodyOwner"],
422             options: [
423                 "Pat",
424                 ["iterable", "Expr"],
425             ]
426         ),
427         "WhileExpr": (
428             traits: ["LoopBodyOwner"],
429             options: [ "Condition" ]
430         ),
431         "ContinueExpr": (),
432         "BreakExpr": (options: ["Expr"]),
433         "Label": (),
434         "BlockExpr": (
435             options: [ "Block" ]
436         ),
437         "ReturnExpr": (options: ["Expr"]),
438         "MatchExpr": (
439             options: [ "Expr", "MatchArmList" ],
440         ),
441         "MatchArmList": (
442             collections: [ ["arms", "MatchArm"] ],
443             traits: [ "AttrsOwner" ]
444         ),
445         "MatchArm": (
446             options: [
447                 [ "guard", "MatchGuard" ],
448                 "Expr",
449             ],
450             collections: [ [ "pats", "Pat" ] ],
451             traits: [ "AttrsOwner" ]
452         ),
453         "MatchGuard": (options: ["Expr"]),
454         "StructLit": (options: ["Path", "NamedFieldList"]),
455         "NamedFieldList": (
456             collections: [ ["fields", "NamedField"] ],
457             options: [["spread", "Expr"]]
458         ),
459         "NamedField": (options: ["NameRef", "Expr"]),
460         "CallExpr": (
461             traits: ["ArgListOwner"],
462             options: [ "Expr" ],
463         ),
464         "MethodCallExpr": (
465             traits: ["ArgListOwner"],
466             options: [ "Expr", "NameRef", "TypeArgList" ],
467         ),
468         "IndexExpr": (),
469         "FieldExpr": (options: ["Expr", "NameRef"]),
470         "TryExpr": (options: ["Expr"]),
471         "CastExpr": (options: ["Expr", "TypeRef"]),
472         "RefExpr": (options: ["Expr"]),
473         "PrefixExpr": (options: ["Expr"]),
474         "RangeExpr": (),
475         "BinExpr": (),
476
477         "Literal": (),
478
479         "Expr": (
480             enum: [
481                 "TupleExpr",
482                 "ArrayExpr",
483                 "ParenExpr",
484                 "PathExpr",
485                 "LambdaExpr",
486                 "IfExpr",
487                 "LoopExpr",
488                 "ForExpr",
489                 "WhileExpr",
490                 "ContinueExpr",
491                 "BreakExpr",
492                 "Label",
493                 "BlockExpr",
494                 "ReturnExpr",
495                 "MatchExpr",
496                 "StructLit",
497                 "CallExpr",
498                 "IndexExpr",
499                 "MethodCallExpr",
500                 "FieldExpr",
501                 "TryExpr",
502                 "CastExpr",
503                 "RefExpr",
504                 "PrefixExpr",
505                 "RangeExpr",
506                 "BinExpr",
507                 "Literal",
508                 "MacroCall",
509             ],
510         ),
511
512         "RefPat": ( options: [ "Pat" ]),
513         "BindPat": (
514             options: [ "Pat" ],
515             traits: ["NameOwner"]
516         ),
517         "PlaceholderPat": (),
518         "PathPat": ( options: [ "Path" ] ),
519         "StructPat": ( options: ["FieldPatList", "Path"] ),
520         "FieldPatList": (
521             collections: [
522                 ["field_pats", "FieldPat"],
523                 ["bind_pats", "BindPat"],
524             ]
525         ),
526         "FieldPat": (
527             traits: ["NameOwner"],
528             options: ["Pat"]
529         ),
530         "TupleStructPat": (
531             options: ["Path"],
532             collections: [["args", "Pat"]],
533         ),
534         "TuplePat": ( collections: [["args", "Pat"]] ),
535         "SlicePat": (),
536         "RangePat": (),
537         "LiteralPat": (options: ["Literal"]),
538
539         "Pat": (
540             enum: [
541                 "RefPat",
542                 "BindPat",
543                 "PlaceholderPat",
544                 "PathPat",
545                 "StructPat",
546                 "TupleStructPat",
547                 "TuplePat",
548                 "SlicePat",
549                 "RangePat",
550                 "LiteralPat",
551             ],
552         ),
553
554         "Visibility": (),
555         "Name": (),
556         "NameRef": (),
557         "MacroCall": (
558             traits: [ "NameOwner", "AttrsOwner","DocCommentsOwner" ],
559             options: [ "TokenTree", "Path" ],
560         ),
561         "Attr": ( options: [ ["value", "TokenTree"] ] ),
562         "TokenTree": (),
563         "TypeParamList": (
564             collections: [
565                 ["type_params", "TypeParam" ],
566                 ["lifetime_params", "LifetimeParam" ],
567             ]
568         ),
569         "TypeParam": ( traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner", "DefaultTypeParamOwner"] ),
570         "LifetimeParam": (
571             traits: ["AttrsOwner"],
572         ),
573         "TypeBound": (
574             options: [
575                 "TypeRef",
576             ]
577         ),
578         "TypeBoundList": (
579             collections: [
580                 ["bounds", "TypeBound"],
581             ]
582         ),
583         "WherePred": (
584             options: [
585                 "TypeRef",
586             ],
587             traits: [
588                 "TypeBoundsOwner",
589             ],
590         ),
591         "WhereClause": (
592             collections: [
593                 ["predicates", "WherePred"],
594             ],
595         ),
596         "ExprStmt": (
597             options: [ ["expr", "Expr"] ]
598         ),
599         "LetStmt": (
600             options: [
601                 ["pat", "Pat"],
602                 ["initializer", "Expr"],
603             ],
604             traits: [
605                 "TypeAscriptionOwner",
606             ]
607         ),
608         "Condition": (
609             options: [ "Pat", "Expr" ]
610         ),
611         "Stmt": (
612             enum: ["ExprStmt", "LetStmt"],
613         ),
614         "Block": (
615             options: [ "Expr" ],
616             collections: [
617                 ["statements", "Stmt"],
618             ],
619             traits: [
620                 "AttrsOwner",
621             ]
622         ),
623         "ParamList": (
624             options: [ "SelfParam" ],
625             collections: [
626                 ["params", "Param"]
627             ]
628         ),
629         "SelfParam": (
630             traits: [
631                 "TypeAscriptionOwner",
632             ]
633         ),
634         "Param": (
635             options: [ "Pat" ],
636             traits: [
637                 "TypeAscriptionOwner",
638             ]
639         ),
640         "UseItem": (
641             traits: ["AttrsOwner"],
642             options: [ "UseTree" ],
643         ),
644         "UseTree": (
645             options: [ "Path", "UseTreeList", "Alias" ]
646         ),
647         "Alias": (
648             traits: ["NameOwner"],
649         ),
650         "UseTreeList": (
651             collections: [["use_trees", "UseTree"]]
652         ),
653         "ExternCrateItem": (
654             options: ["NameRef", "Alias"],
655         ),
656         "ArgList": (
657             collections: [
658                 ["args", "Expr"]
659             ]
660         ),
661         "Path": (
662             options: [
663                 ["segment", "PathSegment"],
664                 ["qualifier", "Path"],
665             ]
666         ),
667         "PathSegment": (
668             options: [ "NameRef", "TypeArgList" ]
669         ),
670         "TypeArgList": (collections: [
671             ["type_args", "TypeArg"],
672             ["lifetime_args", "LifetimeArg"],
673             ["assoc_type_args", "AssocTypeArg"],
674         ]),
675         "TypeArg": (options: ["TypeRef"]),
676         "AssocTypeArg": (options: ["NameRef", "TypeRef"]),
677         "LifetimeArg": (),
678
679         "MacroItems": (
680             traits: [ "ModuleItemOwner", "FnDefOwner" ],            
681         ),
682
683         "MacroStmts" : (
684             options: [ "Expr" ],
685             collections: [
686                 ["statements", "Stmt"],
687             ],
688         )
689     },
690 )