]> git.lizzy.rs Git - rust.git/blob - crates/ra_syntax/src/grammar.ron
Merge #989
[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     ],
247     ast: {
248         "SourceFile": (
249             traits: [ "ModuleItemOwner", "FnDefOwner" ],
250             collections: [
251                 ["modules", "Module"],
252             ]
253         ),
254         "FnDef": (
255             traits: [
256                 "VisibilityOwner",
257                 "NameOwner",
258                 "TypeParamsOwner",
259                 "AttrsOwner",
260                 "DocCommentsOwner"
261             ],
262             options: [ "ParamList", ["body", "Block"], "RetType" ],
263         ),
264         "RetType": (options: ["TypeRef"]),
265         "StructDef": (
266             traits: [
267                 "VisibilityOwner",
268                 "NameOwner",
269                 "TypeParamsOwner",
270                 "AttrsOwner",
271                 "DocCommentsOwner"
272             ]
273         ),
274         "NamedFieldDefList": (collections: [["fields", "NamedFieldDef"]]),
275         "NamedFieldDef": (
276             traits: [
277                 "VisibilityOwner",
278                 "NameOwner",
279                 "AttrsOwner",
280                 "DocCommentsOwner",
281                 "TypeAscriptionOwner"
282             ]
283         ),
284         "PosFieldDefList": (collections: [["fields", "PosFieldDef"]]),
285         "PosFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]),
286         "EnumDef": ( traits: [
287             "VisibilityOwner",
288             "NameOwner",
289             "TypeParamsOwner",
290             "AttrsOwner",
291             "DocCommentsOwner"
292         ], options: [["variant_list", "EnumVariantList"]] ),
293         "EnumVariantList": ( collections: [["variants", "EnumVariant"]] ),
294         "EnumVariant": ( traits: ["NameOwner", "DocCommentsOwner", "AttrsOwner"], options: ["Expr"] ),
295         "TraitDef": ( traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeParamsOwner"] ),
296         "Module": (
297             traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner" ],
298             options: [ "ItemList" ]
299         ),
300         "ItemList": (
301             collections: [["impl_items", "ImplItem"]],
302             traits: [ "FnDefOwner", "ModuleItemOwner" ],
303         ),
304         "ConstDef": (
305             traits: [
306                 "VisibilityOwner",
307                 "NameOwner",
308                 "TypeParamsOwner",
309                 "AttrsOwner",
310                 "DocCommentsOwner",
311                 "TypeAscriptionOwner",
312             ],
313         ),
314         "StaticDef": (
315             traits: [
316                 "VisibilityOwner",
317                 "NameOwner",
318                 "TypeParamsOwner",
319                 "AttrsOwner",
320                 "DocCommentsOwner",
321                 "TypeAscriptionOwner",
322             ],
323         ),
324         "TypeAliasDef": (
325             traits: [
326                 "VisibilityOwner",
327                 "NameOwner",
328                 "TypeParamsOwner",
329                 "AttrsOwner",
330                 "DocCommentsOwner"
331             ],
332             options: ["TypeRef"]
333         ),
334         "ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner"]),
335
336         "ParenType": (options: ["TypeRef"]),
337         "TupleType": ( collections: [["fields", "TypeRef"]] ),
338         "NeverType": (),
339         "PathType": (options: ["Path"]),
340         "PointerType": (options: ["TypeRef"]),
341         "ArrayType": ( options: ["TypeRef", "Expr"] ),
342         "SliceType": ( options: ["TypeRef"] ),
343         "ReferenceType": (options: ["TypeRef"]),
344         "PlaceholderType": (),
345         "FnPointerType": (options: ["ParamList", "RetType"]),
346         "ForType": (options: ["TypeRef"]),
347         "ImplTraitType": (),
348         "DynTraitType": (),
349
350         "TypeRef": ( enum: [
351             "ParenType",
352             "TupleType",
353             "NeverType",
354             "PathType",
355             "PointerType",
356             "ArrayType",
357             "SliceType",
358             "ReferenceType",
359             "PlaceholderType",
360             "FnPointerType",
361             "ForType",
362             "ImplTraitType",
363             "DynTraitType",
364         ]),
365
366         "NominalDef": (
367             enum: ["StructDef", "EnumDef"],
368             traits: [
369                 "NameOwner",
370                 "TypeParamsOwner",
371                 "AttrsOwner"
372             ],
373         ),
374         "ModuleItem": (
375             enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "TypeAliasDef", "ImplBlock",
376                    "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ]
377         ),
378         "ImplItem": (
379             enum: ["FnDef", "TypeAliasDef", "ConstDef"]
380         ),
381
382         "TupleExpr": (
383             collections: [["exprs", "Expr"]]
384         ),
385         "ArrayExpr": (
386             collections: [["exprs", "Expr"]]
387         ),
388         "ParenExpr": (options: ["Expr"]),
389         "PathExpr": (options: ["Path"]),
390         "LambdaExpr": (
391             options: [
392                 "ParamList",
393                 ["body", "Expr"],
394             ]
395         ),
396         "IfExpr": (
397             options: [ "Condition" ]
398         ),
399         "LoopExpr": (
400             traits: ["LoopBodyOwner"],
401         ),
402         "ForExpr": (
403             traits: ["LoopBodyOwner"],
404             options: [
405                 "Pat",
406                 ["iterable", "Expr"],
407             ]
408         ),
409         "WhileExpr": (
410             traits: ["LoopBodyOwner"],
411             options: [ "Condition" ]
412         ),
413         "ContinueExpr": (),
414         "BreakExpr": (options: ["Expr"]),
415         "Label": (),
416         "BlockExpr": (
417             options: [ "Block" ]
418         ),
419         "ReturnExpr": (options: ["Expr"]),
420         "MatchExpr": (
421             options: [ "Expr", "MatchArmList" ],
422         ),
423         "MatchArmList": (
424             collections: [ ["arms", "MatchArm"] ],
425             traits: [ "AttrsOwner" ]
426         ),
427         "MatchArm": (
428             options: [
429                 [ "guard", "MatchGuard" ],
430                 "Expr",
431             ],
432             collections: [ [ "pats", "Pat" ] ],
433             traits: [ "AttrsOwner" ]
434         ),
435         "MatchGuard": (options: ["Expr"]),
436         "StructLit": (options: ["Path", "NamedFieldList", ["spread", "Expr"]]),
437         "NamedFieldList": (collections: [ ["fields", "NamedField"] ]),
438         "NamedField": (options: ["NameRef", "Expr"]),
439         "CallExpr": (
440             traits: ["ArgListOwner"],
441             options: [ "Expr" ],
442         ),
443         "MethodCallExpr": (
444             traits: ["ArgListOwner"],
445             options: [ "Expr", "NameRef", "TypeArgList" ],
446         ),
447         "IndexExpr": (),
448         "FieldExpr": (options: ["Expr", "NameRef"]),
449         "TryExpr": (options: ["Expr"]),
450         "CastExpr": (options: ["Expr", "TypeRef"]),
451         "RefExpr": (options: ["Expr"]),
452         "PrefixExpr": (options: ["Expr"]),
453         "RangeExpr": (),
454         "BinExpr": (),
455
456         "IntNumber": ( traits: ["AstToken"] ),
457         "FloatNumber": ( traits: ["AstToken"] ),
458         "String": ( traits: ["AstToken"] ),
459         "RawString": ( traits: ["AstToken"] ),
460         "Byte": ( traits: ["AstToken"] ),
461         "RawByteString": ( traits: ["AstToken"] ),
462         "ByteString": ( traits: ["AstToken"] ),
463         "Char": ( traits: ["AstToken"] ),
464         "TrueKw": ( traits: ["AstToken"] ),
465         "FalseKw": ( traits: ["AstToken"] ),
466         "LiteralExpr": (
467             enum: [
468                 "String",
469                 "ByteString",
470                 "RawString",
471                 "RawByteString",
472                 "Char",
473                 "Byte",
474                 "IntNumber",
475                 "FloatNumber",
476                 "TrueKw",
477                 "FalseKw",
478             ]
479         ),
480         "Literal": (options: ["LiteralExpr"]),
481
482         "Expr": (
483             enum: [
484                 "TupleExpr",
485                 "ArrayExpr",
486                 "ParenExpr",
487                 "PathExpr",
488                 "LambdaExpr",
489                 "IfExpr",
490                 "LoopExpr",
491                 "ForExpr",
492                 "WhileExpr",
493                 "ContinueExpr",
494                 "BreakExpr",
495                 "Label",
496                 "BlockExpr",
497                 "ReturnExpr",
498                 "MatchExpr",
499                 "StructLit",
500                 "CallExpr",
501                 "IndexExpr",
502                 "MethodCallExpr",
503                 "FieldExpr",
504                 "TryExpr",
505                 "CastExpr",
506                 "RefExpr",
507                 "PrefixExpr",
508                 "RangeExpr",
509                 "BinExpr",
510                 "Literal",
511             ],
512         ),
513
514         "RefPat": ( options: [ "Pat" ]),
515         "BindPat": (
516             options: [ "Pat" ],
517             traits: ["NameOwner"]
518         ),
519         "PlaceholderPat": (),
520         "PathPat": ( options: [ "Path" ] ),
521         "StructPat": ( options: ["FieldPatList", "Path"] ),
522         "FieldPatList": (
523             collections: [
524                 ["field_pats", "FieldPat"],
525                 ["bind_pats", "BindPat"],
526             ]
527         ),
528         "FieldPat": (
529             traits: ["NameOwner"],
530             options: ["Pat"]
531         ),
532         "TupleStructPat": (
533             options: ["Path"],
534             collections: [["args", "Pat"]],
535         ),
536         "TuplePat": ( collections: [["args", "Pat"]] ),
537         "SlicePat": (),
538         "RangePat": (),
539         "LiteralPat": (options: ["Literal"]),
540
541         "Pat": (
542             enum: [
543                 "RefPat",
544                 "BindPat",
545                 "PlaceholderPat",
546                 "PathPat",
547                 "StructPat",
548                 "TupleStructPat",
549                 "TuplePat",
550                 "SlicePat",
551                 "RangePat",
552                 "LiteralPat",
553             ],
554         ),
555
556         "Visibility": (),
557         "Name": (),
558         "NameRef": (),
559         "MacroCall": (
560             traits: [ "NameOwner", "AttrsOwner" ],
561             options: [ "TokenTree", "Path" ],
562         ),
563         "Attr": ( options: [ ["value", "TokenTree"] ] ),
564         "TokenTree": (),
565         "TypeParamList": (
566             collections: [
567                 ["type_params", "TypeParam" ],
568                 ["lifetime_params", "LifetimeParam" ],
569             ]
570         ),
571         "TypeParam": ( traits: ["NameOwner", "AttrsOwner"] ),
572         "LifetimeParam": (
573             options: [ "Lifetime"],
574             traits: ["AttrsOwner"],
575         ),
576         "Lifetime": ( traits: ["AstToken"] ),
577         "WhereClause": (),
578         "ExprStmt": (
579             options: [ ["expr", "Expr"] ]
580         ),
581         "LetStmt": (
582             options: [
583                 ["pat", "Pat"],
584                 ["initializer", "Expr"],
585             ],
586             traits: [
587                 "TypeAscriptionOwner",
588             ]
589         ),
590         "Condition": (
591             options: [ "Pat", "Expr" ]
592         ),
593         "Stmt": (
594             enum: ["ExprStmt", "LetStmt"],
595         ),
596         "Block": (
597             options: [ "Expr" ],
598             collections: [
599                 ["statements", "Stmt"],
600             ],
601             traits: [
602                 "AttrsOwner",
603             ]
604         ),
605         "ParamList": (
606             options: [ "SelfParam" ],
607             collections: [
608                 ["params", "Param"]
609             ]
610         ),
611         "SelfParam": (
612             options: ["SelfKw"],
613             traits: [
614                 "TypeAscriptionOwner",
615             ]
616         ),
617         "SelfKw": (),
618         "Param": (
619             options: [ "Pat" ],
620             traits: [
621                 "TypeAscriptionOwner",
622             ]
623         ),
624         "UseItem": (
625             traits: ["AttrsOwner"],
626             options: [ "UseTree" ],
627         ),
628         "UseTree": (
629             options: [ "Path", "UseTreeList", "Alias" ]
630         ),
631         "Alias": (
632             traits: ["NameOwner"],
633         ),
634         "UseTreeList": (
635             collections: [["use_trees", "UseTree"]]
636         ),
637         "ExternCrateItem": (
638             options: ["NameRef", "Alias"],
639         ),
640         "ArgList": (
641             collections: [
642                 ["args", "Expr"]
643             ]
644         ),
645         "Path": (
646             options: [
647                 ["segment", "PathSegment"],
648                 ["qualifier", "Path"],
649             ]
650         ),
651         "PathSegment": (
652             options: [ "NameRef", "TypeArgList" ]
653         ),
654         "TypeArgList": (collections: [
655             ["type_args", "TypeArg"],
656             ["lifetime_args", "LifetimeArg"],
657             ["assoc_type_args", "AssocTypeArg"],
658         ]),
659         "TypeArg": (options: ["TypeRef"]),
660         "AssocTypeArg": (options: ["NameRef", "TypeRef"]),
661         "LifetimeArg": (options: ["Lifetime"]),
662         "Comment": ( traits: ["AstToken"] ),
663         "Whitespace": ( traits: ["AstToken"] ),
664     },
665 )