]> git.lizzy.rs Git - rust.git/blob - src/grammar/parser-lalr.y
Auto merge of #41433 - estebank:constructor, r=michaelwoerister
[rust.git] / src / grammar / parser-lalr.y
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 %{
12 #define YYERROR_VERBOSE
13 #define YYSTYPE struct node *
14 struct node;
15 extern int yylex();
16 extern void yyerror(char const *s);
17 extern struct node *mk_node(char const *name, int n, ...);
18 extern struct node *mk_atom(char *text);
19 extern struct node *mk_none();
20 extern struct node *ext_node(struct node *nd, int n, ...);
21 extern void push_back(char c);
22 extern char *yytext;
23 %}
24 %debug
25
26 %token SHL
27 %token SHR
28 %token LE
29 %token EQEQ
30 %token NE
31 %token GE
32 %token ANDAND
33 %token OROR
34 %token SHLEQ
35 %token SHREQ
36 %token MINUSEQ
37 %token ANDEQ
38 %token OREQ
39 %token PLUSEQ
40 %token STAREQ
41 %token SLASHEQ
42 %token CARETEQ
43 %token PERCENTEQ
44 %token DOTDOT
45 %token DOTDOTDOT
46 %token MOD_SEP
47 %token RARROW
48 %token LARROW
49 %token FAT_ARROW
50 %token LIT_BYTE
51 %token LIT_CHAR
52 %token LIT_INTEGER
53 %token LIT_FLOAT
54 %token LIT_STR
55 %token LIT_STR_RAW
56 %token LIT_BYTE_STR
57 %token LIT_BYTE_STR_RAW
58 %token IDENT
59 %token UNDERSCORE
60 %token LIFETIME
61
62 // keywords
63 %token SELF
64 %token STATIC
65 %token AS
66 %token BREAK
67 %token CRATE
68 %token ELSE
69 %token ENUM
70 %token EXTERN
71 %token FALSE
72 %token FN
73 %token FOR
74 %token IF
75 %token IMPL
76 %token IN
77 %token LET
78 %token LOOP
79 %token MATCH
80 %token MOD
81 %token MOVE
82 %token MUT
83 %token PRIV
84 %token PUB
85 %token REF
86 %token RETURN
87 %token STRUCT
88 %token TRUE
89 %token TRAIT
90 %token TYPE
91 %token UNSAFE
92 %token DEFAULT
93 %token USE
94 %token WHILE
95 %token CONTINUE
96 %token PROC
97 %token BOX
98 %token CONST
99 %token WHERE
100 %token TYPEOF
101 %token INNER_DOC_COMMENT
102 %token OUTER_DOC_COMMENT
103
104 %token SHEBANG
105 %token SHEBANG_LINE
106 %token STATIC_LIFETIME
107
108  /*
109    Quoting from the Bison manual:
110
111    "Finally, the resolution of conflicts works by comparing the precedence
112    of the rule being considered with that of the lookahead token. If the
113    token's precedence is higher, the choice is to shift. If the rule's
114    precedence is higher, the choice is to reduce. If they have equal
115    precedence, the choice is made based on the associativity of that
116    precedence level. The verbose output file made by ā€˜-vā€™ (see Invoking
117    Bison) says how each conflict was resolved"
118  */
119
120 // We expect no shift/reduce or reduce/reduce conflicts in this grammar;
121 // all potential ambiguities are scrutinized and eliminated manually.
122 %expect 0
123
124 // fake-precedence symbol to cause '|' bars in lambda context to parse
125 // at low precedence, permit things like |x| foo = bar, where '=' is
126 // otherwise lower-precedence than '|'. Also used for proc() to cause
127 // things like proc() a + b to parse as proc() { a + b }.
128 %precedence LAMBDA
129
130 %precedence SELF
131
132 // MUT should be lower precedence than IDENT so that in the pat rule,
133 // "& MUT pat" has higher precedence than "binding_mode ident [@ pat]"
134 %precedence MUT
135
136 // IDENT needs to be lower than '{' so that 'foo {' is shifted when
137 // trying to decide if we've got a struct-construction expr (esp. in
138 // contexts like 'if foo { .')
139 //
140 // IDENT also needs to be lower precedence than '<' so that '<' in
141 // 'foo:bar . <' is shifted (in a trait reference occurring in a
142 // bounds list), parsing as foo:(bar<baz>) rather than (foo:bar)<baz>.
143 %precedence IDENT
144
145 // A couple fake-precedence symbols to use in rules associated with +
146 // and < in trailing type contexts. These come up when you have a type
147 // in the RHS of operator-AS, such as "foo as bar<baz>". The "<" there
148 // has to be shifted so the parser keeps trying to parse a type, even
149 // though it might well consider reducing the type "bar" and then
150 // going on to "<" as a subsequent binop. The "+" case is with
151 // trailing type-bounds ("foo as bar:A+B"), for the same reason.
152 %precedence SHIFTPLUS
153
154 %precedence MOD_SEP
155 %precedence RARROW ':'
156
157 // In where clauses, "for" should have greater precedence when used as
158 // a higher ranked constraint than when used as the beginning of a
159 // for_in_type (which is a ty)
160 %precedence FORTYPE
161 %precedence FOR
162
163 // Binops & unops, and their precedences
164 %precedence BOX
165 %precedence BOXPLACE
166 %nonassoc DOTDOT
167
168 // RETURN needs to be lower-precedence than tokens that start
169 // prefix_exprs
170 %precedence RETURN
171
172 %right '=' SHLEQ SHREQ MINUSEQ ANDEQ OREQ PLUSEQ STAREQ SLASHEQ CARETEQ PERCENTEQ
173 %right LARROW
174 %left OROR
175 %left ANDAND
176 %left EQEQ NE
177 %left '<' '>' LE GE
178 %left '|'
179 %left '^'
180 %left '&'
181 %left SHL SHR
182 %left '+' '-'
183 %precedence AS
184 %left '*' '/' '%'
185 %precedence '!'
186
187 %precedence '{' '[' '(' '.'
188
189 %precedence RANGE
190
191 %start crate
192
193 %%
194
195 ////////////////////////////////////////////////////////////////////////
196 // Part 1: Items and attributes
197 ////////////////////////////////////////////////////////////////////////
198
199 crate
200 : maybe_shebang inner_attrs maybe_mod_items  { mk_node("crate", 2, $2, $3); }
201 | maybe_shebang maybe_mod_items  { mk_node("crate", 1, $2); }
202 ;
203
204 maybe_shebang
205 : SHEBANG_LINE
206 | %empty
207 ;
208
209 maybe_inner_attrs
210 : inner_attrs
211 | %empty                   { $$ = mk_none(); }
212 ;
213
214 inner_attrs
215 : inner_attr               { $$ = mk_node("InnerAttrs", 1, $1); }
216 | inner_attrs inner_attr   { $$ = ext_node($1, 1, $2); }
217 ;
218
219 inner_attr
220 : SHEBANG '[' meta_item ']'   { $$ = mk_node("InnerAttr", 1, $3); }
221 | INNER_DOC_COMMENT           { $$ = mk_node("InnerAttr", 1, mk_node("doc-comment", 1, mk_atom(yytext))); }
222 ;
223
224 maybe_outer_attrs
225 : outer_attrs
226 | %empty                   { $$ = mk_none(); }
227 ;
228
229 outer_attrs
230 : outer_attr               { $$ = mk_node("OuterAttrs", 1, $1); }
231 | outer_attrs outer_attr   { $$ = ext_node($1, 1, $2); }
232 ;
233
234 outer_attr
235 : '#' '[' meta_item ']'    { $$ = $3; }
236 | OUTER_DOC_COMMENT        { $$ = mk_node("doc-comment", 1, mk_atom(yytext)); }
237 ;
238
239 meta_item
240 : ident                      { $$ = mk_node("MetaWord", 1, $1); }
241 | ident '=' lit              { $$ = mk_node("MetaNameValue", 2, $1, $3); }
242 | ident '(' meta_seq ')'     { $$ = mk_node("MetaList", 2, $1, $3); }
243 | ident '(' meta_seq ',' ')' { $$ = mk_node("MetaList", 2, $1, $3); }
244 ;
245
246 meta_seq
247 : %empty                   { $$ = mk_none(); }
248 | meta_item                { $$ = mk_node("MetaItems", 1, $1); }
249 | meta_seq ',' meta_item   { $$ = ext_node($1, 1, $3); }
250 ;
251
252 maybe_mod_items
253 : mod_items
254 | %empty             { $$ = mk_none(); }
255 ;
256
257 mod_items
258 : mod_item                               { $$ = mk_node("Items", 1, $1); }
259 | mod_items mod_item                     { $$ = ext_node($1, 1, $2); }
260 ;
261
262 attrs_and_vis
263 : maybe_outer_attrs visibility           { $$ = mk_node("AttrsAndVis", 2, $1, $2); }
264 ;
265
266 mod_item
267 : attrs_and_vis item    { $$ = mk_node("Item", 2, $1, $2); }
268 ;
269
270 // items that can appear outside of a fn block
271 item
272 : stmt_item
273 | item_macro
274 ;
275
276 // items that can appear in "stmts"
277 stmt_item
278 : item_static
279 | item_const
280 | item_type
281 | block_item
282 | view_item
283 ;
284
285 item_static
286 : STATIC ident ':' ty '=' expr ';'  { $$ = mk_node("ItemStatic", 3, $2, $4, $6); }
287 | STATIC MUT ident ':' ty '=' expr ';'  { $$ = mk_node("ItemStatic", 3, $3, $5, $7); }
288 ;
289
290 item_const
291 : CONST ident ':' ty '=' expr ';'  { $$ = mk_node("ItemConst", 3, $2, $4, $6); }
292 ;
293
294 item_macro
295 : path_expr '!' maybe_ident parens_delimited_token_trees ';'  { $$ = mk_node("ItemMacro", 3, $1, $3, $4); }
296 | path_expr '!' maybe_ident braces_delimited_token_trees      { $$ = mk_node("ItemMacro", 3, $1, $3, $4); }
297 | path_expr '!' maybe_ident brackets_delimited_token_trees ';'{ $$ = mk_node("ItemMacro", 3, $1, $3, $4); }
298 ;
299
300 view_item
301 : use_item
302 | extern_fn_item
303 | EXTERN CRATE ident ';'                      { $$ = mk_node("ViewItemExternCrate", 1, $3); }
304 | EXTERN CRATE ident AS ident ';'             { $$ = mk_node("ViewItemExternCrate", 2, $3, $5); }
305 ;
306
307 extern_fn_item
308 : EXTERN maybe_abi item_fn                    { $$ = mk_node("ViewItemExternFn", 2, $2, $3); }
309 ;
310
311 use_item
312 : USE view_path ';'                           { $$ = mk_node("ViewItemUse", 1, $2); }
313 ;
314
315 view_path
316 : path_no_types_allowed                                    { $$ = mk_node("ViewPathSimple", 1, $1); }
317 | path_no_types_allowed MOD_SEP '{'                '}'     { $$ = mk_node("ViewPathList", 2, $1, mk_atom("ViewPathListEmpty")); }
318 |                       MOD_SEP '{'                '}'     { $$ = mk_node("ViewPathList", 1, mk_atom("ViewPathListEmpty")); }
319 | path_no_types_allowed MOD_SEP '{' idents_or_self '}'     { $$ = mk_node("ViewPathList", 2, $1, $4); }
320 |                       MOD_SEP '{' idents_or_self '}'     { $$ = mk_node("ViewPathList", 1, $3); }
321 | path_no_types_allowed MOD_SEP '{' idents_or_self ',' '}' { $$ = mk_node("ViewPathList", 2, $1, $4); }
322 |                       MOD_SEP '{' idents_or_self ',' '}' { $$ = mk_node("ViewPathList", 1, $3); }
323 | path_no_types_allowed MOD_SEP '*'                        { $$ = mk_node("ViewPathGlob", 1, $1); }
324 |                               '{'                '}'     { $$ = mk_atom("ViewPathListEmpty"); }
325 |                               '{' idents_or_self '}'     { $$ = mk_node("ViewPathList", 1, $2); }
326 |                               '{' idents_or_self ',' '}' { $$ = mk_node("ViewPathList", 1, $2); }
327 | path_no_types_allowed AS ident                           { $$ = mk_node("ViewPathSimple", 2, $1, $3); }
328 ;
329
330 block_item
331 : item_fn
332 | item_unsafe_fn
333 | item_mod
334 | item_foreign_mod          { $$ = mk_node("ItemForeignMod", 1, $1); }
335 | item_struct
336 | item_enum
337 | item_trait
338 | item_impl
339 ;
340
341 maybe_ty_ascription
342 : ':' ty_sum { $$ = $2; }
343 | %empty { $$ = mk_none(); }
344 ;
345
346 maybe_init_expr
347 : '=' expr { $$ = $2; }
348 | %empty   { $$ = mk_none(); }
349 ;
350
351 // structs
352 item_struct
353 : STRUCT ident generic_params maybe_where_clause struct_decl_args
354 {
355   $$ = mk_node("ItemStruct", 4, $2, $3, $4, $5);
356 }
357 | STRUCT ident generic_params struct_tuple_args maybe_where_clause ';'
358 {
359   $$ = mk_node("ItemStruct", 4, $2, $3, $4, $5);
360 }
361 | STRUCT ident generic_params maybe_where_clause ';'
362 {
363   $$ = mk_node("ItemStruct", 3, $2, $3, $4);
364 }
365 ;
366
367 struct_decl_args
368 : '{' struct_decl_fields '}'                  { $$ = $2; }
369 | '{' struct_decl_fields ',' '}'              { $$ = $2; }
370 ;
371
372 struct_tuple_args
373 : '(' struct_tuple_fields ')'                 { $$ = $2; }
374 | '(' struct_tuple_fields ',' ')'             { $$ = $2; }
375 ;
376
377 struct_decl_fields
378 : struct_decl_field                           { $$ = mk_node("StructFields", 1, $1); }
379 | struct_decl_fields ',' struct_decl_field    { $$ = ext_node($1, 1, $3); }
380 | %empty                                      { $$ = mk_none(); }
381 ;
382
383 struct_decl_field
384 : attrs_and_vis ident ':' ty_sum              { $$ = mk_node("StructField", 3, $1, $2, $4); }
385 ;
386
387 struct_tuple_fields
388 : struct_tuple_field                          { $$ = mk_node("StructFields", 1, $1); }
389 | struct_tuple_fields ',' struct_tuple_field  { $$ = ext_node($1, 1, $3); }
390 ;
391
392 struct_tuple_field
393 : attrs_and_vis ty_sum                    { $$ = mk_node("StructField", 2, $1, $2); }
394 ;
395
396 // enums
397 item_enum
398 : ENUM ident generic_params maybe_where_clause '{' enum_defs '}'     { $$ = mk_node("ItemEnum", 0); }
399 | ENUM ident generic_params maybe_where_clause '{' enum_defs ',' '}' { $$ = mk_node("ItemEnum", 0); }
400 ;
401
402 enum_defs
403 : enum_def               { $$ = mk_node("EnumDefs", 1, $1); }
404 | enum_defs ',' enum_def { $$ = ext_node($1, 1, $3); }
405 | %empty                 { $$ = mk_none(); }
406 ;
407
408 enum_def
409 : attrs_and_vis ident enum_args { $$ = mk_node("EnumDef", 3, $1, $2, $3); }
410 ;
411
412 enum_args
413 : '{' struct_decl_fields '}'     { $$ = mk_node("EnumArgs", 1, $2); }
414 | '{' struct_decl_fields ',' '}' { $$ = mk_node("EnumArgs", 1, $2); }
415 | '(' maybe_ty_sums ')'          { $$ = mk_node("EnumArgs", 1, $2); }
416 | '=' expr                       { $$ = mk_node("EnumArgs", 1, $2); }
417 | %empty                         { $$ = mk_none(); }
418 ;
419
420 item_mod
421 : MOD ident ';'                                 { $$ = mk_node("ItemMod", 1, $2); }
422 | MOD ident '{' maybe_mod_items '}'             { $$ = mk_node("ItemMod", 2, $2, $4); }
423 | MOD ident '{' inner_attrs maybe_mod_items '}' { $$ = mk_node("ItemMod", 3, $2, $4, $5); }
424 ;
425
426 item_foreign_mod
427 : EXTERN maybe_abi '{' maybe_foreign_items '}'             { $$ = mk_node("ItemForeignMod", 1, $4); }
428 | EXTERN maybe_abi '{' inner_attrs maybe_foreign_items '}' { $$ = mk_node("ItemForeignMod", 2, $4, $5); }
429 ;
430
431 maybe_abi
432 : str
433 | %empty { $$ = mk_none(); }
434 ;
435
436 maybe_foreign_items
437 : foreign_items
438 | %empty { $$ = mk_none(); }
439 ;
440
441 foreign_items
442 : foreign_item               { $$ = mk_node("ForeignItems", 1, $1); }
443 | foreign_items foreign_item { $$ = ext_node($1, 1, $2); }
444 ;
445
446 foreign_item
447 : attrs_and_vis STATIC item_foreign_static { $$ = mk_node("ForeignItem", 2, $1, $3); }
448 | attrs_and_vis item_foreign_fn            { $$ = mk_node("ForeignItem", 2, $1, $2); }
449 | attrs_and_vis UNSAFE item_foreign_fn     { $$ = mk_node("ForeignItem", 2, $1, $3); }
450 ;
451
452 item_foreign_static
453 : maybe_mut ident ':' ty ';'               { $$ = mk_node("StaticItem", 3, $1, $2, $4); }
454 ;
455
456 item_foreign_fn
457 : FN ident generic_params fn_decl_allow_variadic maybe_where_clause ';' { $$ = mk_node("ForeignFn", 4, $2, $3, $4, $5); }
458 ;
459
460 fn_decl_allow_variadic
461 : fn_params_allow_variadic ret_ty { $$ = mk_node("FnDecl", 2, $1, $2); }
462 ;
463
464 fn_params_allow_variadic
465 : '(' ')'                      { $$ = mk_none(); }
466 | '(' params ')'               { $$ = $2; }
467 | '(' params ',' ')'           { $$ = $2; }
468 | '(' params ',' DOTDOTDOT ')' { $$ = $2; }
469 ;
470
471 visibility
472 : PUB      { $$ = mk_atom("Public"); }
473 | %empty   { $$ = mk_atom("Inherited"); }
474 ;
475
476 idents_or_self
477 : ident_or_self                    { $$ = mk_node("IdentsOrSelf", 1, $1); }
478 | ident_or_self AS ident           { $$ = mk_node("IdentsOrSelf", 2, $1, $3); }
479 | idents_or_self ',' ident_or_self { $$ = ext_node($1, 1, $3); }
480 ;
481
482 ident_or_self
483 : ident
484 | SELF  { $$ = mk_atom(yytext); }
485 ;
486
487 item_type
488 : TYPE ident generic_params maybe_where_clause '=' ty_sum ';'  { $$ = mk_node("ItemTy", 4, $2, $3, $4, $6); }
489 ;
490
491 for_sized
492 : FOR '?' ident { $$ = mk_node("ForSized", 1, $3); }
493 | FOR ident '?' { $$ = mk_node("ForSized", 1, $2); }
494 | %empty        { $$ = mk_none(); }
495 ;
496
497 item_trait
498 : maybe_unsafe TRAIT ident generic_params for_sized maybe_ty_param_bounds maybe_where_clause '{' maybe_trait_items '}'
499 {
500   $$ = mk_node("ItemTrait", 7, $1, $3, $4, $5, $6, $7, $9);
501 }
502 ;
503
504 maybe_trait_items
505 : trait_items
506 | %empty { $$ = mk_none(); }
507 ;
508
509 trait_items
510 : trait_item               { $$ = mk_node("TraitItems", 1, $1); }
511 | trait_items trait_item   { $$ = ext_node($1, 1, $2); }
512 ;
513
514 trait_item
515 : trait_const
516 | trait_type
517 | trait_method
518 ;
519
520 trait_const
521 : maybe_outer_attrs CONST ident maybe_ty_ascription maybe_const_default ';' { $$ = mk_node("ConstTraitItem", 4, $1, $3, $4, $5); }
522 ;
523
524 maybe_const_default
525 : '=' expr { $$ = mk_node("ConstDefault", 1, $2); }
526 | %empty   { $$ = mk_none(); }
527 ;
528
529 trait_type
530 : maybe_outer_attrs TYPE ty_param ';' { $$ = mk_node("TypeTraitItem", 2, $1, $3); }
531 ;
532
533 maybe_unsafe
534 : UNSAFE { $$ = mk_atom("Unsafe"); }
535 | %empty { $$ = mk_none(); }
536 ;
537
538 maybe_default_maybe_unsafe
539 : DEFAULT UNSAFE { $$ = mk_atom("DefaultUnsafe"); }
540 | DEFAULT        { $$ = mk_atom("Default"); }
541 |         UNSAFE { $$ = mk_atom("Unsafe"); }
542 | %empty { $$ = mk_none(); }
543
544 trait_method
545 : type_method { $$ = mk_node("Required", 1, $1); }
546 | method      { $$ = mk_node("Provided", 1, $1); }
547 ;
548
549 type_method
550 : attrs_and_vis maybe_unsafe FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause ';'
551 {
552   $$ = mk_node("TypeMethod", 6, $1, $2, $4, $5, $6, $7);
553 }
554 | attrs_and_vis maybe_unsafe EXTERN maybe_abi FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause ';'
555 {
556   $$ = mk_node("TypeMethod", 7, $1, $2, $4, $6, $7, $8, $9);
557 }
558 ;
559
560 method
561 : attrs_and_vis maybe_unsafe FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause inner_attrs_and_block
562 {
563   $$ = mk_node("Method", 7, $1, $2, $4, $5, $6, $7, $8);
564 }
565 | attrs_and_vis maybe_unsafe EXTERN maybe_abi FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause inner_attrs_and_block
566 {
567   $$ = mk_node("Method", 8, $1, $2, $4, $6, $7, $8, $9, $10);
568 }
569 ;
570
571 impl_method
572 : attrs_and_vis maybe_unsafe FN ident generic_params fn_decl_with_self maybe_where_clause inner_attrs_and_block
573 {
574   $$ = mk_node("Method", 7, $1, $2, $4, $5, $6, $7, $8);
575 }
576 | attrs_and_vis maybe_unsafe EXTERN maybe_abi FN ident generic_params fn_decl_with_self maybe_where_clause inner_attrs_and_block
577 {
578   $$ = mk_node("Method", 8, $1, $2, $4, $6, $7, $8, $9, $10);
579 }
580 ;
581
582 // There are two forms of impl:
583 //
584 // impl (<...>)? TY { ... }
585 // impl (<...>)? TRAIT for TY { ... }
586 //
587 // Unfortunately since TY can begin with '<' itself -- as part of a
588 // TyQualifiedPath type -- there's an s/r conflict when we see '<' after IMPL:
589 // should we reduce one of the early rules of TY (such as maybe_once)
590 // or shall we continue shifting into the generic_params list for the
591 // impl?
592 //
593 // The production parser disambiguates a different case here by
594 // permitting / requiring the user to provide parens around types when
595 // they are ambiguous with traits. We do the same here, regrettably,
596 // by splitting ty into ty and ty_prim.
597 item_impl
598 : maybe_default_maybe_unsafe IMPL generic_params ty_prim_sum maybe_where_clause '{' maybe_inner_attrs maybe_impl_items '}'
599 {
600   $$ = mk_node("ItemImpl", 6, $1, $3, $4, $5, $7, $8);
601 }
602 | maybe_default_maybe_unsafe IMPL generic_params '(' ty ')' maybe_where_clause '{' maybe_inner_attrs maybe_impl_items '}'
603 {
604   $$ = mk_node("ItemImpl", 6, $1, $3, 5, $6, $9, $10);
605 }
606 | maybe_default_maybe_unsafe IMPL generic_params trait_ref FOR ty_sum maybe_where_clause '{' maybe_inner_attrs maybe_impl_items '}'
607 {
608   $$ = mk_node("ItemImpl", 6, $3, $4, $6, $7, $9, $10);
609 }
610 | maybe_default_maybe_unsafe IMPL generic_params '!' trait_ref FOR ty_sum maybe_where_clause '{' maybe_inner_attrs maybe_impl_items '}'
611 {
612   $$ = mk_node("ItemImplNeg", 7, $1, $3, $5, $7, $8, $10, $11);
613 }
614 | maybe_default_maybe_unsafe IMPL generic_params trait_ref FOR DOTDOT '{' '}'
615 {
616   $$ = mk_node("ItemImplDefault", 3, $1, $3, $4);
617 }
618 | maybe_default_maybe_unsafe IMPL generic_params '!' trait_ref FOR DOTDOT '{' '}'
619 {
620   $$ = mk_node("ItemImplDefaultNeg", 3, $1, $3, $4);
621 }
622 ;
623
624 maybe_impl_items
625 : impl_items
626 | %empty { $$ = mk_none(); }
627 ;
628
629 impl_items
630 : impl_item               { $$ = mk_node("ImplItems", 1, $1); }
631 | impl_item impl_items    { $$ = ext_node($1, 1, $2); }
632 ;
633
634 impl_item
635 : impl_method
636 | attrs_and_vis item_macro { $$ = mk_node("ImplMacroItem", 2, $1, $2); }
637 | impl_const
638 | impl_type
639 ;
640
641 impl_const
642 : attrs_and_vis item_const { $$ = mk_node("ImplConst", 1, $1, $2); }
643 ;
644
645 impl_type
646 : attrs_and_vis TYPE ident generic_params '=' ty_sum ';'  { $$ = mk_node("ImplType", 4, $1, $3, $4, $6); }
647 ;
648
649 item_fn
650 : FN ident generic_params fn_decl maybe_where_clause inner_attrs_and_block
651 {
652   $$ = mk_node("ItemFn", 5, $2, $3, $4, $5, $6);
653 }
654 ;
655
656 item_unsafe_fn
657 : UNSAFE FN ident generic_params fn_decl maybe_where_clause inner_attrs_and_block
658 {
659   $$ = mk_node("ItemUnsafeFn", 5, $3, $4, $5, $6, $7);
660 }
661 | UNSAFE EXTERN maybe_abi FN ident generic_params fn_decl maybe_where_clause inner_attrs_and_block
662 {
663   $$ = mk_node("ItemUnsafeFn", 6, $3, $5, $6, $7, $8, $9);
664 }
665 ;
666
667 fn_decl
668 : fn_params ret_ty   { $$ = mk_node("FnDecl", 2, $1, $2); }
669 ;
670
671 fn_decl_with_self
672 : fn_params_with_self ret_ty   { $$ = mk_node("FnDecl", 2, $1, $2); }
673 ;
674
675 fn_decl_with_self_allow_anon_params
676 : fn_anon_params_with_self ret_ty   { $$ = mk_node("FnDecl", 2, $1, $2); }
677 ;
678
679 fn_params
680 : '(' maybe_params ')'  { $$ = $2; }
681 ;
682
683 fn_anon_params
684 : '(' anon_param anon_params_allow_variadic_tail ')' { $$ = ext_node($2, 1, $3); }
685 | '(' ')'                                            { $$ = mk_none(); }
686 ;
687
688 fn_params_with_self
689 : '(' maybe_mut SELF maybe_ty_ascription maybe_comma_params ')'              { $$ = mk_node("SelfValue", 3, $2, $4, $5); }
690 | '(' '&' maybe_mut SELF maybe_ty_ascription maybe_comma_params ')'          { $$ = mk_node("SelfRegion", 3, $3, $5, $6); }
691 | '(' '&' lifetime maybe_mut SELF maybe_ty_ascription maybe_comma_params ')' { $$ = mk_node("SelfRegion", 4, $3, $4, $6, $7); }
692 | '(' maybe_params ')'                                                       { $$ = mk_node("SelfStatic", 1, $2); }
693 ;
694
695 fn_anon_params_with_self
696 : '(' maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')'              { $$ = mk_node("SelfValue", 3, $2, $4, $5); }
697 | '(' '&' maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')'          { $$ = mk_node("SelfRegion", 3, $3, $5, $6); }
698 | '(' '&' lifetime maybe_mut SELF maybe_ty_ascription maybe_comma_anon_params ')' { $$ = mk_node("SelfRegion", 4, $3, $4, $6, $7); }
699 | '(' maybe_anon_params ')'                                                       { $$ = mk_node("SelfStatic", 1, $2); }
700 ;
701
702 maybe_params
703 : params
704 | params ','
705 | %empty  { $$ = mk_none(); }
706 ;
707
708 params
709 : param                { $$ = mk_node("Args", 1, $1); }
710 | params ',' param     { $$ = ext_node($1, 1, $3); }
711 ;
712
713 param
714 : pat ':' ty_sum   { $$ = mk_node("Arg", 2, $1, $3); }
715 ;
716
717 inferrable_params
718 : inferrable_param                       { $$ = mk_node("InferrableParams", 1, $1); }
719 | inferrable_params ',' inferrable_param { $$ = ext_node($1, 1, $3); }
720 ;
721
722 inferrable_param
723 : pat maybe_ty_ascription { $$ = mk_node("InferrableParam", 2, $1, $2); }
724 ;
725
726 maybe_unboxed_closure_kind
727 : %empty
728 | ':'
729 | '&' maybe_mut ':'
730 ;
731
732 maybe_comma_params
733 : ','            { $$ = mk_none(); }
734 | ',' params     { $$ = $2; }
735 | ',' params ',' { $$ = $2; }
736 | %empty         { $$ = mk_none(); }
737 ;
738
739 maybe_comma_anon_params
740 : ','                 { $$ = mk_none(); }
741 | ',' anon_params     { $$ = $2; }
742 | ',' anon_params ',' { $$ = $2; }
743 | %empty              { $$ = mk_none(); }
744 ;
745
746 maybe_anon_params
747 : anon_params
748 | anon_params ','
749 | %empty      { $$ = mk_none(); }
750 ;
751
752 anon_params
753 : anon_param                 { $$ = mk_node("Args", 1, $1); }
754 | anon_params ',' anon_param { $$ = ext_node($1, 1, $3); }
755 ;
756
757 // anon means it's allowed to be anonymous (type-only), but it can
758 // still have a name
759 anon_param
760 : named_arg ':' ty   { $$ = mk_node("Arg", 2, $1, $3); }
761 | ty
762 ;
763
764 anon_params_allow_variadic_tail
765 : ',' DOTDOTDOT                                  { $$ = mk_none(); }
766 | ',' anon_param anon_params_allow_variadic_tail { $$ = mk_node("Args", 2, $2, $3); }
767 | %empty                                         { $$ = mk_none(); }
768 ;
769
770 named_arg
771 : ident
772 | UNDERSCORE        { $$ = mk_atom("PatWild"); }
773 | '&' ident         { $$ = $2; }
774 | '&' UNDERSCORE    { $$ = mk_atom("PatWild"); }
775 | ANDAND ident      { $$ = $2; }
776 | ANDAND UNDERSCORE { $$ = mk_atom("PatWild"); }
777 | MUT ident         { $$ = $2; }
778 ;
779
780 ret_ty
781 : RARROW '!'         { $$ = mk_none(); }
782 | RARROW ty          { $$ = mk_node("ret-ty", 1, $2); }
783 | %prec IDENT %empty { $$ = mk_none(); }
784 ;
785
786 generic_params
787 : '<' lifetimes '>'                   { $$ = mk_node("Generics", 2, $2, mk_none()); }
788 | '<' lifetimes ',' '>'               { $$ = mk_node("Generics", 2, $2, mk_none()); }
789 | '<' lifetimes SHR                   { push_back('>'); $$ = mk_node("Generics", 2, $2, mk_none()); }
790 | '<' lifetimes ',' SHR               { push_back('>'); $$ = mk_node("Generics", 2, $2, mk_none()); }
791 | '<' lifetimes ',' ty_params '>'     { $$ = mk_node("Generics", 2, $2, $4); }
792 | '<' lifetimes ',' ty_params ',' '>' { $$ = mk_node("Generics", 2, $2, $4); }
793 | '<' lifetimes ',' ty_params SHR     { push_back('>'); $$ = mk_node("Generics", 2, $2, $4); }
794 | '<' lifetimes ',' ty_params ',' SHR { push_back('>'); $$ = mk_node("Generics", 2, $2, $4); }
795 | '<' ty_params '>'                   { $$ = mk_node("Generics", 2, mk_none(), $2); }
796 | '<' ty_params ',' '>'               { $$ = mk_node("Generics", 2, mk_none(), $2); }
797 | '<' ty_params SHR                   { push_back('>'); $$ = mk_node("Generics", 2, mk_none(), $2); }
798 | '<' ty_params ',' SHR               { push_back('>'); $$ = mk_node("Generics", 2, mk_none(), $2); }
799 | %empty                              { $$ = mk_none(); }
800 ;
801
802 maybe_where_clause
803 : %empty                              { $$ = mk_none(); }
804 | where_clause
805 ;
806
807 where_clause
808 : WHERE where_predicates              { $$ = mk_node("WhereClause", 1, $2); }
809 | WHERE where_predicates ','          { $$ = mk_node("WhereClause", 1, $2); }
810 ;
811
812 where_predicates
813 : where_predicate                      { $$ = mk_node("WherePredicates", 1, $1); }
814 | where_predicates ',' where_predicate { $$ = ext_node($1, 1, $3); }
815 ;
816
817 where_predicate
818 : maybe_for_lifetimes lifetime ':' bounds    { $$ = mk_node("WherePredicate", 3, $1, $2, $4); }
819 | maybe_for_lifetimes ty ':' ty_param_bounds { $$ = mk_node("WherePredicate", 3, $1, $2, $4); }
820 ;
821
822 maybe_for_lifetimes
823 : FOR '<' lifetimes '>' { $$ = mk_none(); }
824 | %prec FORTYPE %empty  { $$ = mk_none(); }
825
826 ty_params
827 : ty_param               { $$ = mk_node("TyParams", 1, $1); }
828 | ty_params ',' ty_param { $$ = ext_node($1, 1, $3); }
829 ;
830
831 // A path with no type parameters; e.g. `foo::bar::Baz`
832 //
833 // These show up in 'use' view-items, because these are processed
834 // without respect to types.
835 path_no_types_allowed
836 : ident                               { $$ = mk_node("ViewPath", 1, $1); }
837 | MOD_SEP ident                       { $$ = mk_node("ViewPath", 1, $2); }
838 | SELF                                { $$ = mk_node("ViewPath", 1, mk_atom("Self")); }
839 | MOD_SEP SELF                        { $$ = mk_node("ViewPath", 1, mk_atom("Self")); }
840 | path_no_types_allowed MOD_SEP ident { $$ = ext_node($1, 1, $3); }
841 ;
842
843 // A path with a lifetime and type parameters, with no double colons
844 // before the type parameters; e.g. `foo::bar<'a>::Baz<T>`
845 //
846 // These show up in "trait references", the components of
847 // type-parameter bounds lists, as well as in the prefix of the
848 // path_generic_args_and_bounds rule, which is the full form of a
849 // named typed expression.
850 //
851 // They do not have (nor need) an extra '::' before '<' because
852 // unlike in expr context, there are no "less-than" type exprs to
853 // be ambiguous with.
854 path_generic_args_without_colons
855 : %prec IDENT
856   ident                                                                       { $$ = mk_node("components", 1, $1); }
857 | %prec IDENT
858   ident generic_args                                                          { $$ = mk_node("components", 2, $1, $2); }
859 | %prec IDENT
860   ident '(' maybe_ty_sums ')' ret_ty                                          { $$ = mk_node("components", 2, $1, $3); }
861 | %prec IDENT
862   path_generic_args_without_colons MOD_SEP ident                              { $$ = ext_node($1, 1, $3); }
863 | %prec IDENT
864   path_generic_args_without_colons MOD_SEP ident generic_args                 { $$ = ext_node($1, 2, $3, $4); }
865 | %prec IDENT
866   path_generic_args_without_colons MOD_SEP ident '(' maybe_ty_sums ')' ret_ty { $$ = ext_node($1, 2, $3, $5); }
867 ;
868
869 generic_args
870 : '<' generic_values '>'   { $$ = $2; }
871 | '<' generic_values SHR   { push_back('>'); $$ = $2; }
872 | '<' generic_values GE    { push_back('='); $$ = $2; }
873 | '<' generic_values SHREQ { push_back('>'); push_back('='); $$ = $2; }
874 // If generic_args starts with "<<", the first arg must be a
875 // TyQualifiedPath because that's the only type that can start with a
876 // '<'. This rule parses that as the first ty_sum and then continues
877 // with the rest of generic_values.
878 | SHL ty_qualified_path_and_generic_values '>'   { $$ = $2; }
879 | SHL ty_qualified_path_and_generic_values SHR   { push_back('>'); $$ = $2; }
880 | SHL ty_qualified_path_and_generic_values GE    { push_back('='); $$ = $2; }
881 | SHL ty_qualified_path_and_generic_values SHREQ { push_back('>'); push_back('='); $$ = $2; }
882 ;
883
884 generic_values
885 : maybe_lifetimes maybe_ty_sums_and_or_bindings { $$ = mk_node("GenericValues", 2, $1, $2); }
886 ;
887
888 maybe_ty_sums_and_or_bindings
889 : ty_sums
890 | ty_sums ','
891 | ty_sums ',' bindings { $$ = mk_node("TySumsAndBindings", 2, $1, $3); }
892 | bindings
893 | bindings ','
894 | %empty               { $$ = mk_none(); }
895 ;
896
897 maybe_bindings
898 : ',' bindings { $$ = $2; }
899 | %empty       { $$ = mk_none(); }
900 ;
901
902 ////////////////////////////////////////////////////////////////////////
903 // Part 2: Patterns
904 ////////////////////////////////////////////////////////////////////////
905
906 pat
907 : UNDERSCORE                                      { $$ = mk_atom("PatWild"); }
908 | '&' pat                                         { $$ = mk_node("PatRegion", 1, $2); }
909 | '&' MUT pat                                     { $$ = mk_node("PatRegion", 1, $3); }
910 | ANDAND pat                                      { $$ = mk_node("PatRegion", 1, mk_node("PatRegion", 1, $2)); }
911 | '(' ')'                                         { $$ = mk_atom("PatUnit"); }
912 | '(' pat_tup ')'                                 { $$ = mk_node("PatTup", 1, $2); }
913 | '(' pat_tup ',' ')'                             { $$ = mk_node("PatTup", 1, $2); }
914 | '[' pat_vec ']'                                 { $$ = mk_node("PatVec", 1, $2); }
915 | lit_or_path
916 | lit_or_path DOTDOTDOT lit_or_path               { $$ = mk_node("PatRange", 2, $1, $3); }
917 | path_expr '{' pat_struct '}'                    { $$ = mk_node("PatStruct", 2, $1, $3); }
918 | path_expr '(' DOTDOT ')'                        { $$ = mk_node("PatEnum", 1, $1); }
919 | path_expr '(' pat_tup ')'                       { $$ = mk_node("PatEnum", 2, $1, $3); }
920 | path_expr '!' maybe_ident delimited_token_trees { $$ = mk_node("PatMac", 3, $1, $3, $4); }
921 | binding_mode ident                              { $$ = mk_node("PatIdent", 2, $1, $2); }
922 |              ident '@' pat                      { $$ = mk_node("PatIdent", 3, mk_node("BindByValue", 1, mk_atom("MutImmutable")), $1, $3); }
923 | binding_mode ident '@' pat                      { $$ = mk_node("PatIdent", 3, $1, $2, $4); }
924 | BOX pat                                         { $$ = mk_node("PatUniq", 1, $2); }
925 | '<' ty_sum maybe_as_trait_ref '>' MOD_SEP ident { $$ = mk_node("PatQualifiedPath", 3, $2, $3, $6); }
926 | SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident maybe_as_trait_ref '>' MOD_SEP ident
927 {
928   $$ = mk_node("PatQualifiedPath", 3, mk_node("PatQualifiedPath", 3, $2, $3, $6), $7, $10);
929 }
930 ;
931
932 pats_or
933 : pat              { $$ = mk_node("Pats", 1, $1); }
934 | pats_or '|' pat  { $$ = ext_node($1, 1, $3); }
935 ;
936
937 binding_mode
938 : REF         { $$ = mk_node("BindByRef", 1, mk_atom("MutImmutable")); }
939 | REF MUT     { $$ = mk_node("BindByRef", 1, mk_atom("MutMutable")); }
940 | MUT         { $$ = mk_node("BindByValue", 1, mk_atom("MutMutable")); }
941 ;
942
943 lit_or_path
944 : path_expr    { $$ = mk_node("PatLit", 1, $1); }
945 | lit          { $$ = mk_node("PatLit", 1, $1); }
946 | '-' lit      { $$ = mk_node("PatLit", 1, $2); }
947 ;
948
949 pat_field
950 :                  ident        { $$ = mk_node("PatField", 1, $1); }
951 |     binding_mode ident        { $$ = mk_node("PatField", 2, $1, $2); }
952 | BOX              ident        { $$ = mk_node("PatField", 2, mk_atom("box"), $2); }
953 | BOX binding_mode ident        { $$ = mk_node("PatField", 3, mk_atom("box"), $2, $3); }
954 |              ident ':' pat    { $$ = mk_node("PatField", 2, $1, $3); }
955 | binding_mode ident ':' pat    { $$ = mk_node("PatField", 3, $1, $2, $4); }
956 ;
957
958 pat_fields
959 : pat_field                  { $$ = mk_node("PatFields", 1, $1); }
960 | pat_fields ',' pat_field   { $$ = ext_node($1, 1, $3); }
961 ;
962
963 pat_struct
964 : pat_fields                 { $$ = mk_node("PatStruct", 2, $1, mk_atom("false")); }
965 | pat_fields ','             { $$ = mk_node("PatStruct", 2, $1, mk_atom("false")); }
966 | pat_fields ',' DOTDOT      { $$ = mk_node("PatStruct", 2, $1, mk_atom("true")); }
967 | DOTDOT                     { $$ = mk_node("PatStruct", 1, mk_atom("true")); }
968 ;
969
970 pat_tup
971 : pat               { $$ = mk_node("pat_tup", 1, $1); }
972 | pat_tup ',' pat   { $$ = ext_node($1, 1, $3); }
973 ;
974
975 pat_vec
976 : pat_vec_elts                                  { $$ = mk_node("PatVec", 2, $1, mk_none()); }
977 | pat_vec_elts                             ','  { $$ = mk_node("PatVec", 2, $1, mk_none()); }
978 | pat_vec_elts     DOTDOT                       { $$ = mk_node("PatVec", 2, $1, mk_none()); }
979 | pat_vec_elts ',' DOTDOT                       { $$ = mk_node("PatVec", 2, $1, mk_none()); }
980 | pat_vec_elts     DOTDOT ',' pat_vec_elts      { $$ = mk_node("PatVec", 2, $1, $4); }
981 | pat_vec_elts     DOTDOT ',' pat_vec_elts ','  { $$ = mk_node("PatVec", 2, $1, $4); }
982 | pat_vec_elts ',' DOTDOT ',' pat_vec_elts      { $$ = mk_node("PatVec", 2, $1, $5); }
983 | pat_vec_elts ',' DOTDOT ',' pat_vec_elts ','  { $$ = mk_node("PatVec", 2, $1, $5); }
984 |                  DOTDOT ',' pat_vec_elts      { $$ = mk_node("PatVec", 2, mk_none(), $3); }
985 |                  DOTDOT ',' pat_vec_elts ','  { $$ = mk_node("PatVec", 2, mk_none(), $3); }
986 |                  DOTDOT                       { $$ = mk_node("PatVec", 2, mk_none(), mk_none()); }
987 | %empty                                        { $$ = mk_node("PatVec", 2, mk_none(), mk_none()); }
988 ;
989
990 pat_vec_elts
991 : pat                    { $$ = mk_node("PatVecElts", 1, $1); }
992 | pat_vec_elts ',' pat   { $$ = ext_node($1, 1, $3); }
993 ;
994
995 ////////////////////////////////////////////////////////////////////////
996 // Part 3: Types
997 ////////////////////////////////////////////////////////////////////////
998
999 ty
1000 : ty_prim
1001 | ty_closure
1002 | '<' ty_sum maybe_as_trait_ref '>' MOD_SEP ident                                      { $$ = mk_node("TyQualifiedPath", 3, $2, $3, $6); }
1003 | SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident maybe_as_trait_ref '>' MOD_SEP ident { $$ = mk_node("TyQualifiedPath", 3, mk_node("TyQualifiedPath", 3, $2, $3, $6), $7, $10); }
1004 | '(' ty_sums ')'                                                                      { $$ = mk_node("TyTup", 1, $2); }
1005 | '(' ty_sums ',' ')'                                                                  { $$ = mk_node("TyTup", 1, $2); }
1006 | '(' ')'                                                                              { $$ = mk_atom("TyNil"); }
1007 ;
1008
1009 ty_prim
1010 : %prec IDENT path_generic_args_without_colons              { $$ = mk_node("TyPath", 2, mk_node("global", 1, mk_atom("false")), $1); }
1011 | %prec IDENT MOD_SEP path_generic_args_without_colons      { $$ = mk_node("TyPath", 2, mk_node("global", 1, mk_atom("true")), $2); }
1012 | %prec IDENT SELF MOD_SEP path_generic_args_without_colons { $$ = mk_node("TyPath", 2, mk_node("self", 1, mk_atom("true")), $3); }
1013 | BOX ty                                                    { $$ = mk_node("TyBox", 1, $2); }
1014 | '*' maybe_mut_or_const ty                                 { $$ = mk_node("TyPtr", 2, $2, $3); }
1015 | '&' ty                                                    { $$ = mk_node("TyRptr", 2, mk_atom("MutImmutable"), $2); }
1016 | '&' MUT ty                                                { $$ = mk_node("TyRptr", 2, mk_atom("MutMutable"), $3); }
1017 | ANDAND ty                                                 { $$ = mk_node("TyRptr", 1, mk_node("TyRptr", 2, mk_atom("MutImmutable"), $2)); }
1018 | ANDAND MUT ty                                             { $$ = mk_node("TyRptr", 1, mk_node("TyRptr", 2, mk_atom("MutMutable"), $3)); }
1019 | '&' lifetime maybe_mut ty                                 { $$ = mk_node("TyRptr", 3, $2, $3, $4); }
1020 | ANDAND lifetime maybe_mut ty                              { $$ = mk_node("TyRptr", 1, mk_node("TyRptr", 3, $2, $3, $4)); }
1021 | '[' ty ']'                                                { $$ = mk_node("TyVec", 1, $2); }
1022 | '[' ty ',' DOTDOT expr ']'                                { $$ = mk_node("TyFixedLengthVec", 2, $2, $5); }
1023 | '[' ty ';' expr ']'                                       { $$ = mk_node("TyFixedLengthVec", 2, $2, $4); }
1024 | TYPEOF '(' expr ')'                                       { $$ = mk_node("TyTypeof", 1, $3); }
1025 | UNDERSCORE                                                { $$ = mk_atom("TyInfer"); }
1026 | ty_bare_fn
1027 | ty_proc
1028 | for_in_type
1029 ;
1030
1031 ty_bare_fn
1032 :                         FN ty_fn_decl { $$ = $2; }
1033 | UNSAFE                  FN ty_fn_decl { $$ = $3; }
1034 |        EXTERN maybe_abi FN ty_fn_decl { $$ = $4; }
1035 | UNSAFE EXTERN maybe_abi FN ty_fn_decl { $$ = $5; }
1036 ;
1037
1038 ty_fn_decl
1039 : generic_params fn_anon_params ret_ty { $$ = mk_node("TyFnDecl", 3, $1, $2, $3); }
1040 ;
1041
1042 ty_closure
1043 : UNSAFE '|' anon_params '|' maybe_bounds ret_ty { $$ = mk_node("TyClosure", 3, $3, $5, $6); }
1044 |        '|' anon_params '|' maybe_bounds ret_ty { $$ = mk_node("TyClosure", 3, $2, $4, $5); }
1045 | UNSAFE OROR maybe_bounds ret_ty                { $$ = mk_node("TyClosure", 2, $3, $4); }
1046 |        OROR maybe_bounds ret_ty                { $$ = mk_node("TyClosure", 2, $2, $3); }
1047 ;
1048
1049 ty_proc
1050 : PROC generic_params fn_params maybe_bounds ret_ty { $$ = mk_node("TyProc", 4, $2, $3, $4, $5); }
1051 ;
1052
1053 for_in_type
1054 : FOR '<' maybe_lifetimes '>' for_in_type_suffix { $$ = mk_node("ForInType", 2, $3, $5); }
1055 ;
1056
1057 for_in_type_suffix
1058 : ty_proc
1059 | ty_bare_fn
1060 | trait_ref
1061 | ty_closure
1062 ;
1063
1064 maybe_mut
1065 : MUT              { $$ = mk_atom("MutMutable"); }
1066 | %prec MUT %empty { $$ = mk_atom("MutImmutable"); }
1067 ;
1068
1069 maybe_mut_or_const
1070 : MUT    { $$ = mk_atom("MutMutable"); }
1071 | CONST  { $$ = mk_atom("MutImmutable"); }
1072 | %empty { $$ = mk_atom("MutImmutable"); }
1073 ;
1074
1075 ty_qualified_path_and_generic_values
1076 : ty_qualified_path maybe_bindings
1077 {
1078   $$ = mk_node("GenericValues", 3, mk_none(), mk_node("TySums", 1, mk_node("TySum", 1, $1)), $2);
1079 }
1080 | ty_qualified_path ',' ty_sums maybe_bindings
1081 {
1082   $$ = mk_node("GenericValues", 3, mk_none(), mk_node("TySums", 2, $1, $3), $4);
1083 }
1084 ;
1085
1086 ty_qualified_path
1087 : ty_sum AS trait_ref '>' MOD_SEP ident                     { $$ = mk_node("TyQualifiedPath", 3, $1, $3, $6); }
1088 | ty_sum AS trait_ref '>' MOD_SEP ident '+' ty_param_bounds { $$ = mk_node("TyQualifiedPath", 3, $1, $3, $6); }
1089 ;
1090
1091 maybe_ty_sums
1092 : ty_sums
1093 | ty_sums ','
1094 | %empty { $$ = mk_none(); }
1095 ;
1096
1097 ty_sums
1098 : ty_sum             { $$ = mk_node("TySums", 1, $1); }
1099 | ty_sums ',' ty_sum { $$ = ext_node($1, 1, $3); }
1100 ;
1101
1102 ty_sum
1103 : ty                     { $$ = mk_node("TySum", 1, $1); }
1104 | ty '+' ty_param_bounds { $$ = mk_node("TySum", 2, $1, $3); }
1105 ;
1106
1107 ty_prim_sum
1108 : ty_prim                     { $$ = mk_node("TySum", 1, $1); }
1109 | ty_prim '+' ty_param_bounds { $$ = mk_node("TySum", 2, $1, $3); }
1110 ;
1111
1112 maybe_ty_param_bounds
1113 : ':' ty_param_bounds { $$ = $2; }
1114 | %empty              { $$ = mk_none(); }
1115 ;
1116
1117 ty_param_bounds
1118 : boundseq
1119 | %empty { $$ = mk_none(); }
1120 ;
1121
1122 boundseq
1123 : polybound
1124 | boundseq '+' polybound { $$ = ext_node($1, 1, $3); }
1125 ;
1126
1127 polybound
1128 : FOR '<' maybe_lifetimes '>' bound { $$ = mk_node("PolyBound", 2, $3, $5); }
1129 | bound
1130 | '?' bound { $$ = $2; }
1131 ;
1132
1133 bindings
1134 : binding              { $$ = mk_node("Bindings", 1, $1); }
1135 | bindings ',' binding { $$ = ext_node($1, 1, $3); }
1136 ;
1137
1138 binding
1139 : ident '=' ty { mk_node("Binding", 2, $1, $3); }
1140 ;
1141
1142 ty_param
1143 : ident maybe_ty_param_bounds maybe_ty_default           { $$ = mk_node("TyParam", 3, $1, $2, $3); }
1144 | ident '?' ident maybe_ty_param_bounds maybe_ty_default { $$ = mk_node("TyParam", 4, $1, $3, $4, $5); }
1145 ;
1146
1147 maybe_bounds
1148 : %prec SHIFTPLUS
1149   ':' bounds             { $$ = $2; }
1150 | %prec SHIFTPLUS %empty { $$ = mk_none(); }
1151 ;
1152
1153 bounds
1154 : bound            { $$ = mk_node("bounds", 1, $1); }
1155 | bounds '+' bound { $$ = ext_node($1, 1, $3); }
1156 ;
1157
1158 bound
1159 : lifetime
1160 | trait_ref
1161 ;
1162
1163 maybe_ltbounds
1164 : %prec SHIFTPLUS
1165   ':' ltbounds       { $$ = $2; }
1166 | %empty             { $$ = mk_none(); }
1167 ;
1168
1169 ltbounds
1170 : lifetime              { $$ = mk_node("ltbounds", 1, $1); }
1171 | ltbounds '+' lifetime { $$ = ext_node($1, 1, $3); }
1172 ;
1173
1174 maybe_ty_default
1175 : '=' ty_sum { $$ = mk_node("TyDefault", 1, $2); }
1176 | %empty     { $$ = mk_none(); }
1177 ;
1178
1179 maybe_lifetimes
1180 : lifetimes
1181 | lifetimes ','
1182 | %empty { $$ = mk_none(); }
1183 ;
1184
1185 lifetimes
1186 : lifetime_and_bounds               { $$ = mk_node("Lifetimes", 1, $1); }
1187 | lifetimes ',' lifetime_and_bounds { $$ = ext_node($1, 1, $3); }
1188 ;
1189
1190 lifetime_and_bounds
1191 : LIFETIME maybe_ltbounds         { $$ = mk_node("lifetime", 2, mk_atom(yytext), $2); }
1192 | STATIC_LIFETIME                 { $$ = mk_atom("static_lifetime"); }
1193 ;
1194
1195 lifetime
1196 : LIFETIME         { $$ = mk_node("lifetime", 1, mk_atom(yytext)); }
1197 | STATIC_LIFETIME  { $$ = mk_atom("static_lifetime"); }
1198 ;
1199
1200 trait_ref
1201 : %prec IDENT path_generic_args_without_colons
1202 | %prec IDENT MOD_SEP path_generic_args_without_colons { $$ = $2; }
1203 ;
1204
1205 ////////////////////////////////////////////////////////////////////////
1206 // Part 4: Blocks, statements, and expressions
1207 ////////////////////////////////////////////////////////////////////////
1208
1209 inner_attrs_and_block
1210 : '{' maybe_inner_attrs maybe_stmts '}'        { $$ = mk_node("ExprBlock", 2, $2, $3); }
1211 ;
1212
1213 block
1214 : '{' maybe_stmts '}'                          { $$ = mk_node("ExprBlock", 1, $2); }
1215 ;
1216
1217 maybe_stmts
1218 : stmts
1219 | stmts nonblock_expr { $$ = ext_node($1, 1, $2); }
1220 | nonblock_expr
1221 | %empty              { $$ = mk_none(); }
1222 ;
1223
1224 // There are two sub-grammars within a "stmts: exprs" derivation
1225 // depending on whether each stmt-expr is a block-expr form; this is to
1226 // handle the "semicolon rule" for stmt sequencing that permits
1227 // writing
1228 //
1229 //     if foo { bar } 10
1230 //
1231 // as a sequence of two stmts (one if-expr stmt, one lit-10-expr
1232 // stmt). Unfortunately by permitting juxtaposition of exprs in
1233 // sequence like that, the non-block expr grammar has to have a
1234 // second limited sub-grammar that excludes the prefix exprs that
1235 // are ambiguous with binops. That is to say:
1236 //
1237 //     {10} - 1
1238 //
1239 // should parse as (progn (progn 10) (- 1)) not (- (progn 10) 1), that
1240 // is to say, two statements rather than one, at least according to
1241 // the mainline rust parser.
1242 //
1243 // So we wind up with a 3-way split in exprs that occur in stmt lists:
1244 // block, nonblock-prefix, and nonblock-nonprefix.
1245 //
1246 // In non-stmts contexts, expr can relax this trichotomy.
1247 //
1248 // There is also one other expr subtype: nonparen_expr disallows exprs
1249 // surrounded by parens (including tuple expressions), this is
1250 // necessary for BOX (place) expressions, so a parens expr following
1251 // the BOX is always parsed as the place.
1252
1253 stmts
1254 : stmt           { $$ = mk_node("stmts", 1, $1); }
1255 | stmts stmt     { $$ = ext_node($1, 1, $2); }
1256 ;
1257
1258 stmt
1259 : let
1260 |                 stmt_item
1261 |             PUB stmt_item { $$ = $2; }
1262 | outer_attrs     stmt_item { $$ = $2; }
1263 | outer_attrs PUB stmt_item { $$ = $3; }
1264 | full_block_expr
1265 | block
1266 | nonblock_expr ';'
1267 | ';'                   { $$ = mk_none(); }
1268 ;
1269
1270 maybe_exprs
1271 : exprs
1272 | exprs ','
1273 | %empty { $$ = mk_none(); }
1274 ;
1275
1276 maybe_expr
1277 : expr
1278 | %empty { $$ = mk_none(); }
1279 ;
1280
1281 exprs
1282 : expr                                                        { $$ = mk_node("exprs", 1, $1); }
1283 | exprs ',' expr                                              { $$ = ext_node($1, 1, $3); }
1284 ;
1285
1286 path_expr
1287 : path_generic_args_with_colons
1288 | MOD_SEP path_generic_args_with_colons      { $$ = $2; }
1289 | SELF MOD_SEP path_generic_args_with_colons { $$ = mk_node("SelfPath", 1, $3); }
1290 ;
1291
1292 // A path with a lifetime and type parameters with double colons before
1293 // the type parameters; e.g. `foo::bar::<'a>::Baz::<T>`
1294 //
1295 // These show up in expr context, in order to disambiguate from "less-than"
1296 // expressions.
1297 path_generic_args_with_colons
1298 : ident                                              { $$ = mk_node("components", 1, $1); }
1299 | path_generic_args_with_colons MOD_SEP ident        { $$ = ext_node($1, 1, $3); }
1300 | path_generic_args_with_colons MOD_SEP generic_args { $$ = ext_node($1, 1, $3); }
1301 ;
1302
1303 // the braces-delimited macro is a block_expr so it doesn't appear here
1304 macro_expr
1305 : path_expr '!' maybe_ident parens_delimited_token_trees   { $$ = mk_node("MacroExpr", 3, $1, $3, $4); }
1306 | path_expr '!' maybe_ident brackets_delimited_token_trees { $$ = mk_node("MacroExpr", 3, $1, $3, $4); }
1307 ;
1308
1309 nonblock_expr
1310 : lit                                                           { $$ = mk_node("ExprLit", 1, $1); }
1311 | %prec IDENT
1312   path_expr                                                     { $$ = mk_node("ExprPath", 1, $1); }
1313 | SELF                                                          { $$ = mk_node("ExprPath", 1, mk_node("ident", 1, mk_atom("self"))); }
1314 | macro_expr                                                    { $$ = mk_node("ExprMac", 1, $1); }
1315 | path_expr '{' struct_expr_fields '}'                          { $$ = mk_node("ExprStruct", 2, $1, $3); }
1316 | nonblock_expr '.' path_generic_args_with_colons               { $$ = mk_node("ExprField", 2, $1, $3); }
1317 | nonblock_expr '.' LIT_INTEGER                                 { $$ = mk_node("ExprTupleIndex", 1, $1); }
1318 | nonblock_expr '[' maybe_expr ']'                              { $$ = mk_node("ExprIndex", 2, $1, $3); }
1319 | nonblock_expr '(' maybe_exprs ')'                             { $$ = mk_node("ExprCall", 2, $1, $3); }
1320 | '[' vec_expr ']'                                              { $$ = mk_node("ExprVec", 1, $2); }
1321 | '(' maybe_exprs ')'                                           { $$ = mk_node("ExprParen", 1, $2); }
1322 | CONTINUE                                                      { $$ = mk_node("ExprAgain", 0); }
1323 | CONTINUE lifetime                                             { $$ = mk_node("ExprAgain", 1, $2); }
1324 | RETURN                                                        { $$ = mk_node("ExprRet", 0); }
1325 | RETURN expr                                                   { $$ = mk_node("ExprRet", 1, $2); }
1326 | BREAK                                                         { $$ = mk_node("ExprBreak", 0); }
1327 | BREAK lifetime                                                { $$ = mk_node("ExprBreak", 1, $2); }
1328 | nonblock_expr LARROW expr                                     { $$ = mk_node("ExprInPlace", 2, $1, $3); }
1329 | nonblock_expr '=' expr                                        { $$ = mk_node("ExprAssign", 2, $1, $3); }
1330 | nonblock_expr SHLEQ expr                                      { $$ = mk_node("ExprAssignShl", 2, $1, $3); }
1331 | nonblock_expr SHREQ expr                                      { $$ = mk_node("ExprAssignShr", 2, $1, $3); }
1332 | nonblock_expr MINUSEQ expr                                    { $$ = mk_node("ExprAssignSub", 2, $1, $3); }
1333 | nonblock_expr ANDEQ expr                                      { $$ = mk_node("ExprAssignBitAnd", 2, $1, $3); }
1334 | nonblock_expr OREQ expr                                       { $$ = mk_node("ExprAssignBitOr", 2, $1, $3); }
1335 | nonblock_expr PLUSEQ expr                                     { $$ = mk_node("ExprAssignAdd", 2, $1, $3); }
1336 | nonblock_expr STAREQ expr                                     { $$ = mk_node("ExprAssignMul", 2, $1, $3); }
1337 | nonblock_expr SLASHEQ expr                                    { $$ = mk_node("ExprAssignDiv", 2, $1, $3); }
1338 | nonblock_expr CARETEQ expr                                    { $$ = mk_node("ExprAssignBitXor", 2, $1, $3); }
1339 | nonblock_expr PERCENTEQ expr                                  { $$ = mk_node("ExprAssignRem", 2, $1, $3); }
1340 | nonblock_expr OROR expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiOr"), $1, $3); }
1341 | nonblock_expr ANDAND expr                                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiAnd"), $1, $3); }
1342 | nonblock_expr EQEQ expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiEq"), $1, $3); }
1343 | nonblock_expr NE expr                                         { $$ = mk_node("ExprBinary", 3, mk_atom("BiNe"), $1, $3); }
1344 | nonblock_expr '<' expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiLt"), $1, $3); }
1345 | nonblock_expr '>' expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiGt"), $1, $3); }
1346 | nonblock_expr LE expr                                         { $$ = mk_node("ExprBinary", 3, mk_atom("BiLe"), $1, $3); }
1347 | nonblock_expr GE expr                                         { $$ = mk_node("ExprBinary", 3, mk_atom("BiGe"), $1, $3); }
1348 | nonblock_expr '|' expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitOr"), $1, $3); }
1349 | nonblock_expr '^' expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitXor"), $1, $3); }
1350 | nonblock_expr '&' expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitAnd"), $1, $3); }
1351 | nonblock_expr SHL expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiShl"), $1, $3); }
1352 | nonblock_expr SHR expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiShr"), $1, $3); }
1353 | nonblock_expr '+' expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiAdd"), $1, $3); }
1354 | nonblock_expr '-' expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiSub"), $1, $3); }
1355 | nonblock_expr '*' expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiMul"), $1, $3); }
1356 | nonblock_expr '/' expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiDiv"), $1, $3); }
1357 | nonblock_expr '%' expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiRem"), $1, $3); }
1358 | nonblock_expr DOTDOT                                          { $$ = mk_node("ExprRange", 2, $1, mk_none()); }
1359 | nonblock_expr DOTDOT expr                                     { $$ = mk_node("ExprRange", 2, $1, $3); }
1360 |               DOTDOT expr                                     { $$ = mk_node("ExprRange", 2, mk_none(), $2); }
1361 |               DOTDOT                                          { $$ = mk_node("ExprRange", 2, mk_none(), mk_none()); }
1362 | nonblock_expr AS ty                                           { $$ = mk_node("ExprCast", 2, $1, $3); }
1363 | BOX nonparen_expr                                             { $$ = mk_node("ExprBox", 1, $2); }
1364 | %prec BOXPLACE BOX '(' maybe_expr ')' nonblock_expr           { $$ = mk_node("ExprBox", 2, $3, $5); }
1365 | expr_qualified_path
1366 | nonblock_prefix_expr
1367 ;
1368
1369 expr
1370 : lit                                                 { $$ = mk_node("ExprLit", 1, $1); }
1371 | %prec IDENT
1372   path_expr                                           { $$ = mk_node("ExprPath", 1, $1); }
1373 | SELF                                                { $$ = mk_node("ExprPath", 1, mk_node("ident", 1, mk_atom("self"))); }
1374 | macro_expr                                          { $$ = mk_node("ExprMac", 1, $1); }
1375 | path_expr '{' struct_expr_fields '}'                { $$ = mk_node("ExprStruct", 2, $1, $3); }
1376 | expr '.' path_generic_args_with_colons              { $$ = mk_node("ExprField", 2, $1, $3); }
1377 | expr '.' LIT_INTEGER                                { $$ = mk_node("ExprTupleIndex", 1, $1); }
1378 | expr '[' maybe_expr ']'                             { $$ = mk_node("ExprIndex", 2, $1, $3); }
1379 | expr '(' maybe_exprs ')'                            { $$ = mk_node("ExprCall", 2, $1, $3); }
1380 | '(' maybe_exprs ')'                                 { $$ = mk_node("ExprParen", 1, $2); }
1381 | '[' vec_expr ']'                                    { $$ = mk_node("ExprVec", 1, $2); }
1382 | CONTINUE                                            { $$ = mk_node("ExprAgain", 0); }
1383 | CONTINUE ident                                      { $$ = mk_node("ExprAgain", 1, $2); }
1384 | RETURN                                              { $$ = mk_node("ExprRet", 0); }
1385 | RETURN expr                                         { $$ = mk_node("ExprRet", 1, $2); }
1386 | BREAK                                               { $$ = mk_node("ExprBreak", 0); }
1387 | BREAK ident                                         { $$ = mk_node("ExprBreak", 1, $2); }
1388 | expr LARROW expr                                    { $$ = mk_node("ExprInPlace", 2, $1, $3); }
1389 | expr '=' expr                                       { $$ = mk_node("ExprAssign", 2, $1, $3); }
1390 | expr SHLEQ expr                                     { $$ = mk_node("ExprAssignShl", 2, $1, $3); }
1391 | expr SHREQ expr                                     { $$ = mk_node("ExprAssignShr", 2, $1, $3); }
1392 | expr MINUSEQ expr                                   { $$ = mk_node("ExprAssignSub", 2, $1, $3); }
1393 | expr ANDEQ expr                                     { $$ = mk_node("ExprAssignBitAnd", 2, $1, $3); }
1394 | expr OREQ expr                                      { $$ = mk_node("ExprAssignBitOr", 2, $1, $3); }
1395 | expr PLUSEQ expr                                    { $$ = mk_node("ExprAssignAdd", 2, $1, $3); }
1396 | expr STAREQ expr                                    { $$ = mk_node("ExprAssignMul", 2, $1, $3); }
1397 | expr SLASHEQ expr                                   { $$ = mk_node("ExprAssignDiv", 2, $1, $3); }
1398 | expr CARETEQ expr                                   { $$ = mk_node("ExprAssignBitXor", 2, $1, $3); }
1399 | expr PERCENTEQ expr                                 { $$ = mk_node("ExprAssignRem", 2, $1, $3); }
1400 | expr OROR expr                                      { $$ = mk_node("ExprBinary", 3, mk_atom("BiOr"), $1, $3); }
1401 | expr ANDAND expr                                    { $$ = mk_node("ExprBinary", 3, mk_atom("BiAnd"), $1, $3); }
1402 | expr EQEQ expr                                      { $$ = mk_node("ExprBinary", 3, mk_atom("BiEq"), $1, $3); }
1403 | expr NE expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiNe"), $1, $3); }
1404 | expr '<' expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiLt"), $1, $3); }
1405 | expr '>' expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiGt"), $1, $3); }
1406 | expr LE expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiLe"), $1, $3); }
1407 | expr GE expr                                        { $$ = mk_node("ExprBinary", 3, mk_atom("BiGe"), $1, $3); }
1408 | expr '|' expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitOr"), $1, $3); }
1409 | expr '^' expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitXor"), $1, $3); }
1410 | expr '&' expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitAnd"), $1, $3); }
1411 | expr SHL expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiShl"), $1, $3); }
1412 | expr SHR expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiShr"), $1, $3); }
1413 | expr '+' expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiAdd"), $1, $3); }
1414 | expr '-' expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiSub"), $1, $3); }
1415 | expr '*' expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiMul"), $1, $3); }
1416 | expr '/' expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiDiv"), $1, $3); }
1417 | expr '%' expr                                       { $$ = mk_node("ExprBinary", 3, mk_atom("BiRem"), $1, $3); }
1418 | expr DOTDOT                                         { $$ = mk_node("ExprRange", 2, $1, mk_none()); }
1419 | expr DOTDOT expr                                    { $$ = mk_node("ExprRange", 2, $1, $3); }
1420 |      DOTDOT expr                                    { $$ = mk_node("ExprRange", 2, mk_none(), $2); }
1421 |      DOTDOT                                         { $$ = mk_node("ExprRange", 2, mk_none(), mk_none()); }
1422 | expr AS ty                                          { $$ = mk_node("ExprCast", 2, $1, $3); }
1423 | BOX nonparen_expr                                   { $$ = mk_node("ExprBox", 1, $2); }
1424 | %prec BOXPLACE BOX '(' maybe_expr ')' expr          { $$ = mk_node("ExprBox", 2, $3, $5); }
1425 | expr_qualified_path
1426 | block_expr
1427 | block
1428 | nonblock_prefix_expr
1429 ;
1430
1431 nonparen_expr
1432 : lit                                                 { $$ = mk_node("ExprLit", 1, $1); }
1433 | %prec IDENT
1434   path_expr                                           { $$ = mk_node("ExprPath", 1, $1); }
1435 | SELF                                                { $$ = mk_node("ExprPath", 1, mk_node("ident", 1, mk_atom("self"))); }
1436 | macro_expr                                          { $$ = mk_node("ExprMac", 1, $1); }
1437 | path_expr '{' struct_expr_fields '}'                { $$ = mk_node("ExprStruct", 2, $1, $3); }
1438 | nonparen_expr '.' path_generic_args_with_colons     { $$ = mk_node("ExprField", 2, $1, $3); }
1439 | nonparen_expr '.' LIT_INTEGER                       { $$ = mk_node("ExprTupleIndex", 1, $1); }
1440 | nonparen_expr '[' maybe_expr ']'                    { $$ = mk_node("ExprIndex", 2, $1, $3); }
1441 | nonparen_expr '(' maybe_exprs ')'                   { $$ = mk_node("ExprCall", 2, $1, $3); }
1442 | '[' vec_expr ']'                                    { $$ = mk_node("ExprVec", 1, $2); }
1443 | CONTINUE                                            { $$ = mk_node("ExprAgain", 0); }
1444 | CONTINUE ident                                      { $$ = mk_node("ExprAgain", 1, $2); }
1445 | RETURN                                              { $$ = mk_node("ExprRet", 0); }
1446 | RETURN expr                                         { $$ = mk_node("ExprRet", 1, $2); }
1447 | BREAK                                               { $$ = mk_node("ExprBreak", 0); }
1448 | BREAK ident                                         { $$ = mk_node("ExprBreak", 1, $2); }
1449 | nonparen_expr LARROW nonparen_expr                  { $$ = mk_node("ExprInPlace", 2, $1, $3); }
1450 | nonparen_expr '=' nonparen_expr                     { $$ = mk_node("ExprAssign", 2, $1, $3); }
1451 | nonparen_expr SHLEQ nonparen_expr                   { $$ = mk_node("ExprAssignShl", 2, $1, $3); }
1452 | nonparen_expr SHREQ nonparen_expr                   { $$ = mk_node("ExprAssignShr", 2, $1, $3); }
1453 | nonparen_expr MINUSEQ nonparen_expr                 { $$ = mk_node("ExprAssignSub", 2, $1, $3); }
1454 | nonparen_expr ANDEQ nonparen_expr                   { $$ = mk_node("ExprAssignBitAnd", 2, $1, $3); }
1455 | nonparen_expr OREQ nonparen_expr                    { $$ = mk_node("ExprAssignBitOr", 2, $1, $3); }
1456 | nonparen_expr PLUSEQ nonparen_expr                  { $$ = mk_node("ExprAssignAdd", 2, $1, $3); }
1457 | nonparen_expr STAREQ nonparen_expr                  { $$ = mk_node("ExprAssignMul", 2, $1, $3); }
1458 | nonparen_expr SLASHEQ nonparen_expr                 { $$ = mk_node("ExprAssignDiv", 2, $1, $3); }
1459 | nonparen_expr CARETEQ nonparen_expr                 { $$ = mk_node("ExprAssignBitXor", 2, $1, $3); }
1460 | nonparen_expr PERCENTEQ nonparen_expr               { $$ = mk_node("ExprAssignRem", 2, $1, $3); }
1461 | nonparen_expr OROR nonparen_expr                    { $$ = mk_node("ExprBinary", 3, mk_atom("BiOr"), $1, $3); }
1462 | nonparen_expr ANDAND nonparen_expr                  { $$ = mk_node("ExprBinary", 3, mk_atom("BiAnd"), $1, $3); }
1463 | nonparen_expr EQEQ nonparen_expr                    { $$ = mk_node("ExprBinary", 3, mk_atom("BiEq"), $1, $3); }
1464 | nonparen_expr NE nonparen_expr                      { $$ = mk_node("ExprBinary", 3, mk_atom("BiNe"), $1, $3); }
1465 | nonparen_expr '<' nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiLt"), $1, $3); }
1466 | nonparen_expr '>' nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiGt"), $1, $3); }
1467 | nonparen_expr LE nonparen_expr                      { $$ = mk_node("ExprBinary", 3, mk_atom("BiLe"), $1, $3); }
1468 | nonparen_expr GE nonparen_expr                      { $$ = mk_node("ExprBinary", 3, mk_atom("BiGe"), $1, $3); }
1469 | nonparen_expr '|' nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitOr"), $1, $3); }
1470 | nonparen_expr '^' nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitXor"), $1, $3); }
1471 | nonparen_expr '&' nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitAnd"), $1, $3); }
1472 | nonparen_expr SHL nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiShl"), $1, $3); }
1473 | nonparen_expr SHR nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiShr"), $1, $3); }
1474 | nonparen_expr '+' nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiAdd"), $1, $3); }
1475 | nonparen_expr '-' nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiSub"), $1, $3); }
1476 | nonparen_expr '*' nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiMul"), $1, $3); }
1477 | nonparen_expr '/' nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiDiv"), $1, $3); }
1478 | nonparen_expr '%' nonparen_expr                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiRem"), $1, $3); }
1479 | nonparen_expr DOTDOT                                { $$ = mk_node("ExprRange", 2, $1, mk_none()); }
1480 | nonparen_expr DOTDOT nonparen_expr                  { $$ = mk_node("ExprRange", 2, $1, $3); }
1481 |               DOTDOT nonparen_expr                  { $$ = mk_node("ExprRange", 2, mk_none(), $2); }
1482 |               DOTDOT                                { $$ = mk_node("ExprRange", 2, mk_none(), mk_none()); }
1483 | nonparen_expr AS ty                                 { $$ = mk_node("ExprCast", 2, $1, $3); }
1484 | BOX nonparen_expr                                   { $$ = mk_node("ExprBox", 1, $2); }
1485 | %prec BOXPLACE BOX '(' maybe_expr ')' expr          { $$ = mk_node("ExprBox", 1, $3, $5); }
1486 | expr_qualified_path
1487 | block_expr
1488 | block
1489 | nonblock_prefix_expr
1490 ;
1491
1492 expr_nostruct
1493 : lit                                                 { $$ = mk_node("ExprLit", 1, $1); }
1494 | %prec IDENT
1495   path_expr                                           { $$ = mk_node("ExprPath", 1, $1); }
1496 | SELF                                                { $$ = mk_node("ExprPath", 1, mk_node("ident", 1, mk_atom("self"))); }
1497 | macro_expr                                          { $$ = mk_node("ExprMac", 1, $1); }
1498 | expr_nostruct '.' path_generic_args_with_colons     { $$ = mk_node("ExprField", 2, $1, $3); }
1499 | expr_nostruct '.' LIT_INTEGER                       { $$ = mk_node("ExprTupleIndex", 1, $1); }
1500 | expr_nostruct '[' maybe_expr ']'                    { $$ = mk_node("ExprIndex", 2, $1, $3); }
1501 | expr_nostruct '(' maybe_exprs ')'                   { $$ = mk_node("ExprCall", 2, $1, $3); }
1502 | '[' vec_expr ']'                                    { $$ = mk_node("ExprVec", 1, $2); }
1503 | '(' maybe_exprs ')'                                 { $$ = mk_node("ExprParen", 1, $2); }
1504 | CONTINUE                                            { $$ = mk_node("ExprAgain", 0); }
1505 | CONTINUE ident                                      { $$ = mk_node("ExprAgain", 1, $2); }
1506 | RETURN                                              { $$ = mk_node("ExprRet", 0); }
1507 | RETURN expr                                         { $$ = mk_node("ExprRet", 1, $2); }
1508 | BREAK                                               { $$ = mk_node("ExprBreak", 0); }
1509 | BREAK ident                                         { $$ = mk_node("ExprBreak", 1, $2); }
1510 | expr_nostruct LARROW expr_nostruct                  { $$ = mk_node("ExprInPlace", 2, $1, $3); }
1511 | expr_nostruct '=' expr_nostruct                     { $$ = mk_node("ExprAssign", 2, $1, $3); }
1512 | expr_nostruct SHLEQ expr_nostruct                   { $$ = mk_node("ExprAssignShl", 2, $1, $3); }
1513 | expr_nostruct SHREQ expr_nostruct                   { $$ = mk_node("ExprAssignShr", 2, $1, $3); }
1514 | expr_nostruct MINUSEQ expr_nostruct                 { $$ = mk_node("ExprAssignSub", 2, $1, $3); }
1515 | expr_nostruct ANDEQ expr_nostruct                   { $$ = mk_node("ExprAssignBitAnd", 2, $1, $3); }
1516 | expr_nostruct OREQ expr_nostruct                    { $$ = mk_node("ExprAssignBitOr", 2, $1, $3); }
1517 | expr_nostruct PLUSEQ expr_nostruct                  { $$ = mk_node("ExprAssignAdd", 2, $1, $3); }
1518 | expr_nostruct STAREQ expr_nostruct                  { $$ = mk_node("ExprAssignMul", 2, $1, $3); }
1519 | expr_nostruct SLASHEQ expr_nostruct                 { $$ = mk_node("ExprAssignDiv", 2, $1, $3); }
1520 | expr_nostruct CARETEQ expr_nostruct                 { $$ = mk_node("ExprAssignBitXor", 2, $1, $3); }
1521 | expr_nostruct PERCENTEQ expr_nostruct               { $$ = mk_node("ExprAssignRem", 2, $1, $3); }
1522 | expr_nostruct OROR expr_nostruct                    { $$ = mk_node("ExprBinary", 3, mk_atom("BiOr"), $1, $3); }
1523 | expr_nostruct ANDAND expr_nostruct                  { $$ = mk_node("ExprBinary", 3, mk_atom("BiAnd"), $1, $3); }
1524 | expr_nostruct EQEQ expr_nostruct                    { $$ = mk_node("ExprBinary", 3, mk_atom("BiEq"), $1, $3); }
1525 | expr_nostruct NE expr_nostruct                      { $$ = mk_node("ExprBinary", 3, mk_atom("BiNe"), $1, $3); }
1526 | expr_nostruct '<' expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiLt"), $1, $3); }
1527 | expr_nostruct '>' expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiGt"), $1, $3); }
1528 | expr_nostruct LE expr_nostruct                      { $$ = mk_node("ExprBinary", 3, mk_atom("BiLe"), $1, $3); }
1529 | expr_nostruct GE expr_nostruct                      { $$ = mk_node("ExprBinary", 3, mk_atom("BiGe"), $1, $3); }
1530 | expr_nostruct '|' expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitOr"), $1, $3); }
1531 | expr_nostruct '^' expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitXor"), $1, $3); }
1532 | expr_nostruct '&' expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitAnd"), $1, $3); }
1533 | expr_nostruct SHL expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiShl"), $1, $3); }
1534 | expr_nostruct SHR expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiShr"), $1, $3); }
1535 | expr_nostruct '+' expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiAdd"), $1, $3); }
1536 | expr_nostruct '-' expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiSub"), $1, $3); }
1537 | expr_nostruct '*' expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiMul"), $1, $3); }
1538 | expr_nostruct '/' expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiDiv"), $1, $3); }
1539 | expr_nostruct '%' expr_nostruct                     { $$ = mk_node("ExprBinary", 3, mk_atom("BiRem"), $1, $3); }
1540 | expr_nostruct DOTDOT               %prec RANGE      { $$ = mk_node("ExprRange", 2, $1, mk_none()); }
1541 | expr_nostruct DOTDOT expr_nostruct                  { $$ = mk_node("ExprRange", 2, $1, $3); }
1542 |               DOTDOT expr_nostruct                  { $$ = mk_node("ExprRange", 2, mk_none(), $2); }
1543 |               DOTDOT                                { $$ = mk_node("ExprRange", 2, mk_none(), mk_none()); }
1544 | expr_nostruct AS ty                                 { $$ = mk_node("ExprCast", 2, $1, $3); }
1545 | BOX nonparen_expr                                   { $$ = mk_node("ExprBox", 1, $2); }
1546 | %prec BOXPLACE BOX '(' maybe_expr ')' expr_nostruct { $$ = mk_node("ExprBox", 1, $3, $5); }
1547 | expr_qualified_path
1548 | block_expr
1549 | block
1550 | nonblock_prefix_expr_nostruct
1551 ;
1552
1553 nonblock_prefix_expr_nostruct
1554 : '-' expr_nostruct                         { $$ = mk_node("ExprUnary", 2, mk_atom("UnNeg"), $2); }
1555 | '!' expr_nostruct                         { $$ = mk_node("ExprUnary", 2, mk_atom("UnNot"), $2); }
1556 | '*' expr_nostruct                         { $$ = mk_node("ExprUnary", 2, mk_atom("UnDeref"), $2); }
1557 | '&' maybe_mut expr_nostruct               { $$ = mk_node("ExprAddrOf", 2, $2, $3); }
1558 | ANDAND maybe_mut expr_nostruct            { $$ = mk_node("ExprAddrOf", 1, mk_node("ExprAddrOf", 2, $2, $3)); }
1559 | lambda_expr_nostruct
1560 | MOVE lambda_expr_nostruct                 { $$ = $2; }
1561 | proc_expr_nostruct
1562 ;
1563
1564 nonblock_prefix_expr
1565 : '-' expr                         { $$ = mk_node("ExprUnary", 2, mk_atom("UnNeg"), $2); }
1566 | '!' expr                         { $$ = mk_node("ExprUnary", 2, mk_atom("UnNot"), $2); }
1567 | '*' expr                         { $$ = mk_node("ExprUnary", 2, mk_atom("UnDeref"), $2); }
1568 | '&' maybe_mut expr               { $$ = mk_node("ExprAddrOf", 2, $2, $3); }
1569 | ANDAND maybe_mut expr            { $$ = mk_node("ExprAddrOf", 1, mk_node("ExprAddrOf", 2, $2, $3)); }
1570 | lambda_expr
1571 | MOVE lambda_expr                 { $$ = $2; }
1572 | proc_expr
1573 ;
1574
1575 expr_qualified_path
1576 : '<' ty_sum maybe_as_trait_ref '>' MOD_SEP ident maybe_qpath_params
1577 {
1578   $$ = mk_node("ExprQualifiedPath", 4, $2, $3, $6, $7);
1579 }
1580 | SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident maybe_as_trait_ref '>' MOD_SEP ident
1581 {
1582   $$ = mk_node("ExprQualifiedPath", 3, mk_node("ExprQualifiedPath", 3, $2, $3, $6), $7, $10);
1583 }
1584 | SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident generic_args maybe_as_trait_ref '>' MOD_SEP ident
1585 {
1586   $$ = mk_node("ExprQualifiedPath", 3, mk_node("ExprQualifiedPath", 4, $2, $3, $6, $7), $8, $11);
1587 }
1588 | SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident maybe_as_trait_ref '>' MOD_SEP ident generic_args
1589 {
1590   $$ = mk_node("ExprQualifiedPath", 4, mk_node("ExprQualifiedPath", 3, $2, $3, $6), $7, $10, $11);
1591 }
1592 | SHL ty_sum maybe_as_trait_ref '>' MOD_SEP ident generic_args maybe_as_trait_ref '>' MOD_SEP ident generic_args
1593 {
1594   $$ = mk_node("ExprQualifiedPath", 4, mk_node("ExprQualifiedPath", 4, $2, $3, $6, $7), $8, $11, $12);
1595 }
1596
1597 maybe_qpath_params
1598 : MOD_SEP generic_args { $$ = $2; }
1599 | %empty               { $$ = mk_none(); }
1600 ;
1601
1602 maybe_as_trait_ref
1603 : AS trait_ref { $$ = $2; }
1604 | %empty       { $$ = mk_none(); }
1605 ;
1606
1607 lambda_expr
1608 : %prec LAMBDA
1609   OROR ret_ty expr                                        { $$ = mk_node("ExprFnBlock", 3, mk_none(), $2, $3); }
1610 | %prec LAMBDA
1611   '|' maybe_unboxed_closure_kind '|' ret_ty expr          { $$ = mk_node("ExprFnBlock", 3, mk_none(), $4, $5); }
1612 | %prec LAMBDA
1613   '|' inferrable_params '|' ret_ty expr                   { $$ = mk_node("ExprFnBlock", 3, $2, $4, $5); }
1614 | %prec LAMBDA
1615   '|' '&' maybe_mut ':' inferrable_params '|' ret_ty expr { $$ = mk_node("ExprFnBlock", 3, $5, $7, $8); }
1616 | %prec LAMBDA
1617   '|' ':' inferrable_params '|' ret_ty expr               { $$ = mk_node("ExprFnBlock", 3, $3, $5, $6); }
1618 ;
1619
1620 lambda_expr_nostruct
1621 : %prec LAMBDA
1622   OROR expr_nostruct                                        { $$ = mk_node("ExprFnBlock", 2, mk_none(), $2); }
1623 | %prec LAMBDA
1624   '|' maybe_unboxed_closure_kind '|'  expr_nostruct         { $$ = mk_node("ExprFnBlock", 2, mk_none(), $4); }
1625 | %prec LAMBDA
1626   '|' inferrable_params '|' expr_nostruct                   { $$ = mk_node("ExprFnBlock", 2, $2, $4); }
1627 | %prec LAMBDA
1628   '|' '&' maybe_mut ':' inferrable_params '|' expr_nostruct { $$ = mk_node("ExprFnBlock", 2, $5, $7); }
1629 | %prec LAMBDA
1630   '|' ':' inferrable_params '|' expr_nostruct               { $$ = mk_node("ExprFnBlock", 2, $3, $5); }
1631
1632 ;
1633
1634 proc_expr
1635 : %prec LAMBDA
1636   PROC '(' ')' expr                         { $$ = mk_node("ExprProc", 2, mk_none(), $4); }
1637 | %prec LAMBDA
1638   PROC '(' inferrable_params ')' expr       { $$ = mk_node("ExprProc", 2, $3, $5); }
1639 ;
1640
1641 proc_expr_nostruct
1642 : %prec LAMBDA
1643   PROC '(' ')' expr_nostruct                     { $$ = mk_node("ExprProc", 2, mk_none(), $4); }
1644 | %prec LAMBDA
1645   PROC '(' inferrable_params ')' expr_nostruct   { $$ = mk_node("ExprProc", 2, $3, $5); }
1646 ;
1647
1648 vec_expr
1649 : maybe_exprs
1650 | exprs ';' expr { $$ = mk_node("VecRepeat", 2, $1, $3); }
1651 ;
1652
1653 struct_expr_fields
1654 : field_inits
1655 | field_inits ','
1656 | maybe_field_inits default_field_init { $$ = ext_node($1, 1, $2); }
1657 ;
1658
1659 maybe_field_inits
1660 : field_inits
1661 | field_inits ','
1662 | %empty { $$ = mk_none(); }
1663 ;
1664
1665 field_inits
1666 : field_init                 { $$ = mk_node("FieldInits", 1, $1); }
1667 | field_inits ',' field_init { $$ = ext_node($1, 1, $3); }
1668 ;
1669
1670 field_init
1671 : ident ':' expr   { $$ = mk_node("FieldInit", 2, $1, $3); }
1672 ;
1673
1674 default_field_init
1675 : DOTDOT expr   { $$ = mk_node("DefaultFieldInit", 1, $2); }
1676 ;
1677
1678 block_expr
1679 : expr_match
1680 | expr_if
1681 | expr_if_let
1682 | expr_while
1683 | expr_while_let
1684 | expr_loop
1685 | expr_for
1686 | UNSAFE block                                           { $$ = mk_node("UnsafeBlock", 1, $2); }
1687 | path_expr '!' maybe_ident braces_delimited_token_trees { $$ = mk_node("Macro", 3, $1, $3, $4); }
1688 ;
1689
1690 full_block_expr
1691 : block_expr
1692 | full_block_expr '.' path_generic_args_with_colons %prec IDENT         { $$ = mk_node("ExprField", 2, $1, $3); }
1693 | full_block_expr '.' path_generic_args_with_colons '[' maybe_expr ']'  { $$ = mk_node("ExprIndex", 3, $1, $3, $5); }
1694 | full_block_expr '.' path_generic_args_with_colons '(' maybe_exprs ')' { $$ = mk_node("ExprCall", 3, $1, $3, $5); }
1695 | full_block_expr '.' LIT_INTEGER                                       { $$ = mk_node("ExprTupleIndex", 1, $1); }
1696 ;
1697
1698 expr_match
1699 : MATCH expr_nostruct '{' '}'                                     { $$ = mk_node("ExprMatch", 1, $2); }
1700 | MATCH expr_nostruct '{' match_clauses                       '}' { $$ = mk_node("ExprMatch", 2, $2, $4); }
1701 | MATCH expr_nostruct '{' match_clauses nonblock_match_clause '}' { $$ = mk_node("ExprMatch", 2, $2, ext_node($4, 1, $5)); }
1702 | MATCH expr_nostruct '{'               nonblock_match_clause '}' { $$ = mk_node("ExprMatch", 2, $2, mk_node("Arms", 1, $4)); }
1703 ;
1704
1705 match_clauses
1706 : match_clause               { $$ = mk_node("Arms", 1, $1); }
1707 | match_clauses match_clause { $$ = ext_node($1, 1, $2); }
1708 ;
1709
1710 match_clause
1711 : nonblock_match_clause ','
1712 | block_match_clause
1713 | block_match_clause ','
1714 ;
1715
1716 nonblock_match_clause
1717 : maybe_outer_attrs pats_or maybe_guard FAT_ARROW nonblock_expr   { $$ = mk_node("Arm", 4, $1, $2, $3, $5); }
1718 | maybe_outer_attrs pats_or maybe_guard FAT_ARROW full_block_expr { $$ = mk_node("Arm", 4, $1, $2, $3, $5); }
1719 ;
1720
1721 block_match_clause
1722 : maybe_outer_attrs pats_or maybe_guard FAT_ARROW block { $$ = mk_node("Arm", 4, $1, $2, $3, $5); }
1723 ;
1724
1725 maybe_guard
1726 : IF expr_nostruct           { $$ = $2; }
1727 | %empty                     { $$ = mk_none(); }
1728 ;
1729
1730 expr_if
1731 : IF expr_nostruct block                              { $$ = mk_node("ExprIf", 2, $2, $3); }
1732 | IF expr_nostruct block ELSE block_or_if             { $$ = mk_node("ExprIf", 3, $2, $3, $5); }
1733 ;
1734
1735 expr_if_let
1736 : IF LET pat '=' expr_nostruct block                  { $$ = mk_node("ExprIfLet", 3, $3, $5, $6); }
1737 | IF LET pat '=' expr_nostruct block ELSE block_or_if { $$ = mk_node("ExprIfLet", 4, $3, $5, $6, $8); }
1738 ;
1739
1740 block_or_if
1741 : block
1742 | expr_if
1743 | expr_if_let
1744 ;
1745
1746 expr_while
1747 : maybe_label WHILE expr_nostruct block               { $$ = mk_node("ExprWhile", 3, $1, $3, $4); }
1748 ;
1749
1750 expr_while_let
1751 : maybe_label WHILE LET pat '=' expr_nostruct block   { $$ = mk_node("ExprWhileLet", 4, $1, $4, $6, $7); }
1752 ;
1753
1754 expr_loop
1755 : maybe_label LOOP block                              { $$ = mk_node("ExprLoop", 2, $1, $3); }
1756 ;
1757
1758 expr_for
1759 : maybe_label FOR pat IN expr_nostruct block          { $$ = mk_node("ExprForLoop", 4, $1, $3, $5, $6); }
1760 ;
1761
1762 maybe_label
1763 : lifetime ':'
1764 | %empty { $$ = mk_none(); }
1765 ;
1766
1767 let
1768 : LET pat maybe_ty_ascription maybe_init_expr ';' { $$ = mk_node("DeclLocal", 3, $2, $3, $4); }
1769 ;
1770
1771 ////////////////////////////////////////////////////////////////////////
1772 // Part 5: Macros and misc. rules
1773 ////////////////////////////////////////////////////////////////////////
1774
1775 lit
1776 : LIT_BYTE                   { $$ = mk_node("LitByte", 1, mk_atom(yytext)); }
1777 | LIT_CHAR                   { $$ = mk_node("LitChar", 1, mk_atom(yytext)); }
1778 | LIT_INTEGER                { $$ = mk_node("LitInteger", 1, mk_atom(yytext)); }
1779 | LIT_FLOAT                  { $$ = mk_node("LitFloat", 1, mk_atom(yytext)); }
1780 | TRUE                       { $$ = mk_node("LitBool", 1, mk_atom(yytext)); }
1781 | FALSE                      { $$ = mk_node("LitBool", 1, mk_atom(yytext)); }
1782 | str
1783 ;
1784
1785 str
1786 : LIT_STR                    { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("CookedStr")); }
1787 | LIT_STR_RAW                { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("RawStr")); }
1788 | LIT_BYTE_STR                 { $$ = mk_node("LitByteStr", 1, mk_atom(yytext), mk_atom("ByteStr")); }
1789 | LIT_BYTE_STR_RAW             { $$ = mk_node("LitByteStr", 1, mk_atom(yytext), mk_atom("RawByteStr")); }
1790 ;
1791
1792 maybe_ident
1793 : %empty { $$ = mk_none(); }
1794 | ident
1795 ;
1796
1797 ident
1798 : IDENT                      { $$ = mk_node("ident", 1, mk_atom(yytext)); }
1799 ;
1800
1801 unpaired_token
1802 : SHL                        { $$ = mk_atom(yytext); }
1803 | SHR                        { $$ = mk_atom(yytext); }
1804 | LE                         { $$ = mk_atom(yytext); }
1805 | EQEQ                       { $$ = mk_atom(yytext); }
1806 | NE                         { $$ = mk_atom(yytext); }
1807 | GE                         { $$ = mk_atom(yytext); }
1808 | ANDAND                     { $$ = mk_atom(yytext); }
1809 | OROR                       { $$ = mk_atom(yytext); }
1810 | LARROW                     { $$ = mk_atom(yytext); }
1811 | SHLEQ                      { $$ = mk_atom(yytext); }
1812 | SHREQ                      { $$ = mk_atom(yytext); }
1813 | MINUSEQ                    { $$ = mk_atom(yytext); }
1814 | ANDEQ                      { $$ = mk_atom(yytext); }
1815 | OREQ                       { $$ = mk_atom(yytext); }
1816 | PLUSEQ                     { $$ = mk_atom(yytext); }
1817 | STAREQ                     { $$ = mk_atom(yytext); }
1818 | SLASHEQ                    { $$ = mk_atom(yytext); }
1819 | CARETEQ                    { $$ = mk_atom(yytext); }
1820 | PERCENTEQ                  { $$ = mk_atom(yytext); }
1821 | DOTDOT                     { $$ = mk_atom(yytext); }
1822 | DOTDOTDOT                  { $$ = mk_atom(yytext); }
1823 | MOD_SEP                    { $$ = mk_atom(yytext); }
1824 | RARROW                     { $$ = mk_atom(yytext); }
1825 | FAT_ARROW                  { $$ = mk_atom(yytext); }
1826 | LIT_BYTE                   { $$ = mk_atom(yytext); }
1827 | LIT_CHAR                   { $$ = mk_atom(yytext); }
1828 | LIT_INTEGER                { $$ = mk_atom(yytext); }
1829 | LIT_FLOAT                  { $$ = mk_atom(yytext); }
1830 | LIT_STR                    { $$ = mk_atom(yytext); }
1831 | LIT_STR_RAW                { $$ = mk_atom(yytext); }
1832 | LIT_BYTE_STR               { $$ = mk_atom(yytext); }
1833 | LIT_BYTE_STR_RAW           { $$ = mk_atom(yytext); }
1834 | IDENT                      { $$ = mk_atom(yytext); }
1835 | UNDERSCORE                 { $$ = mk_atom(yytext); }
1836 | LIFETIME                   { $$ = mk_atom(yytext); }
1837 | SELF                       { $$ = mk_atom(yytext); }
1838 | STATIC                     { $$ = mk_atom(yytext); }
1839 | AS                         { $$ = mk_atom(yytext); }
1840 | BREAK                      { $$ = mk_atom(yytext); }
1841 | CRATE                      { $$ = mk_atom(yytext); }
1842 | ELSE                       { $$ = mk_atom(yytext); }
1843 | ENUM                       { $$ = mk_atom(yytext); }
1844 | EXTERN                     { $$ = mk_atom(yytext); }
1845 | FALSE                      { $$ = mk_atom(yytext); }
1846 | FN                         { $$ = mk_atom(yytext); }
1847 | FOR                        { $$ = mk_atom(yytext); }
1848 | IF                         { $$ = mk_atom(yytext); }
1849 | IMPL                       { $$ = mk_atom(yytext); }
1850 | IN                         { $$ = mk_atom(yytext); }
1851 | LET                        { $$ = mk_atom(yytext); }
1852 | LOOP                       { $$ = mk_atom(yytext); }
1853 | MATCH                      { $$ = mk_atom(yytext); }
1854 | MOD                        { $$ = mk_atom(yytext); }
1855 | MOVE                       { $$ = mk_atom(yytext); }
1856 | MUT                        { $$ = mk_atom(yytext); }
1857 | PRIV                       { $$ = mk_atom(yytext); }
1858 | PUB                        { $$ = mk_atom(yytext); }
1859 | REF                        { $$ = mk_atom(yytext); }
1860 | RETURN                     { $$ = mk_atom(yytext); }
1861 | STRUCT                     { $$ = mk_atom(yytext); }
1862 | TRUE                       { $$ = mk_atom(yytext); }
1863 | TRAIT                      { $$ = mk_atom(yytext); }
1864 | TYPE                       { $$ = mk_atom(yytext); }
1865 | UNSAFE                     { $$ = mk_atom(yytext); }
1866 | USE                        { $$ = mk_atom(yytext); }
1867 | WHILE                      { $$ = mk_atom(yytext); }
1868 | CONTINUE                   { $$ = mk_atom(yytext); }
1869 | PROC                       { $$ = mk_atom(yytext); }
1870 | BOX                        { $$ = mk_atom(yytext); }
1871 | CONST                      { $$ = mk_atom(yytext); }
1872 | WHERE                      { $$ = mk_atom(yytext); }
1873 | TYPEOF                     { $$ = mk_atom(yytext); }
1874 | INNER_DOC_COMMENT          { $$ = mk_atom(yytext); }
1875 | OUTER_DOC_COMMENT          { $$ = mk_atom(yytext); }
1876 | SHEBANG                    { $$ = mk_atom(yytext); }
1877 | STATIC_LIFETIME            { $$ = mk_atom(yytext); }
1878 | ';'                        { $$ = mk_atom(yytext); }
1879 | ','                        { $$ = mk_atom(yytext); }
1880 | '.'                        { $$ = mk_atom(yytext); }
1881 | '@'                        { $$ = mk_atom(yytext); }
1882 | '#'                        { $$ = mk_atom(yytext); }
1883 | '~'                        { $$ = mk_atom(yytext); }
1884 | ':'                        { $$ = mk_atom(yytext); }
1885 | '$'                        { $$ = mk_atom(yytext); }
1886 | '='                        { $$ = mk_atom(yytext); }
1887 | '?'                        { $$ = mk_atom(yytext); }
1888 | '!'                        { $$ = mk_atom(yytext); }
1889 | '<'                        { $$ = mk_atom(yytext); }
1890 | '>'                        { $$ = mk_atom(yytext); }
1891 | '-'                        { $$ = mk_atom(yytext); }
1892 | '&'                        { $$ = mk_atom(yytext); }
1893 | '|'                        { $$ = mk_atom(yytext); }
1894 | '+'                        { $$ = mk_atom(yytext); }
1895 | '*'                        { $$ = mk_atom(yytext); }
1896 | '/'                        { $$ = mk_atom(yytext); }
1897 | '^'                        { $$ = mk_atom(yytext); }
1898 | '%'                        { $$ = mk_atom(yytext); }
1899 ;
1900
1901 token_trees
1902 : %empty                     { $$ = mk_node("TokenTrees", 0); }
1903 | token_trees token_tree     { $$ = ext_node($1, 1, $2); }
1904 ;
1905
1906 token_tree
1907 : delimited_token_trees
1908 | unpaired_token         { $$ = mk_node("TTTok", 1, $1); }
1909 ;
1910
1911 delimited_token_trees
1912 : parens_delimited_token_trees
1913 | braces_delimited_token_trees
1914 | brackets_delimited_token_trees
1915 ;
1916
1917 parens_delimited_token_trees
1918 : '(' token_trees ')'
1919 {
1920   $$ = mk_node("TTDelim", 3,
1921                mk_node("TTTok", 1, mk_atom("(")),
1922                $2,
1923                mk_node("TTTok", 1, mk_atom(")")));
1924 }
1925 ;
1926
1927 braces_delimited_token_trees
1928 : '{' token_trees '}'
1929 {
1930   $$ = mk_node("TTDelim", 3,
1931                mk_node("TTTok", 1, mk_atom("{")),
1932                $2,
1933                mk_node("TTTok", 1, mk_atom("}")));
1934 }
1935 ;
1936
1937 brackets_delimited_token_trees
1938 : '[' token_trees ']'
1939 {
1940   $$ = mk_node("TTDelim", 3,
1941                mk_node("TTTok", 1, mk_atom("[")),
1942                $2,
1943                mk_node("TTTok", 1, mk_atom("]")));
1944 }
1945 ;