File tree 6 files changed +62550
-61582
lines changed
6 files changed +62550
-61582
lines changed Original file line number Diff line number Diff line change @@ -753,3 +753,53 @@ const a : A = unsafe { foo() };
753
753
(identifier)
754
754
(type_identifier)
755
755
(unsafe_block (block (call_expression (identifier) (arguments))))))
756
+
757
+ ===========================================
758
+ Inline const or Const blocks as expression
759
+ ===========================================
760
+
761
+ const { 1 + 3 };
762
+ if *x < 0 { const { &4i32.pow(4) } } else { x }
763
+ let three_ranges = [const { (0..=5).into_inner() }; 3];
764
+
765
+ ---
766
+
767
+ (source_file
768
+ (const_block
769
+ body: (block
770
+ (binary_expression
771
+ left: (integer_literal)
772
+ right: (integer_literal))))
773
+ (empty_statement)
774
+ (if_expression
775
+ condition: (binary_expression
776
+ left: (unary_expression
777
+ (identifier))
778
+ right: (integer_literal))
779
+ consequence: (block
780
+ (const_block
781
+ body: (block
782
+ (reference_expression
783
+ value: (call_expression
784
+ function: (field_expression
785
+ value: (integer_literal)
786
+ field: (field_identifier))
787
+ arguments: (arguments
788
+ (integer_literal)))))))
789
+ alternative: (else_clause
790
+ (block
791
+ (identifier))))
792
+ (let_declaration
793
+ pattern: (identifier)
794
+ value: (array_expression
795
+ (const_block
796
+ body: (block
797
+ (call_expression
798
+ function: (field_expression
799
+ value: (parenthesized_expression
800
+ (range_expression
801
+ (integer_literal)
802
+ (integer_literal)))
803
+ field: (field_identifier))
804
+ arguments: (arguments))))
805
+ length: (integer_literal))))
Original file line number Diff line number Diff line change @@ -310,3 +310,82 @@ fn foo((1 | 2 | 3): u8) {}
310
310
(line_comment)
311
311
(line_comment)
312
312
(line_comment))
313
+
314
+ ===========================================
315
+ Inline const or Const blocks as pattern
316
+ ===========================================
317
+
318
+ fn foo(x: i32) {
319
+ const CUBE: i32 = 3.pow(3);
320
+ match x {
321
+ CUBE => println!("three cubed"),
322
+ _ => {}
323
+ }
324
+ }
325
+
326
+ fn foo(x: i32) {
327
+ match x {
328
+ const { 3.pow(3) } => println!("three cubed"),
329
+ _ => {}
330
+ }
331
+ }
332
+
333
+ ---
334
+
335
+ (source_file
336
+ (function_item
337
+ name: (identifier)
338
+ parameters: (parameters
339
+ (parameter
340
+ pattern: (identifier)
341
+ type: (primitive_type)))
342
+ body: (block
343
+ (const_item
344
+ name: (identifier)
345
+ type: (primitive_type)
346
+ value: (call_expression
347
+ function: (field_expression
348
+ value: (integer_literal)
349
+ field: (field_identifier))
350
+ arguments: (arguments
351
+ (integer_literal))))
352
+ (match_expression
353
+ value: (identifier)
354
+ body: (match_block
355
+ (match_arm
356
+ pattern: (match_pattern
357
+ (identifier))
358
+ value: (macro_invocation
359
+ macro: (identifier)
360
+ (token_tree
361
+ (string_literal))))
362
+ (match_arm
363
+ pattern: (match_pattern)
364
+ value: (block))))))
365
+ (function_item
366
+ name: (identifier)
367
+ parameters: (parameters
368
+ (parameter
369
+ pattern: (identifier)
370
+ type: (primitive_type)))
371
+ body: (block
372
+ (match_expression
373
+ value: (identifier)
374
+ body: (match_block
375
+ (match_arm
376
+ pattern: (match_pattern
377
+ (const_block
378
+ body: (block
379
+ (call_expression
380
+ function: (field_expression
381
+ value: (integer_literal)
382
+ field: (field_identifier))
383
+ arguments: (arguments
384
+ (integer_literal))))))
385
+ value: (macro_invocation
386
+ macro: (identifier)
387
+ (token_tree
388
+ (string_literal))))
389
+ (match_arm
390
+ pattern: (match_pattern)
391
+ value: (block)))))))
Original file line number Diff line number Diff line change @@ -870,7 +870,8 @@ module.exports = grammar({
870
870
$ . while_expression ,
871
871
$ . while_let_expression ,
872
872
$ . loop_expression ,
873
- $ . for_expression
873
+ $ . for_expression ,
874
+ $ . const_block
874
875
) ,
875
876
876
877
macro_invocation : $ => seq (
@@ -1160,6 +1161,11 @@ module.exports = grammar({
1160
1161
field ( 'body' , $ . block )
1161
1162
) ,
1162
1163
1164
+ const_block : $ => seq (
1165
+ 'const' ,
1166
+ field ( 'body' , $ . block )
1167
+ ) ,
1168
+
1163
1169
closure_expression : $ => prec ( PREC . closure , seq (
1164
1170
optional ( 'move' ) ,
1165
1171
field ( 'parameters' , $ . closure_parameters ) ,
@@ -1240,6 +1246,7 @@ module.exports = grammar({
1240
1246
$ . mut_pattern ,
1241
1247
$ . range_pattern ,
1242
1248
$ . or_pattern ,
1249
+ $ . const_block ,
1243
1250
'_'
1244
1251
) ,
1245
1252
Original file line number Diff line number Diff line change 4829
4829
{
4830
4830
"type" : " SYMBOL" ,
4831
4831
"name" : " for_expression"
4832
+ },
4833
+ {
4834
+ "type" : " SYMBOL" ,
4835
+ "name" : " const_block"
4832
4836
}
4833
4837
]
4834
4838
},
6698
6702
}
6699
6703
]
6700
6704
},
6705
+ "const_block" : {
6706
+ "type" : " SEQ" ,
6707
+ "members" : [
6708
+ {
6709
+ "type" : " STRING" ,
6710
+ "value" : " const"
6711
+ },
6712
+ {
6713
+ "type" : " FIELD" ,
6714
+ "name" : " body" ,
6715
+ "content" : {
6716
+ "type" : " SYMBOL" ,
6717
+ "name" : " block"
6718
+ }
6719
+ }
6720
+ ]
6721
+ },
6701
6722
"closure_expression" : {
6702
6723
"type" : " PREC" ,
6703
6724
"value" : -1 ,
7208
7229
"type" : " SYMBOL" ,
7209
7230
"name" : " or_pattern"
7210
7231
},
7232
+ {
7233
+ "type" : " SYMBOL" ,
7234
+ "name" : " const_block"
7235
+ },
7211
7236
{
7212
7237
"type" : " STRING" ,
7213
7238
"value" : " _"
Original file line number Diff line number Diff line change 137
137
"type" : " compound_assignment_expr" ,
138
138
"named" : true
139
139
},
140
+ {
141
+ "type" : " const_block" ,
142
+ "named" : true
143
+ },
140
144
{
141
145
"type" : " continue_expression" ,
142
146
"named" : true
327
331
"type" : " captured_pattern" ,
328
332
"named" : true
329
333
},
334
+ {
335
+ "type" : " const_block" ,
336
+ "named" : true
337
+ },
330
338
{
331
339
"type" : " identifier" ,
332
340
"named" : true
1015
1023
}
1016
1024
}
1017
1025
},
1026
+ {
1027
+ "type" : " const_block" ,
1028
+ "named" : true ,
1029
+ "fields" : {
1030
+ "body" : {
1031
+ "multiple" : false ,
1032
+ "required" : true ,
1033
+ "types" : [
1034
+ {
1035
+ "type" : " block" ,
1036
+ "named" : true
1037
+ }
1038
+ ]
1039
+ }
1040
+ }
1041
+ },
1018
1042
{
1019
1043
"type" : " const_item" ,
1020
1044
"named" : true ,
You can’t perform that action at this time.
0 commit comments