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