Grammar Diff (vN vs vN+1)


vN
vN+1
t1<<< =========================================================t1<<< =========================================================
2   Vitte — Complete Core Grammar2   Vitte — Complete Core Grammar
3   systems + application + kernel + compiler surface3   systems + application + kernel + compiler surface
4   canonical blocks: { }4   canonical blocks: { }
5   canonical syntax source for parser/docs/tests5   canonical syntax source for parser/docs/tests
6   low-level capable6   low-level capable
7   compiler-capable7   compiler-capable
8   no aliases, reduced duplicates8   no aliases, reduced duplicates
9   ========================================================= >>>9   ========================================================= >>>
1010
11program ::= WS? { toplevel WS? } EOF ;11program ::= WS? { toplevel WS? } EOF ;
1212
13<<< ================= Top-level ================= >>>13<<< ================= Top-level ================= >>>
1414
15toplevel ::= inner_attribute15toplevel ::= inner_attribute
16          | space_decl16          | space_decl
17          | use_decl17          | use_decl
18          | export_decl18          | export_decl
19          | const_decl19          | const_decl
20          | static_decl20          | static_decl
21          | global_decl21          | global_decl
22          | type_alias_decl22          | type_alias_decl
23          | opaque_type_decl23          | opaque_type_decl
24          | extern_type_decl24          | extern_type_decl
25          | form_decl25          | form_decl
26          | class_decl26          | class_decl
27          | union_decl27          | union_decl
28          | bits_decl28          | bits_decl
29          | pick_decl29          | pick_decl
30          | flags_decl30          | flags_decl
31          | trait_decl31          | trait_decl
32          | impl_decl32          | impl_decl
33          | extern_block33          | extern_block
34          | proc_decl34          | proc_decl
35          | intrinsic_decl35          | intrinsic_decl
36          | compiler_decl36          | compiler_decl
37          | query_decl37          | query_decl
38          | pass_decl38          | pass_decl
39          | backend_decl39          | backend_decl
40          | diagnostic_decl40          | diagnostic_decl
41          | macro_decl41          | macro_decl
42          | comptime_decl42          | comptime_decl
43          | static_assert_decl43          | static_assert_decl
44          | test_decl44          | test_decl
45          | bench_decl45          | bench_decl
46          | entry_decl46          | entry_decl
47          ;47          ;
4848
49space_decl ::= "space" WS1 module_path ;49space_decl ::= "space" WS1 module_path ;
5050
51use_decl ::= "use" WS1 package_path [ use_group | use_glob ] [ WS1 "as" WS1 ident ] ;51use_decl ::= "use" WS1 package_path [ use_group | use_glob ] [ WS1 "as" WS1 ident ] ;
52use_glob ::= "." "*" ;52use_glob ::= "." "*" ;
53use_group ::= "." "{" WS? ( "*" | import_items [ WS? "," WS? "*" ]? ) WS? "}" ;53use_group ::= "." "{" WS? ( "*" | import_items [ WS? "," WS? "*" ]? ) WS? "}" ;
5454
55import_items ::= import_item { WS? "," WS? import_item } [ WS? "," ] ;55import_items ::= import_item { WS? "," WS? import_item } [ WS? "," ] ;
56import_item ::= ident [ WS1 "as" WS1 ident ] ;56import_item ::= ident [ WS1 "as" WS1 ident ] ;
5757
58export_decl ::= "export" WS1 ( "*" | ident_list | "{" WS? ident_list WS? "}" ) ;58export_decl ::= "export" WS1 ( "*" | ident_list | "{" WS? ident_list WS? "}" ) ;
5959
60const_decl ::= { attr_prefix WS? } "const" WS1 ident [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;60const_decl ::= { attr_prefix WS? } "const" WS1 ident [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;
61static_decl ::= { attr_prefix WS? } "static" WS1 ident [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;61static_decl ::= { attr_prefix WS? } "static" WS1 ident [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;
62global_decl ::= { attr_prefix WS? } "global" WS1 ident [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;62global_decl ::= { attr_prefix WS? } "global" WS1 ident [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;
6363
64type_alias_decl ::= { attr_prefix WS? } "type" WS1 ident [ generic_params ] WS? "=" WS? type_expr ;64type_alias_decl ::= { attr_prefix WS? } "type" WS1 ident [ generic_params ] WS? "=" WS? type_expr ;
65opaque_type_decl ::= { attr_prefix WS? } "opaque" WS1 "type" WS1 ident [ generic_params ] [ WS? "=" WS? type_expr ] ;65opaque_type_decl ::= { attr_prefix WS? } "opaque" WS1 "type" WS1 ident [ generic_params ] [ WS? "=" WS? type_expr ] ;
66extern_type_decl ::= { attr_prefix WS? } "extern" WS1 "type" WS1 ident [ generic_params ] [ WS? ";" ] ;66extern_type_decl ::= { attr_prefix WS? } "extern" WS1 "type" WS1 ident [ generic_params ] [ WS? ";" ] ;
6767
68form_decl ::= { attr_prefix WS? } "form" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS? form_items? WS? "68form_decl ::= { attr_prefix WS? } "form" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS? form_items? WS? "
>}" ;>}" ;
69class_decl ::= { attr_prefix WS? } "class" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS? class_items? WS69class_decl ::= { attr_prefix WS? } "class" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS? class_items? WS
>? "}" ;>? "}" ;
70union_decl ::= { attr_prefix WS? } "union" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS? field_list? WS?70union_decl ::= { attr_prefix WS? } "union" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS? field_list? WS?
> "}" ;> "}" ;
7171
72form_items ::= form_item { WS? ","? WS? form_item } [ WS? "," ] ;72form_items ::= form_item { WS? ","? WS? form_item } [ WS? "," ] ;
73form_item ::= field_item | const_decl | type_alias_decl | proc_decl ;73form_item ::= field_item | const_decl | type_alias_decl | proc_decl ;
7474
75class_items ::= class_item { WS? ","? WS? class_item } [ WS? "," ] ;75class_items ::= class_item { WS? ","? WS? class_item } [ WS? "," ] ;
76class_item ::= field_item | const_decl | type_alias_decl | proc_decl ;76class_item ::= field_item | const_decl | type_alias_decl | proc_decl ;
7777
78field_list ::= field_item { WS? "," WS? field_item } [ WS? "," ] ;78field_list ::= field_item { WS? "," WS? field_item } [ WS? "," ] ;
79field_item ::= { attr_prefix WS? } [ visibility WS1 ] ident WS? ":" WS? type_expr [ WS? "=" WS? expr ] ;79field_item ::= { attr_prefix WS? } [ visibility WS1 ] ident WS? ":" WS? type_expr [ WS? "=" WS? expr ] ;
8080
81bits_decl ::= { attr_prefix WS? } "bits" WS1 ident [ WS? ":" WS? type_expr ] WS? "{" WS? bitfield_list? WS? "}" ;81bits_decl ::= { attr_prefix WS? } "bits" WS1 ident [ WS? ":" WS? type_expr ] WS? "{" WS? bitfield_list? WS? "}" ;
82bitfield_list ::= bitfield_item { WS? "," WS? bitfield_item } [ WS? "," ] ;82bitfield_list ::= bitfield_item { WS? "," WS? bitfield_item } [ WS? "," ] ;
83bitfield_item ::= ident WS? ":" WS? expr WS? ".." WS? expr ;83bitfield_item ::= ident WS? ":" WS? expr WS? ".." WS? expr ;
8484
85pick_decl ::= { attr_prefix WS? } "pick" WS1 ident [ generic_params ] [ WS? ":" WS? type_expr ] [ WS? where_clause ] WS?85pick_decl ::= { attr_prefix WS? } "pick" WS1 ident [ generic_params ] [ WS? ":" WS? type_expr ] [ WS? where_clause ] WS?
> "{" WS? case_list? WS? "}" ;> "{" WS? case_list? WS? "}" ;
86case_list ::= case_item { WS? "," WS? case_item } [ WS? "," ] ;86case_list ::= case_item { WS? "," WS? case_item } [ WS? "," ] ;
87case_item ::= [ "case" WS1 ] ident [ "(" WS? case_payload? WS? ")" ] [ WS? "=" WS? expr ] ;87case_item ::= [ "case" WS1 ] ident [ "(" WS? case_payload? WS? ")" ] [ WS? "=" WS? expr ] ;
88case_payload ::= case_field { WS? "," WS? case_field } [ WS? "," ] ;88case_payload ::= case_field { WS? "," WS? case_field } [ WS? "," ] ;
89case_field ::= ident WS? ":" WS? type_expr | type_expr ;89case_field ::= ident WS? ":" WS? type_expr | type_expr ;
9090
91flags_decl ::= { attr_prefix WS? } "flags" WS1 ident [ WS? ":" WS? type_expr ] WS? "{" WS? flag_list? WS? "}" ;91flags_decl ::= { attr_prefix WS? } "flags" WS1 ident [ WS? ":" WS? type_expr ] WS? "{" WS? flag_list? WS? "}" ;
92flag_list ::= flag_item { WS? "," WS? flag_item } [ WS? "," ] ;92flag_list ::= flag_item { WS? "," WS? flag_item } [ WS? "," ] ;
93flag_item ::= ident [ WS? "=" WS? expr ] ;93flag_item ::= ident [ WS? "=" WS? expr ] ;
9494
95trait_decl ::= { attr_prefix WS? } [ "unsafe" WS1 ] "trait" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS95trait_decl ::= { attr_prefix WS? } [ "unsafe" WS1 ] "trait" WS1 ident [ generic_params ] [ WS? where_clause ] WS? "{" WS
>? trait_item* WS? "}" ;>? trait_item* WS? "}" ;
96trait_item ::= proc_signature | const_decl | associated_type_decl ;96trait_item ::= proc_signature | const_decl | associated_type_decl ;
9797
98associated_type_decl ::= "type" WS1 ident [ WS? ":" WS? trait_bound ] [ WS? "=" WS? type_expr ] ;98associated_type_decl ::= "type" WS1 ident [ WS? ":" WS? trait_bound ] [ WS? "=" WS? type_expr ] ;
9999
100impl_decl ::= { attr_prefix WS? } [ "unsafe" WS1 ] "impl" WS1 impl_head [ WS? where_clause ] WS? "{" WS? impl_item* WS? 100impl_decl ::= { attr_prefix WS? } [ "unsafe" WS1 ] "impl" WS1 impl_head [ WS? where_clause ] WS? "{" WS? impl_item* WS? 
>"}" ;>"}" ;
101impl_head ::= type_expr | type_expr WS1 "for" WS1 type_expr ;101impl_head ::= type_expr | type_expr WS1 "for" WS1 type_expr ;
102impl_item ::= const_decl | type_alias_decl | associated_type_decl | proc_decl ;102impl_item ::= const_decl | type_alias_decl | associated_type_decl | proc_decl ;
103103
104proc_signature ::= { attr_prefix WS? } "proc" WS1 ident [ generic_params ]104proc_signature ::= { attr_prefix WS? } "proc" WS1 ident [ generic_params ]
105                   "(" WS? param_list? WS? ")"105                   "(" WS? param_list? WS? ")"
106                   [ WS? "->" WS? type_expr ]106                   [ WS? "->" WS? type_expr ]
107                   WS? proc_suffix*107                   WS? proc_suffix*
108                   WS? ";"108                   WS? ";"
109                   ;109                   ;
110110
111proc_decl ::= { attr_prefix WS? } [ visibility WS1 ] proc_modifier* [ extern_clause WS1 ] "proc" WS1 proc_name [ generic111proc_decl ::= { attr_prefix WS? } [ visibility WS1 ] proc_modifier* [ extern_clause WS1 ] "proc" WS1 proc_name [ generic
>_params ]>_params ]
112              "(" WS? param_list? WS? ")"112              "(" WS? param_list? WS? ")"
113              [ WS? "->" WS? type_expr ]113              [ WS? "->" WS? type_expr ]
114              WS? proc_suffix*114              WS? proc_suffix*
115              WS? ( block | ";" )115              WS? ( block | ";" )
116              ;116              ;
117117
118proc_name ::= ident | "operator" WS? operator_symbol ;118proc_name ::= ident | "operator" WS? operator_symbol ;
119operator_symbol ::= "+" | "-" | "*" | "/" | "%"119operator_symbol ::= "+" | "-" | "*" | "/" | "%"
120                  | "==" | "!=" | "<" | "<=" | ">" | ">="120                  | "==" | "!=" | "<" | "<=" | ">" | ">="
121                  | "[]" | "()" ;121                  | "[]" | "()" ;
122122
123proc_modifier ::= "async" WS1123proc_modifier ::= "async" WS1
124                | "unsafe" WS1124                | "unsafe" WS1
125                | "const" WS1125                | "const" WS1
126                | "inline" WS1126                | "inline" WS1
127                | "noinline" WS1127                | "noinline" WS1
128                | "naked" WS1128                | "naked" WS1
129                | "interrupt" WS1129                | "interrupt" WS1
130                ;130                ;
131131
132proc_suffix ::= effects_clause132proc_suffix ::= effects_clause
133              | requires_clause133              | requires_clause
134              | where_clause134              | where_clause
135              | "noexcept"135              | "noexcept"
136              ;136              ;
137137
138extern_block ::= { attr_prefix WS? } "extern" WS1 extern_abi WS? "{" WS? extern_item* WS? "}" ;138extern_block ::= { attr_prefix WS? } "extern" WS1 extern_abi WS? "{" WS? extern_item* WS? "}" ;
139extern_item ::= extern_proc_decl | extern_type_decl | const_decl ;139extern_item ::= extern_proc_decl | extern_type_decl | const_decl ;
140140
141extern_proc_decl ::= { attr_prefix WS? } "proc" WS1 ident [ generic_params ]141extern_proc_decl ::= { attr_prefix WS? } "proc" WS1 ident [ generic_params ]
142                     "(" WS? param_list? WS? ")"142                     "(" WS? param_list? WS? ")"
143                     [ WS? "->" WS? type_expr ]143                     [ WS? "->" WS? type_expr ]
144                     WS? proc_suffix*144                     WS? proc_suffix*
145                     WS? ";"145                     WS? ";"
146                     ;146                     ;
147147
148extern_clause ::= "extern" WS1 extern_abi ;148extern_clause ::= "extern" WS1 extern_abi ;
149extern_abi ::= callconv | string_lit ;149extern_abi ::= callconv | string_lit ;
150callconv ::= "C" | "sysv64" | "win64" | "interrupt" | "naked" ;150callconv ::= "C" | "sysv64" | "win64" | "interrupt" | "naked" ;
151151
152intrinsic_decl ::= { attr_prefix WS? } "intrinsic" WS1 ident [ generic_params ]152intrinsic_decl ::= { attr_prefix WS? } "intrinsic" WS1 ident [ generic_params ]
153                   "(" WS? param_list? WS? ")"153                   "(" WS? param_list? WS? ")"
154                   [ WS? "->" WS? type_expr ]154                   [ WS? "->" WS? type_expr ]
155                   WS? ";"155                   WS? ";"
156                   ;156                   ;
157157
158macro_decl ::= { attr_prefix WS? } "macro" WS1 ident "(" WS? macro_param_list? WS? ")" WS? block ;158macro_decl ::= { attr_prefix WS? } "macro" WS1 ident "(" WS? macro_param_list? WS? ")" WS? block ;
159macro_param_list ::= macro_param { WS? "," WS? macro_param } [ WS? "," ] ;159macro_param_list ::= macro_param { WS? "," WS? macro_param } [ WS? "," ] ;
160macro_param ::= ident [ WS? ":" WS? macro_kind ] ;160macro_param ::= ident [ WS? ":" WS? macro_kind ] ;
161macro_kind ::= "expr" | "stmt" | "type" | "ident" | "block" | "item" ;161macro_kind ::= "expr" | "stmt" | "type" | "ident" | "block" | "item" ;
162162
163comptime_decl ::= "comptime" WS? block ;163comptime_decl ::= "comptime" WS? block ;
164static_assert_decl ::= "static_assert" WS? "(" WS? expr [ WS? "," WS? expr ] WS? ")" ;164static_assert_decl ::= "static_assert" WS? "(" WS? expr [ WS? "," WS? expr ] WS? ")" ;
165test_decl ::= { attr_prefix WS? } "test" WS1 string_lit WS? block ;165test_decl ::= { attr_prefix WS? } "test" WS1 string_lit WS? block ;
166bench_decl ::= { attr_prefix WS? } "bench" WS1 string_lit WS? block ;166bench_decl ::= { attr_prefix WS? } "bench" WS1 string_lit WS? block ;
167entry_decl ::= { attr_prefix WS? } "entry" WS1 ident WS1 "at" WS1 module_path WS? block ;167entry_decl ::= { attr_prefix WS? } "entry" WS1 ident WS1 "at" WS1 module_path WS? block ;
168168
169visibility ::= "pub" | "priv" | "pub" WS? "(" WS? visibility_scope WS? ")" ;169visibility ::= "pub" | "priv" | "pub" WS? "(" WS? visibility_scope WS? ")" ;
170visibility_scope ::= "package" | "module" | "super" ;170visibility_scope ::= "package" | "module" | "super" ;
171171
172generic_params ::= "[" WS? generic_param_list? WS? "]" ;172generic_params ::= "[" WS? generic_param_list? WS? "]" ;
173generic_param_list ::= generic_param { WS? "," WS? generic_param } [ WS? "," ] ;173generic_param_list ::= generic_param { WS? "," WS? generic_param } [ WS? "," ] ;
174generic_param ::= ident [ WS? ":" WS? trait_bound ] [ WS? "=" WS? type_expr ]174generic_param ::= ident [ WS? ":" WS? trait_bound ] [ WS? "=" WS? type_expr ]
175                | "const" WS1 ident WS? ":" WS? type_expr175                | "const" WS1 ident WS? ":" WS? type_expr
176                | "comptime" WS1 ident WS? ":" WS? type_expr176                | "comptime" WS1 ident WS? ":" WS? type_expr
177                ;177                ;
178178
179where_clause ::= "where" WS1 where_bounds ;179where_clause ::= "where" WS1 where_bounds ;
180where_bounds ::= where_bound { WS? "," WS? where_bound } [ WS? "," ] ;180where_bounds ::= where_bound { WS? "," WS? where_bound } [ WS? "," ] ;
181where_bound ::= type_expr WS? ":" WS? trait_bound181where_bound ::= type_expr WS? ":" WS? trait_bound
182              | type_expr WS? "==" WS? type_expr182              | type_expr WS? "==" WS? type_expr
183              | expr WS? rel_op WS? expr183              | expr WS? rel_op WS? expr
184              ;184              ;
185185
186trait_bound ::= type_expr { WS? "+" WS? type_expr } ;186trait_bound ::= type_expr { WS? "+" WS? type_expr } ;
187187
188param_list ::= param { WS? "," WS? param } [ WS? "," ] ;188param_list ::= param { WS? "," WS? param } [ WS? "," ] ;
189param ::= self_param | normal_param | variadic_param ;189param ::= self_param | normal_param | variadic_param ;
190self_param ::= [ "&" WS? ] [ "mut" WS1 ] "self" ;190self_param ::= [ "&" WS? ] [ "mut" WS1 ] "self" ;
191normal_param ::= [ param_mode WS1 ] pattern [ WS? ":" WS? type_expr ] [ WS? "=" WS? expr ] ;191normal_param ::= [ param_mode WS1 ] pattern [ WS? ":" WS? type_expr ] [ WS? "=" WS? expr ] ;
192variadic_param ::= "..." | ident WS? ":" WS? "..." type_expr ;192variadic_param ::= "..." | ident WS? ":" WS? "..." type_expr ;
193param_mode ::= "mut" | "owned" | "borrow" | "move" ;193param_mode ::= "mut" | "owned" | "borrow" | "move" ;
194194
195effects_clause ::= "effects" WS? "(" WS? ident_list? WS? ")" ;195effects_clause ::= "effects" WS? "(" WS? ident_list? WS? ")" ;
196requires_clause ::= "requires" WS? "(" WS? capability_list? WS? ")" ;196requires_clause ::= "requires" WS? "(" WS? capability_list? WS? ")" ;
197capability_list ::= capability { WS? "," WS? capability } [ WS? "," ] ;197capability_list ::= capability { WS? "," WS? capability } [ WS? "," ] ;
198capability ::= ident { "." ident } ;198capability ::= ident { "." ident } ;
199199
200module_path ::= relative? package_parts ;200module_path ::= relative? package_parts ;
201package_path ::= relative? package_parts ;201package_path ::= relative? package_parts ;
202relative ::= { "." } ;202relative ::= { "." } ;
203package_parts ::= ident { ( "/" | "." | "::" ) ident } ;203package_parts ::= ident { ( "/" | "." | "::" ) ident } ;
204ident_list ::= ident { WS? "," WS? ident } [ WS? "," ] ;204ident_list ::= ident { WS? "," WS? ident } [ WS? "," ] ;
205205
206<<< ================= Compiler Declarations ================= >>>206<<< ================= Compiler Declarations ================= >>>
207207
208compiler_decl ::= { attr_prefix WS? } "compiler" WS1 ident WS? "{" WS? compiler_items? WS? "}" ;208compiler_decl ::= { attr_prefix WS? } "compiler" WS1 ident WS? "{" WS? compiler_items? WS? "}" ;
209compiler_items ::= compiler_item { WS? compiler_item } ;209compiler_items ::= compiler_item { WS? compiler_item } ;
210210
211compiler_item ::= compiler_phase_decl211compiler_item ::= compiler_phase_decl
212                | compiler_stage_decl212                | compiler_stage_decl
213                | compiler_artifact_decl213                | compiler_artifact_decl
214                | compiler_pipeline_decl214                | compiler_pipeline_decl
215                | compiler_cache_decl215                | compiler_cache_decl
216                | compiler_target_decl216                | compiler_target_decl
217                ;217                ;
218218
219compiler_phase_decl ::= "phase" WS1 ident WS? "{" WS?219compiler_phase_decl ::= "phase" WS1 ident WS? "{" WS?
220                        "input" WS? ":" WS? type_expr WS? ";"220                        "input" WS? ":" WS? type_expr WS? ";"
221                        "output" WS? ":" WS? type_expr WS? ";"221                        "output" WS? ":" WS? type_expr WS? ";"
222                        [ "errors" WS? ":" WS? type_expr WS? ";" ]222                        [ "errors" WS? ":" WS? type_expr WS? ";" ]
223                        WS? "}" ;223                        WS? "}" ;
224224
225compiler_stage_decl ::= "stage" WS1 ident WS? ":" WS? ident_list WS? ";" ;225compiler_stage_decl ::= "stage" WS1 ident WS? ":" WS? ident_list WS? ";" ;
226compiler_artifact_decl ::= "artifact" WS1 ident WS? ":" WS? type_expr WS? ";" ;226compiler_artifact_decl ::= "artifact" WS1 ident WS? ":" WS? type_expr WS? ";" ;
227227
228compiler_pipeline_decl ::= "pipeline" WS1 ident WS? "{" WS? pipeline_step* WS? "}" ;228compiler_pipeline_decl ::= "pipeline" WS1 ident WS? "{" WS? pipeline_step* WS? "}" ;
229pipeline_step ::= "run" WS1 ident [ WS? "as" WS? ident ] WS? ";"229pipeline_step ::= "run" WS1 ident [ WS? "as" WS? ident ] WS? ";"
230                | "dump" WS1 ident WS? ";"230                | "dump" WS1 ident WS? ";"
231                | "verify" WS1 ident WS? ";"231                | "verify" WS1 ident WS? ";"
232                ;232                ;
233233
234compiler_cache_decl ::= "cache" WS1 ident WS? "{" WS? cache_item* WS? "}" ;234compiler_cache_decl ::= "cache" WS1 ident WS? "{" WS? cache_item* WS? "}" ;
235cache_item ::= "key" WS? ":" WS? type_expr WS? ";"235cache_item ::= "key" WS? ":" WS? type_expr WS? ";"
236             | "value" WS? ":" WS? type_expr WS? ";"236             | "value" WS? ":" WS? type_expr WS? ";"
237             | "strategy" WS? ":" WS? ident WS? ";"237             | "strategy" WS? ":" WS? ident WS? ";"
238             ;238             ;
239239
240compiler_target_decl ::= "target" WS1 ident WS? "{" WS? target_item* WS? "}" ;240compiler_target_decl ::= "target" WS1 ident WS? "{" WS? target_item* WS? "}" ;
241target_item ::= ident WS? ":" WS? expr WS? ";" ;241target_item ::= ident WS? ":" WS? expr WS? ";" ;
242242
243query_decl ::= { attr_prefix WS? } "query" WS1 ident243query_decl ::= { attr_prefix WS? } "query" WS1 ident
244               "(" WS? param_list? WS? ")"244               "(" WS? param_list? WS? ")"
245               WS? "->" WS? type_expr245               WS? "->" WS? type_expr
246               WS? query_body ;246               WS? query_body ;
247247
248query_body ::= block | ";" ;248query_body ::= block | ";" ;
249249
250pass_decl ::= { attr_prefix WS? } "pass" WS1 ident WS? "{" WS? pass_items? WS? "}" ;250pass_decl ::= { attr_prefix WS? } "pass" WS1 ident WS? "{" WS? pass_items? WS? "}" ;
251pass_items ::= pass_item { WS? pass_item } ;251pass_items ::= pass_item { WS? pass_item } ;
252pass_item ::= "input" WS? ":" WS? type_expr WS? ";"252pass_item ::= "input" WS? ":" WS? type_expr WS? ";"
253            | "output" WS? ":" WS? type_expr WS? ";"253            | "output" WS? ":" WS? type_expr WS? ";"
254            | "requires" WS? ":" WS? ident_list WS? ";"254            | "requires" WS? ":" WS? ident_list WS? ";"
255            | "invalidates" WS? ":" WS? ident_list WS? ";"255            | "invalidates" WS? ":" WS? ident_list WS? ";"
256            | proc_decl256            | proc_decl
257            ;257            ;
258258
259backend_decl ::= { attr_prefix WS? } "backend" WS1 ident WS? "{" WS? backend_items? WS? "}" ;259backend_decl ::= { attr_prefix WS? } "backend" WS1 ident WS? "{" WS? backend_items? WS? "}" ;
260backend_items ::= backend_item { WS? backend_item } ;260backend_items ::= backend_item { WS? backend_item } ;
261backend_item ::= "target" WS? ":" WS? string_lit WS? ";"261backend_item ::= "target" WS? ":" WS? string_lit WS? ";"
262               | "format" WS? ":" WS? backend_format WS? ";"262               | "format" WS? ":" WS? backend_format WS? ";"
263               | "emits" WS? ":" WS? backend_output WS? ";"263               | "emits" WS? ":" WS? backend_output WS? ";"
264               | "requires" WS? ":" WS? ident_list WS? ";"264               | "requires" WS? ":" WS? ident_list WS? ";"
265               | proc_decl265               | proc_decl
266               ;266               ;
267267
268backend_format ::= "c" | "llvm" | "asm" | "object" | "wasm" | "ir" ;268backend_format ::= "c" | "llvm" | "asm" | "object" | "wasm" | "ir" ;
269backend_output ::= "source" | "assembly" | "object" | "executable" | "library" ;269backend_output ::= "source" | "assembly" | "object" | "executable" | "library" ;
270270
271diagnostic_decl ::= { attr_prefix WS? } "diagnostic" WS1 diagnostic_code WS? "{" WS? diagnostic_items? WS? "}" ;271diagnostic_decl ::= { attr_prefix WS? } "diagnostic" WS1 diagnostic_code WS? "{" WS? diagnostic_items? WS? "}" ;
272diagnostic_code ::= ident | string_lit ;272diagnostic_code ::= ident | string_lit ;
273diagnostic_items ::= diagnostic_item { WS? diagnostic_item } ;273diagnostic_items ::= diagnostic_item { WS? diagnostic_item } ;
274274
275diagnostic_item ::= "level" WS? ":" WS? diagnostic_level WS? ";"275diagnostic_item ::= "level" WS? ":" WS? diagnostic_level WS? ";"
276                  | "message" WS? ":" WS? string_lit WS? ";"276                  | "message" WS? ":" WS? string_lit WS? ";"
277                  | "label" WS? ":" WS? string_lit WS? ";"277                  | "label" WS? ":" WS? string_lit WS? ";"
278                  | "help" WS? ":" WS? string_lit WS? ";"278                  | "help" WS? ":" WS? string_lit WS? ";"
279                  | "note" WS? ":" WS? string_lit WS? ";"279                  | "note" WS? ":" WS? string_lit WS? ";"
280                  | "suggest" WS? ":" WS? string_lit WS? ";"280                  | "suggest" WS? ":" WS? string_lit WS? ";"
281                  ;281                  ;
282282
283diagnostic_level ::= "error" | "warning" | "note" | "help" | "fatal" ;283diagnostic_level ::= "error" | "warning" | "note" | "help" | "fatal" ;
284284
285<<< ================= Attributes ================= >>>285<<< ================= Attributes ================= >>>
286286
287attr_prefix ::= outer_attribute | doc_comment | docstring ;287attr_prefix ::= outer_attribute | doc_comment | docstring ;
288inner_attribute ::= "#![" attr_path [ "(" WS? attr_arg_list? WS? ")" ] "]" ;288inner_attribute ::= "#![" attr_path [ "(" WS? attr_arg_list? WS? ")" ] "]" ;
289outer_attribute ::= "#[" attr_path [ "(" WS? attr_arg_list? WS? ")" ] "]" ;289outer_attribute ::= "#[" attr_path [ "(" WS? attr_arg_list? WS? ")" ] "]" ;
290doc_comment ::= "///" { ~NEWLINE ANY } ;290doc_comment ::= "///" { ~NEWLINE ANY } ;
291docstring ::= raw_string_lit ;291docstring ::= raw_string_lit ;
292292
293attr_path ::= ident { "." ident } ;293attr_path ::= ident { "." ident } ;
294attr_arg_list ::= attr_arg { WS? "," WS? attr_arg } [ WS? "," ] ;294attr_arg_list ::= attr_arg { WS? "," WS? attr_arg } [ WS? "," ] ;
295attr_arg ::= ident295attr_arg ::= ident
296           | string_lit296           | string_lit
297           | int_lit297           | int_lit
298           | bool_lit298           | bool_lit
299           | ident WS? "=" WS? literal299           | ident WS? "=" WS? literal
300           ;300           ;
301301
302<<< ================= Blocks / Statements ================= >>>302<<< ================= Blocks / Statements ================= >>>
303303
304block ::= "{" WS? { stmt WS? } "}" ;304block ::= "{" WS? { stmt WS? } "}" ;
305305
306stmt ::= local_const_stmt stmt_end306stmt ::= local_const_stmt stmt_end
307       | let_stmt stmt_end307       | let_stmt stmt_end
308       | set_stmt stmt_end308       | set_stmt stmt_end
309       | give_stmt stmt_end309       | give_stmt stmt_end
310       | try_stmt stmt_end310       | try_stmt stmt_end
311       | defer_stmt311       | defer_stmt
312       | asm_stmt stmt_end312       | asm_stmt stmt_end
313       | unsafe_stmt313       | unsafe_stmt
314       | emit_stmt stmt_end314       | emit_stmt stmt_end
315       | assert_stmt stmt_end315       | assert_stmt stmt_end
316       | panic_stmt stmt_end316       | panic_stmt stmt_end
317       | unreachable_stmt stmt_end317       | unreachable_stmt stmt_end
318       | if_stmt318       | if_stmt
319       | while_stmt319       | while_stmt
320       | loop_stmt320       | loop_stmt
321       | for_stmt321       | for_stmt
322       | break_stmt stmt_end322       | break_stmt stmt_end
323       | continue_stmt stmt_end323       | continue_stmt stmt_end
324       | select_stmt324       | select_stmt
325       | match_stmt325       | match_stmt
326       | when_match_stmt326       | when_match_stmt
327       | with_stmt327       | with_stmt
328       | critical_stmt328       | critical_stmt
329       | expr_stmt stmt_end329       | expr_stmt stmt_end
330       ;330       ;
331331
332stmt_end ::= WS? ";" ;332stmt_end ::= WS? ";" ;
333333
334local_const_stmt ::= "const" WS1 ident [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;334local_const_stmt ::= "const" WS1 ident [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;
335let_stmt ::= "let" WS1 [ "mut" WS1 ] pattern [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;335let_stmt ::= "let" WS1 [ "mut" WS1 ] pattern [ WS? ":" WS? type_expr ] WS? "=" WS? expr ;
336<<< assign_target stays intentionally syntactic here; projection validity and aliasing336<<< assign_target stays intentionally syntactic here; projection validity and aliasing
337    are enforced later by sema/typeck/borrowck on structured HIR/MIR places. >>>337    are enforced later by sema/typeck/borrowck on structured HIR/MIR places. >>>
338set_stmt ::= "set" WS1 assign_target WS? assign_op WS? expr ;338set_stmt ::= "set" WS1 assign_target WS? assign_op WS? expr ;
339assign_target ::= unary_expr ;339assign_target ::= unary_expr ;
340340
341give_stmt ::= "give" [ WS1 expr ] ;341give_stmt ::= "give" [ WS1 expr ] ;
342try_stmt ::= "try" WS1 expr ;342try_stmt ::= "try" WS1 expr ;
343defer_stmt ::= "defer" WS? block ;343defer_stmt ::= "defer" WS? block ;
344344
345asm_stmt ::= "asm" WS? "(" WS? asm_arg_list? WS? ")" ;345asm_stmt ::= "asm" WS? "(" WS? asm_arg_list? WS? ")" ;
346asm_arg_list ::= asm_arg { WS? "," WS? asm_arg } [ WS? "," ] ;346asm_arg_list ::= asm_arg { WS? "," WS? asm_arg } [ WS? "," ] ;
347asm_arg ::= string_lit | ident WS? "(" WS? arg_list? WS? ")" | ident WS? ":" WS? expr ;347asm_arg ::= string_lit | ident WS? "(" WS? arg_list? WS? ")" | ident WS? ":" WS? expr ;
348348
349unsafe_stmt ::= "unsafe" WS? block ;349unsafe_stmt ::= "unsafe" WS? block ;
350350
351emit_stmt ::= "emit" WS1 expr ;351emit_stmt ::= "emit" WS1 expr ;
352assert_stmt ::= "assert" WS1 expr [ WS? "," WS? expr ] ;352assert_stmt ::= "assert" WS1 expr [ WS? "," WS? expr ] ;
353panic_stmt ::= "panic" WS1 expr ;353panic_stmt ::= "panic" WS1 expr ;
354unreachable_stmt ::= "unreachable" ;354unreachable_stmt ::= "unreachable" ;
355355
356if_stmt ::= "if" WS1 expr WS? block356if_stmt ::= "if" WS1 expr WS? block
357            { WS? "elif" WS1 expr WS? block }357            { WS? "elif" WS1 expr WS? block }
358            [ WS? "else" WS? block ] ;358            [ WS? "else" WS? block ] ;
359359
360while_stmt ::= "while" WS1 expr WS? block ;360while_stmt ::= "while" WS1 expr WS? block ;
361loop_stmt ::= "loop" WS? block ;361loop_stmt ::= "loop" WS? block ;
362for_stmt ::= "for" WS1 pattern WS1 "in" WS1 expr WS? block ;362for_stmt ::= "for" WS1 pattern WS1 "in" WS1 expr WS? block ;
363363
364break_stmt ::= "break" [ WS1 expr ] ;364break_stmt ::= "break" [ WS1 expr ] ;
365continue_stmt ::= "continue" ;365continue_stmt ::= "continue" ;
366366
367select_stmt ::= "select" WS1 expr WS? "{" WS?367select_stmt ::= "select" WS1 expr WS? "{" WS?
368                { "when" WS1 pattern WS? block WS? }368                { "when" WS1 pattern WS? block WS? }
369                [ "else" WS? block ]369                [ "else" WS? block ]
370                WS? "}" ;370                WS? "}" ;
371371
372match_stmt ::= "match" WS1 expr WS?372match_stmt ::= "match" WS1 expr WS?
373               "{" WS?373               "{" WS?
374               { "case" WS1 pattern [ WS1 "if" WS1 expr ] WS? match_arm_body WS? }374               { "case" WS1 pattern [ WS1 "if" WS1 expr ] WS? match_arm_body WS? }
375               [ WS? "else" WS? match_arm_body ]375               [ WS? "else" WS? match_arm_body ]
376               WS? "}" ;376               WS? "}" ;
377377
378match_arm_body ::= block | "=>" WS? expr WS? ";" ;378match_arm_body ::= block | "=>" WS? expr WS? ";" ;
379379
380when_match_stmt ::= "when" WS1 expr WS1 "is" WS1 pattern WS? block ;380when_match_stmt ::= "when" WS1 expr WS1 "is" WS1 pattern WS? block ;
381with_stmt ::= "with" WS1 expr [ WS1 "as" WS1 pattern ] WS? block ;381with_stmt ::= "with" WS1 expr [ WS1 "as" WS1 pattern ] WS? block ;
382critical_stmt ::= "critical" WS? block ;382critical_stmt ::= "critical" WS? block ;
383expr_stmt ::= expr ;383expr_stmt ::= expr ;
384384
385<<< ================= Expressions ================= >>>385<<< ================= Expressions ================= >>>
386386
387expr ::= assign_expr ;387expr ::= assign_expr ;
388388
389assign_expr ::= ternary_expr [ WS? assign_op WS? assign_expr ] ;389assign_expr ::= ternary_expr [ WS? assign_op WS? assign_expr ] ;
390assign_op ::= "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=" ;390assign_op ::= "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>=" ;
391391
392ternary_expr ::= coalesce_expr [ WS? "?" WS? expr WS? ":" WS? expr ] ;392ternary_expr ::= coalesce_expr [ WS? "?" WS? expr WS? ":" WS? expr ] ;
393coalesce_expr ::= range_expr { WS? "??" WS? range_expr } ;393coalesce_expr ::= range_expr { WS? "??" WS? range_expr } ;
394range_expr ::= or_expr [ WS? ( ".." | "..=" ) WS? or_expr ] ;394range_expr ::= or_expr [ WS? ( ".." | "..=" ) WS? or_expr ] ;
395395
396or_expr ::= and_expr { WS? ( "or" | "||" ) WS? and_expr } ;396or_expr ::= and_expr { WS? ( "or" | "||" ) WS? and_expr } ;
397and_expr ::= bit_or_expr { WS? ( "and" | "&&" ) WS? bit_or_expr } ;397and_expr ::= bit_or_expr { WS? ( "and" | "&&" ) WS? bit_or_expr } ;
398398
399bit_or_expr ::= bit_xor_expr { WS? "|" WS? bit_xor_expr } ;399bit_or_expr ::= bit_xor_expr { WS? "|" WS? bit_xor_expr } ;
400bit_xor_expr ::= bit_and_expr { WS? "^" WS? bit_and_expr } ;400bit_xor_expr ::= bit_and_expr { WS? "^" WS? bit_and_expr } ;
401bit_and_expr ::= eq_expr { WS? "&" WS? eq_expr } ;401bit_and_expr ::= eq_expr { WS? "&" WS? eq_expr } ;
402402
403eq_expr ::= rel_expr { WS? ( "==" | "!=" ) WS? rel_expr } ;403eq_expr ::= rel_expr { WS? ( "==" | "!=" ) WS? rel_expr } ;
404rel_expr ::= shift_expr { WS? rel_op WS? shift_expr } ;404rel_expr ::= shift_expr { WS? rel_op WS? shift_expr } ;
405rel_op ::= "<" | "<=" | ">" | ">=" | "in" | "not" WS1 "in" ;405rel_op ::= "<" | "<=" | ">" | ">=" | "in" | "not" WS1 "in" ;
406406
407shift_expr ::= add_expr { WS? ( "<<" | ">>" ) WS? add_expr } ;407shift_expr ::= add_expr { WS? ( "<<" | ">>" ) WS? add_expr } ;
408add_expr ::= mul_expr { WS? ( "+" | "-" ) WS? mul_expr } ;408add_expr ::= mul_expr { WS? ( "+" | "-" ) WS? mul_expr } ;
409mul_expr ::= cast_expr { WS? ( "*" | "/" | "%" ) WS? cast_expr } ;409mul_expr ::= cast_expr { WS? ( "*" | "/" | "%" ) WS? cast_expr } ;
410410
411cast_expr ::= unary_expr { WS? ( "as" WS? type_expr | "is" WS? pattern | "is" WS1 "not" WS1 pattern ) } ;411cast_expr ::= unary_expr { WS? ( "as" WS? type_expr | "is" WS? pattern | "is" WS1 "not" WS1 pattern ) } ;
412412
413<<< unary borrow and move syntax are accepted at parse time; whether a use is413<<< unary borrow and move syntax are accepted at parse time; whether a use is
414    actually a copy or a move is decided later from inferred types. >>>414    actually a copy or a move is decided later from inferred types. >>>
415unary_expr ::= ( "not" | "-" | "~" | "*" | "&" | "move" | "await" ) WS? unary_expr415unary_expr ::= ( "not" | "-" | "~" | "*" | "&" | "move" | "await" ) WS? unary_expr
416             | postfix_expr416             | postfix_expr
417             ;417             ;
418418
419<<< postfix chains define the full place surface used later by ownership and419<<< postfix chains define the full place surface used later by ownership and
420    borrow analysis: field projection, indexing, call, try and await suffixes. >>>420    borrow analysis: field projection, indexing, call, try and await suffixes. >>>
421postfix_expr ::= primary { call_suffix | member_suffix | index_suffix | try_suffix | await_suffix } ;421postfix_expr ::= primary { call_suffix | member_suffix | index_suffix | try_suffix | await_suffix } ;
422call_suffix ::= "(" WS? arg_list? WS? ")" ;422call_suffix ::= "(" WS? arg_list? WS? ")" ;
423member_suffix ::= "." ident ;423member_suffix ::= "." ident ;
424index_suffix ::= "[" WS? index_expr WS? "]" ;424index_suffix ::= "[" WS? index_expr WS? "]" ;
425try_suffix ::= "?" ;425try_suffix ::= "?" ;
426await_suffix ::= "." "await" ;426await_suffix ::= "." "await" ;
427427
428index_expr ::= expr | slice_expr ;428index_expr ::= expr | slice_expr ;
429slice_expr ::= [ expr ] ":" [ expr ] [ ":" expr ] ;429slice_expr ::= [ expr ] ":" [ expr ] [ ":" expr ] ;
430430
431primary ::= literal431primary ::= literal
432          | builtin_expr432          | builtin_expr
433          | path_expr433          | path_expr
434          | struct_lit434          | struct_lit
435          | list_lit435          | list_lit
436          | tuple_lit436          | tuple_lit
437          | set_lit437          | set_lit
438          | map_lit438          | map_lit
439          | bytes_lit439          | bytes_lit
440          | resource_lit440          | resource_lit
441          | if_expr441          | if_expr
442          | proc_expr442          | proc_expr
443          | match_expr443          | match_expr
444          | lambda_expr444          | lambda_expr
445          | unsafe_expr445          | unsafe_expr
446          | block446          | block
447          | "(" WS? expr WS? ")"447          | "(" WS? expr WS? ")"
448          ;448          ;
449449
450path_expr ::= ident { ( "." | "::" ) ident } ;450path_expr ::= ident { ( "." | "::" ) ident } ;
451451
452arg_list ::= arg { WS? "," WS? arg } [ WS? "," ] ;452arg_list ::= arg { WS? "," WS? arg } [ WS? "," ] ;
453arg ::= ident WS? ":" WS? expr | expr ;453arg ::= ident WS? ":" WS? expr | expr ;
454454
455tuple_lit ::= "(" WS? expr WS? "," WS? expr { WS? "," WS? expr } [ WS? "," ] WS? ")" ;455tuple_lit ::= "(" WS? expr WS? "," WS? expr { WS? "," WS? expr } [ WS? "," ] WS? ")" ;
456set_lit ::= "set" WS? "{" WS? arg_list? WS? "}" ;456set_lit ::= "set" WS? "{" WS? arg_list? WS? "}" ;
457457
458map_lit ::= "map" WS? "{" WS? map_items? WS? "}" ;458map_lit ::= "map" WS? "{" WS? map_items? WS? "}" ;
459map_items ::= map_item { WS? "," WS? map_item } [ WS? "," ] ;459map_items ::= map_item { WS? "," WS? map_item } [ WS? "," ] ;
460map_item ::= expr WS? ":" WS? expr ;460map_item ::= expr WS? ":" WS? expr ;
461461
462bytes_lit ::= "b" string_lit ;462bytes_lit ::= "b" string_lit ;
463463
464resource_lit ::= "resource" WS? "{" WS? resource_items? WS? "}" ;464resource_lit ::= "resource" WS? "{" WS? resource_items? WS? "}" ;
465resource_items ::= resource_item { WS? "," WS? resource_item } [ WS? "," ] ;465resource_items ::= resource_item { WS? "," WS? resource_item } [ WS? "," ] ;
466resource_item ::= ident WS? ":" WS? expr ;466resource_item ::= ident WS? ":" WS? expr ;
467467
468struct_lit ::= type_path WS? "{" WS? field_init_list? WS? "}" ;468struct_lit ::= type_path WS? "{" WS? field_init_list? WS? "}" ;
469type_path ::= ident { ( "." | "::" ) ident } ;469type_path ::= ident { ( "." | "::" ) ident } ;
470field_init_list ::= field_init { WS? "," WS? field_init } [ WS? "," ] ;470field_init_list ::= field_init { WS? "," WS? field_init } [ WS? "," ] ;
471field_init ::= ident WS? ":" WS? expr471field_init ::= ident WS? ":" WS? expr
472             | ident472             | ident
473             | ".." expr473             | ".." expr
474             ;474             ;
475475
476if_expr ::= "if" WS1 expr WS? block476if_expr ::= "if" WS1 expr WS? block
477            { WS? "elif" WS1 expr WS? block }477            { WS? "elif" WS1 expr WS? block }
478            [ WS? "else" WS? block ] ;478            [ WS? "else" WS? block ] ;
479479
480proc_expr ::= { attr_prefix WS? } proc_modifier* "proc" WS? "(" WS? param_list? WS? ")"480proc_expr ::= { attr_prefix WS? } proc_modifier* "proc" WS? "(" WS? param_list? WS? ")"
481              [ WS? "->" WS? type_expr ]481              [ WS? "->" WS? type_expr ]
482              WS? proc_suffix*482              WS? proc_suffix*
483              WS? block ;483              WS? block ;
484484
485match_expr ::= "match" WS1 expr WS?485match_expr ::= "match" WS1 expr WS?
486               "{" WS?486               "{" WS?
487               { "case" WS1 pattern [ WS1 "if" WS1 expr ] WS? match_arm_body WS? }487               { "case" WS1 pattern [ WS1 "if" WS1 expr ] WS? match_arm_body WS? }
488               [ WS? "else" WS? match_arm_body ]488               [ WS? "else" WS? match_arm_body ]
489               WS? "}" ;489               WS? "}" ;
490490
491lambda_expr ::= "|" WS? param_list? WS? "|" WS? ( expr | block ) ;491lambda_expr ::= "|" WS? param_list? WS? "|" WS? ( expr | block ) ;
492unsafe_expr ::= "unsafe" WS? block ;492unsafe_expr ::= "unsafe" WS? block ;
493493
494builtin_expr ::= sizeof_expr | alignof_expr | offsetof_expr | typeof_expr | nameof_expr ;494builtin_expr ::= sizeof_expr | alignof_expr | offsetof_expr | typeof_expr | nameof_expr ;
495sizeof_expr ::= "sizeof" WS? "(" WS? ( type_expr | expr ) WS? ")" ;495sizeof_expr ::= "sizeof" WS? "(" WS? ( type_expr | expr ) WS? ")" ;
496alignof_expr ::= "alignof" WS? "(" WS? type_expr WS? ")" ;496alignof_expr ::= "alignof" WS? "(" WS? type_expr WS? ")" ;
497offsetof_expr ::= "offsetof" WS? "(" WS? type_expr WS? "," WS? ident WS? ")" ;497offsetof_expr ::= "offsetof" WS? "(" WS? type_expr WS? "," WS? ident WS? ")" ;
498typeof_expr ::= "typeof" WS? "(" WS? expr WS? ")" ;498typeof_expr ::= "typeof" WS? "(" WS? expr WS? ")" ;
499nameof_expr ::= "nameof" WS? "(" WS? path_expr WS? ")" ;499nameof_expr ::= "nameof" WS? "(" WS? path_expr WS? ")" ;
500500
501<<< ================= Patterns ================= >>>501<<< ================= Patterns ================= >>>
502502
503pattern ::= pattern_or ;503pattern ::= pattern_or ;
504pattern_or ::= pattern_atom { WS? "|" WS? pattern_atom } ;504pattern_or ::= pattern_atom { WS? "|" WS? pattern_atom } ;
505505
506pattern_atom ::= "_"506pattern_atom ::= "_"
507               | literal507               | literal
508               | "mut" WS1 pattern_bind508               | "mut" WS1 pattern_bind
509               | "ref" WS1 pattern_bind509               | "ref" WS1 pattern_bind
510               | pattern_bind510               | pattern_bind
511               | pattern_ctor511               | pattern_ctor
512               | pattern_struct512               | pattern_struct
513               | pattern_tuple513               | pattern_tuple
514               | pattern_list514               | pattern_list
515               | pattern_range515               | pattern_range
516               ;516               ;
517517
518pattern_bind ::= ident ;518pattern_bind ::= ident ;
519pattern_ctor ::= pattern_head [ "(" WS? pattern_args? WS? ")" ] ;519pattern_ctor ::= pattern_head [ "(" WS? pattern_args? WS? ")" ] ;
520pattern_head ::= ident { ( "." | "::" ) ident } ;520pattern_head ::= ident { ( "." | "::" ) ident } ;
521pattern_args ::= pattern { WS? "," WS? pattern } [ WS? "," ] ;521pattern_args ::= pattern { WS? "," WS? pattern } [ WS? "," ] ;
522522
523pattern_struct ::= pattern_head WS? "{" WS? pattern_fields? WS? "}" ;523pattern_struct ::= pattern_head WS? "{" WS? pattern_fields? WS? "}" ;
524pattern_fields ::= pattern_field { WS? "," WS? pattern_field } [ WS? "," ] ;524pattern_fields ::= pattern_field { WS? "," WS? pattern_field } [ WS? "," ] ;
525pattern_field ::= ident [ WS? ":" WS? pattern ] | ".." ;525pattern_field ::= ident [ WS? ":" WS? pattern ] | ".." ;
526526
527pattern_tuple ::= "(" WS? pattern WS? "," WS? pattern { WS? "," WS? pattern } [ WS? "," ] WS? ")" ;527pattern_tuple ::= "(" WS? pattern WS? "," WS? pattern { WS? "," WS? pattern } [ WS? "," ] WS? ")" ;
528pattern_list ::= "[" WS? pattern_args? WS? "]" ;528pattern_list ::= "[" WS? pattern_args? WS? "]" ;
529pattern_range ::= literal WS? ( ".." | "..=" ) WS? literal ;529pattern_range ::= literal WS? ( ".." | "..=" ) WS? literal ;
530530
531<<< ================= Types ================= >>>531<<< ================= Types ================= >>>
532532
533type_expr ::= type_union ;533type_expr ::= type_union ;
534534
535type_union ::= type_prefix { WS? "|" WS? type_prefix } ;535type_union ::= type_prefix { WS? "|" WS? type_prefix } ;
536536
537type_prefix ::= type_qualifier* type_atom ;537type_prefix ::= type_qualifier* type_atom ;
538type_qualifier ::= type_qual WS1 | addr_space WS1 ;538type_qualifier ::= type_qual WS1 | addr_space WS1 ;
539539
540type_qual ::= "const" | "volatile" | "atomic" | "mut" | "owned" | "borrow" ;540type_qual ::= "const" | "volatile" | "atomic" | "mut" | "owned" | "borrow" ;
541addr_space ::= "user" | "kernel" | "phys" | "mmio" | "dma" ;541addr_space ::= "user" | "kernel" | "phys" | "mmio" | "dma" ;
542542
543type_atom ::= reference_type543type_atom ::= reference_type
544            | pointer_type544            | pointer_type
545            | optional_type545            | optional_type
546            | fixed_array_type546            | fixed_array_type
547            | slice_type547            | slice_type
548            | tuple_type548            | tuple_type
549            | proc_type549            | proc_type
550            | dyn_type550            | dyn_type
551            | impl_trait_type551            | impl_trait_type
552            | type_primary552            | type_primary
553            ;553            ;
554554
555<<< shared and mutable references are part of the core surface grammar; lifetime,555<<< shared and mutable references are part of the core surface grammar; lifetime,
556    aliasing and region closure remain semantic checks outside the parser. >>>556    aliasing and region closure remain semantic checks outside the parser. >>>
557reference_type ::= "&" WS? [ lifetime WS? ] [ "mut" WS1 ] type_expr ;557reference_type ::= "&" WS? [ lifetime WS? ] [ "mut" WS1 ] type_expr ;
558pointer_type ::= "*" WS? [ "const" WS1 | "mut" WS1 | "volatile" WS1 | addr_space WS1 ] type_expr ;558pointer_type ::= "*" WS? [ "const" WS1 | "mut" WS1 | "volatile" WS1 | addr_space WS1 ] type_expr ;
559optional_type ::= "?" WS? type_expr ;559optional_type ::= "?" WS? type_expr ;
560560
561fixed_array_type ::= "[" WS? type_expr WS? ";" WS? expr WS? "]" ;561fixed_array_type ::= "[" WS? type_expr WS? ";" WS? expr WS? "]" ;
562slice_type ::= "[" WS? type_expr WS? "]" ;562slice_type ::= "[" WS? type_expr WS? "]" ;
563563
564tuple_type ::= "(" WS? type_expr WS? "," WS? type_expr { WS? "," WS? type_expr } [ WS? "," ] WS? ")" ;564tuple_type ::= "(" WS? type_expr WS? "," WS? type_expr { WS? "," WS? type_expr } [ WS? "," ] WS? ")" ;
565proc_type ::= "proc" WS? "(" WS? type_list? WS? ")" [ WS? "->" WS? type_expr ] ;565proc_type ::= "proc" WS? "(" WS? type_list? WS? ")" [ WS? "->" WS? type_expr ] ;
566566
567type_list ::= type_param { WS? "," WS? type_param } [ WS? "," ] ;567type_list ::= type_param { WS? "," WS? type_param } [ WS? "," ] ;
568type_param ::= ident WS? ":" WS? type_expr | type_expr ;568type_param ::= ident WS? ":" WS? type_expr | type_expr ;
569569
570dyn_type ::= "dyn" WS1 trait_bound ;570dyn_type ::= "dyn" WS1 trait_bound ;
571impl_trait_type ::= "impl" WS1 trait_bound ;571impl_trait_type ::= "impl" WS1 trait_bound ;
572572
573type_primary ::= type_path [ "[" WS? type_list? WS? "]" ]573type_primary ::= type_path [ "[" WS? type_list? WS? "]" ]
574               | primitive_type574               | primitive_type
575               | "Self"575               | "Self"
576               ;576               ;
577577
578lifetime ::= "'" ident ;578lifetime ::= "'" ident ;
579579
580primitive_type ::= "void"580primitive_type ::= "void"
581                 | "never"581                 | "never"
582                 | "unit"582                 | "unit"
583                 | "bool"583                 | "bool"
584                 | "char"584                 | "char"
585                 | "rune"585                 | "rune"
586                 | "str"586                 | "str"
587                 | "string"587                 | "string"
588                 | "bytes"588                 | "bytes"
589                 | "cstr"589                 | "cstr"
590                 | "int"590                 | "int"
591                 | "i8" | "i16" | "i32" | "i64" | "i128"591                 | "i8" | "i16" | "i32" | "i64" | "i128"
592                 | "u8" | "u16" | "u32" | "u64" | "u128"592                 | "u8" | "u16" | "u32" | "u64" | "u128"
593                 | "usize" | "isize"593                 | "usize" | "isize"
594                 | "intptr" | "uintptr"594                 | "intptr" | "uintptr"
595                 | "f16" | "f32" | "f64" | "f128"595                 | "f16" | "f32" | "f64" | "f128"
596                 | "c_char" | "c_int" | "c_uint" | "c_long" | "c_ulong" | "c_void"596                 | "c_char" | "c_int" | "c_uint" | "c_long" | "c_ulong" | "c_void"
597                 | "TokenId"597                 | "TokenId"
598                 | "NodeId"598                 | "NodeId"
599                 | "DefId"599                 | "DefId"
600                 | "HirId"600                 | "HirId"
601                 | "MirId"601                 | "MirId"
602                 | "TypeId"602                 | "TypeId"
603                 | "SymbolId"603                 | "SymbolId"
604                 | "ScopeId"604                 | "ScopeId"
605                 | "BlockId"605                 | "BlockId"
606                 | "ValueId"606                 | "ValueId"
607                 | "InstrId"607                 | "InstrId"
608                 ;608                 ;
609609
610<<< ================= Literals ================= >>>610<<< ================= Literals ================= >>>
611611
612literal ::= bool_lit612literal ::= bool_lit
613          | null_lit613          | null_lit
614          | int_lit614          | int_lit
615          | float_lit615          | float_lit
616          | char_lit616          | char_lit
617          | string_lit617          | string_lit
618          | list_lit618          | list_lit
619          ;619          ;
620620
621list_lit ::= "[" WS? ( list_comp | arg_list? ) WS? "]" ;621list_lit ::= "[" WS? ( list_comp | arg_list? ) WS? "]" ;
622list_comp ::= expr WS1 "for" WS1 pattern WS1 "in" WS1 expr [ WS1 "if" WS1 expr ] ;622list_comp ::= expr WS1 "for" WS1 pattern WS1 "in" WS1 expr [ WS1 "if" WS1 expr ] ;
623623
624bool_lit ::= "true" | "false" ;624bool_lit ::= "true" | "false" ;
625null_lit ::= "null" ;625null_lit ::= "null" ;
626626
627int_lit ::= [ "-" ] DIGIT { DIGIT | "_" } [ suffix ]627int_lit ::= [ "-" ] DIGIT { DIGIT | "_" } [ suffix ]
628          | [ "-" ] "0x" HEXDIGIT { HEXDIGIT | "_" } [ suffix ]628          | [ "-" ] "0x" HEXDIGIT { HEXDIGIT | "_" } [ suffix ]
629          | [ "-" ] "0b" BINDIGIT { BINDIGIT | "_" } [ suffix ]629          | [ "-" ] "0b" BINDIGIT { BINDIGIT | "_" } [ suffix ]
630          | [ "-" ] "0o" OCTDIGIT { OCTDIGIT | "_" } [ suffix ]630          | [ "-" ] "0o" OCTDIGIT { OCTDIGIT | "_" } [ suffix ]
631          ;631          ;
632632
633float_lit ::= [ "-" ] DIGIT { DIGIT | "_" } "." DIGIT { DIGIT | "_" } [ exponent ] [ suffix ] ;633float_lit ::= [ "-" ] DIGIT { DIGIT | "_" } "." DIGIT { DIGIT | "_" } [ exponent ] [ suffix ] ;
634exponent ::= ( "e" | "E" ) [ "+" | "-" ] DIGIT { DIGIT | "_" } ;634exponent ::= ( "e" | "E" ) [ "+" | "-" ] DIGIT { DIGIT | "_" } ;
635635
636char_lit ::= "'" char_char "'" ;636char_lit ::= "'" char_char "'" ;
637char_char ::= escape_seq | ~"'" ;637char_char ::= escape_seq | ~"'" ;
638638
639string_lit ::= "\"" { string_char } "\"" | raw_string_lit ;639string_lit ::= "\"" { string_char } "\"" | raw_string_lit ;
640string_char ::= escape_seq | ~"\"" ;640string_char ::= escape_seq | ~"\"" ;
641641
642escape_seq ::= "\\n"642escape_seq ::= "\\n"
643             | "\\r"643             | "\\r"
644             | "\\t"644             | "\\t"
645             | "\\0"645             | "\\0"
646             | "\\\""646             | "\\\""
647             | "\\'"647             | "\\'"
648             | "\\\\"648             | "\\\\"
649             | "\\x" HEXDIGIT HEXDIGIT649             | "\\x" HEXDIGIT HEXDIGIT
650             | "\\u{" HEXDIGIT { HEXDIGIT } "}"650             | "\\u{" HEXDIGIT { HEXDIGIT } "}"
651             ;651             ;
652652
653raw_string_lit ::= "\"\"\"" { raw_string_char } "\"\"\""653raw_string_lit ::= "\"\"\"" { raw_string_char } "\"\"\""
654                 | "r\"" { raw_string_char } "\""654                 | "r\"" { raw_string_char } "\""
655                 ;655                 ;
656raw_string_char ::= ~"\"\"\"" ;656raw_string_char ::= ~"\"\"\"" ;
657657
658<<< ================= Lexical ================= >>>658<<< ================= Lexical ================= >>>
659659
660line_comment ::= "#" { ~NEWLINE ANY }660line_comment ::= "#" { ~NEWLINE ANY }
661               | "//" { ~NEWLINE ANY }661               | "//" { ~NEWLINE ANY }
662               ;662               ;
663663
664block_comment ::= "/*" { ~"*/" ANY } "*/" ;664block_comment ::= "/*" { ~"*/" ANY } "*/" ;
665zone_comment ::= "<<<" { ~">>>" ANY } ">>>" ;665zone_comment ::= "<<<" { ~">>>" ANY } ">>>" ;
666666
667ident ::= ( LETTER | "_" ) { LETTER | DIGIT | "_" } ;667ident ::= ( LETTER | "_" ) { LETTER | DIGIT | "_" } ;
668suffix ::= LETTER { LETTER | DIGIT } ;668suffix ::= LETTER { LETTER | DIGIT } ;
669669
670WS ::= { " " | "\t" | NEWLINE | line_comment | block_comment | zone_comment } ;670WS ::= { " " | "\t" | NEWLINE | line_comment | block_comment | zone_comment } ;
671WS1 ::= ( " " | "\t" | NEWLINE | line_comment | block_comment | zone_comment )671WS1 ::= ( " " | "\t" | NEWLINE | line_comment | block_comment | zone_comment )
672        { " " | "\t" | NEWLINE | line_comment | block_comment | zone_comment } ;672        { " " | "\t" | NEWLINE | line_comment | block_comment | zone_comment } ;
673673
674NEWLINE ::= "\n" | "\r\n" ;674NEWLINE ::= "\n" | "\r\n" ;
675675
676LETTER ::= "a"..."z" | "A"..."Z" ;676LETTER ::= "a"..."z" | "A"..."Z" ;
677DIGIT ::= "0"..."9" ;677DIGIT ::= "0"..."9" ;
678BINDIGIT ::= "0" | "1" ;678BINDIGIT ::= "0" | "1" ;
679OCTDIGIT ::= "0"..."7" ;679OCTDIGIT ::= "0"..."7" ;
680HEXDIGIT ::= DIGIT | "a"..."f" | "A"..."F" ;680HEXDIGIT ::= DIGIT | "a"..."f" | "A"..."F" ;
681681
682EOF ::= !ANY ;682EOF ::= !ANY ;