Skip to content

Commit 5993f53

Browse files
authored
Merge pull request #127 from resolritter/range
Fix range parsing
2 parents c7c50d4 + 0a9f0b4 commit 5993f53

File tree

5 files changed

+61384
-60919
lines changed

5 files changed

+61384
-60919
lines changed

corpus/expressions.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ a..b;
128128
1..(1);
129129
(1)..1;
130130
(1)..(1);
131+
1..{1};
132+
for i in 1.. {
133+
}
131134

132135
---
133136

@@ -146,7 +149,16 @@ a..b;
146149
(integer_literal))
147150
(range_expression
148151
(parenthesized_expression (integer_literal))
149-
(parenthesized_expression (integer_literal))))
152+
(parenthesized_expression (integer_literal)))
153+
(range_expression
154+
(integer_literal)
155+
(block
156+
(integer_literal)))
157+
(for_expression
158+
(identifier)
159+
(range_expression
160+
(integer_literal))
161+
(block)))
150162

151163
============================================
152164
Assignment expressions

grammar.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -831,15 +831,14 @@ module.exports = grammar({
831831

832832
// Section - Expressions
833833

834-
_expression: $ => choice(
834+
_expression_except_range: $ => choice(
835835
$.unary_expression,
836836
$.reference_expression,
837837
$.try_expression,
838838
$.binary_expression,
839839
$.assignment_expression,
840840
$.compound_assignment_expr,
841841
$.type_cast_expression,
842-
$.range_expression,
843842
$.call_expression,
844843
$.return_expression,
845844
$.yield_expression,
@@ -856,14 +855,19 @@ module.exports = grammar({
856855
$.tuple_expression,
857856
prec(1, $.macro_invocation),
858857
$.unit_expression,
859-
$._expression_ending_with_block,
860858
$.break_expression,
861859
$.continue_expression,
862860
$.index_expression,
863861
$.metavariable,
864862
$.closure_expression,
865863
$.parenthesized_expression,
866-
$.struct_expression
864+
$.struct_expression,
865+
$._expression_ending_with_block,
866+
),
867+
868+
_expression: $ => choice(
869+
$._expression_except_range,
870+
$.range_expression,
867871
),
868872

869873
_expression_ending_with_block: $ => choice(
@@ -921,10 +925,7 @@ module.exports = grammar({
921925
),
922926

923927
range_expression: $ => prec.left(PREC.range, choice(
924-
prec.left(
925-
PREC.range + 1,
926-
seq($._expression, choice('..', '...', '..='), $._expression)
927-
),
928+
seq($._expression, choice('..', '...', '..='), $._expression),
928929
seq($._expression, '..'),
929930
seq('..', $._expression),
930931
'..'
@@ -995,7 +996,7 @@ module.exports = grammar({
995996
),
996997

997998
call_expression: $ => prec(PREC.call, seq(
998-
field('function', $._expression),
999+
field('function', $._expression_except_range),
9991000
field('arguments', $.arguments)
10001001
)),
10011002

src/grammar.json

+47-42
Original file line numberDiff line numberDiff line change
@@ -4622,7 +4622,7 @@
46224622
"type": "STRING",
46234623
"value": "mut"
46244624
},
4625-
"_expression": {
4625+
"_expression_except_range": {
46264626
"type": "CHOICE",
46274627
"members": [
46284628
{
@@ -4653,10 +4653,6 @@
46534653
"type": "SYMBOL",
46544654
"name": "type_cast_expression"
46554655
},
4656-
{
4657-
"type": "SYMBOL",
4658-
"name": "range_expression"
4659-
},
46604656
{
46614657
"type": "SYMBOL",
46624658
"name": "call_expression"
@@ -4807,10 +4803,6 @@
48074803
"type": "SYMBOL",
48084804
"name": "unit_expression"
48094805
},
4810-
{
4811-
"type": "SYMBOL",
4812-
"name": "_expression_ending_with_block"
4813-
},
48144806
{
48154807
"type": "SYMBOL",
48164808
"name": "break_expression"
@@ -4838,6 +4830,23 @@
48384830
{
48394831
"type": "SYMBOL",
48404832
"name": "struct_expression"
4833+
},
4834+
{
4835+
"type": "SYMBOL",
4836+
"name": "_expression_ending_with_block"
4837+
}
4838+
]
4839+
},
4840+
"_expression": {
4841+
"type": "CHOICE",
4842+
"members": [
4843+
{
4844+
"type": "SYMBOL",
4845+
"name": "_expression_except_range"
4846+
},
4847+
{
4848+
"type": "SYMBOL",
4849+
"name": "range_expression"
48414850
}
48424851
]
48434852
},
@@ -5088,38 +5097,34 @@
50885097
"type": "CHOICE",
50895098
"members": [
50905099
{
5091-
"type": "PREC_LEFT",
5092-
"value": 16,
5093-
"content": {
5094-
"type": "SEQ",
5095-
"members": [
5096-
{
5097-
"type": "SYMBOL",
5098-
"name": "_expression"
5099-
},
5100-
{
5101-
"type": "CHOICE",
5102-
"members": [
5103-
{
5104-
"type": "STRING",
5105-
"value": ".."
5106-
},
5107-
{
5108-
"type": "STRING",
5109-
"value": "..."
5110-
},
5111-
{
5112-
"type": "STRING",
5113-
"value": "..="
5114-
}
5115-
]
5116-
},
5117-
{
5118-
"type": "SYMBOL",
5119-
"name": "_expression"
5120-
}
5121-
]
5122-
}
5100+
"type": "SEQ",
5101+
"members": [
5102+
{
5103+
"type": "SYMBOL",
5104+
"name": "_expression"
5105+
},
5106+
{
5107+
"type": "CHOICE",
5108+
"members": [
5109+
{
5110+
"type": "STRING",
5111+
"value": ".."
5112+
},
5113+
{
5114+
"type": "STRING",
5115+
"value": "..."
5116+
},
5117+
{
5118+
"type": "STRING",
5119+
"value": "..="
5120+
}
5121+
]
5122+
},
5123+
{
5124+
"type": "SYMBOL",
5125+
"name": "_expression"
5126+
}
5127+
]
51235128
},
51245129
{
51255130
"type": "SEQ",
@@ -5787,7 +5792,7 @@
57875792
"name": "function",
57885793
"content": {
57895794
"type": "SYMBOL",
5790-
"name": "_expression"
5795+
"name": "_expression_except_range"
57915796
}
57925797
},
57935798
{

src/node-types.json

+153-1
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,159 @@
888888
"required": true,
889889
"types": [
890890
{
891-
"type": "_expression",
891+
"type": "_literal",
892+
"named": true
893+
},
894+
{
895+
"type": "array_expression",
896+
"named": true
897+
},
898+
{
899+
"type": "assignment_expression",
900+
"named": true
901+
},
902+
{
903+
"type": "async_block",
904+
"named": true
905+
},
906+
{
907+
"type": "await_expression",
908+
"named": true
909+
},
910+
{
911+
"type": "binary_expression",
912+
"named": true
913+
},
914+
{
915+
"type": "block",
916+
"named": true
917+
},
918+
{
919+
"type": "break_expression",
920+
"named": true
921+
},
922+
{
923+
"type": "call_expression",
924+
"named": true
925+
},
926+
{
927+
"type": "closure_expression",
928+
"named": true
929+
},
930+
{
931+
"type": "compound_assignment_expr",
932+
"named": true
933+
},
934+
{
935+
"type": "const_block",
936+
"named": true
937+
},
938+
{
939+
"type": "continue_expression",
940+
"named": true
941+
},
942+
{
943+
"type": "field_expression",
944+
"named": true
945+
},
946+
{
947+
"type": "for_expression",
948+
"named": true
949+
},
950+
{
951+
"type": "generic_function",
952+
"named": true
953+
},
954+
{
955+
"type": "identifier",
956+
"named": true
957+
},
958+
{
959+
"type": "if_expression",
960+
"named": true
961+
},
962+
{
963+
"type": "if_let_expression",
964+
"named": true
965+
},
966+
{
967+
"type": "index_expression",
968+
"named": true
969+
},
970+
{
971+
"type": "loop_expression",
972+
"named": true
973+
},
974+
{
975+
"type": "macro_invocation",
976+
"named": true
977+
},
978+
{
979+
"type": "match_expression",
980+
"named": true
981+
},
982+
{
983+
"type": "metavariable",
984+
"named": true
985+
},
986+
{
987+
"type": "parenthesized_expression",
988+
"named": true
989+
},
990+
{
991+
"type": "reference_expression",
992+
"named": true
993+
},
994+
{
995+
"type": "return_expression",
996+
"named": true
997+
},
998+
{
999+
"type": "scoped_identifier",
1000+
"named": true
1001+
},
1002+
{
1003+
"type": "self",
1004+
"named": true
1005+
},
1006+
{
1007+
"type": "struct_expression",
1008+
"named": true
1009+
},
1010+
{
1011+
"type": "try_expression",
1012+
"named": true
1013+
},
1014+
{
1015+
"type": "tuple_expression",
1016+
"named": true
1017+
},
1018+
{
1019+
"type": "type_cast_expression",
1020+
"named": true
1021+
},
1022+
{
1023+
"type": "unary_expression",
1024+
"named": true
1025+
},
1026+
{
1027+
"type": "unit_expression",
1028+
"named": true
1029+
},
1030+
{
1031+
"type": "unsafe_block",
1032+
"named": true
1033+
},
1034+
{
1035+
"type": "while_expression",
1036+
"named": true
1037+
},
1038+
{
1039+
"type": "while_let_expression",
1040+
"named": true
1041+
},
1042+
{
1043+
"type": "yield_expression",
8921044
"named": true
8931045
}
8941046
]

0 commit comments

Comments
 (0)