@@ -734,12 +734,23 @@ impl<'input> Parser<'input> {
734
734
// Parameters = Parameter { "," Parameter } .
735
735
fn parse_parameters ( & mut self ) -> Vec < ParameterType > {
736
736
let mut params = Vec :: < ParameterType > :: new ( ) ;
737
+ // keep track of the last token's byte offsets
738
+ let mut last = self . peek ( ) . start_offset ;
737
739
while self . more ( ) {
738
740
let parameter = self . parse_parameter_type ( ) ;
739
741
params. push ( parameter) ;
740
742
if self . peek ( ) . tok == TokenType :: Comma {
741
743
self . consume ( ) ;
742
744
}
745
+
746
+ // If we parse the same token twice in a row,
747
+ // it means we've hit a parse error, and that
748
+ // we're now in an infinite loop.
749
+ let this = self . peek ( ) . start_offset ;
750
+ if last == this {
751
+ break ;
752
+ }
753
+ last = this;
743
754
}
744
755
params
745
756
}
@@ -889,11 +900,22 @@ impl<'input> Parser<'input> {
889
900
self . consume ( ) ;
890
901
}
891
902
// check for more properties
903
+ // keep track of the last token's byte offsets
904
+ let mut last = self . peek ( ) . start_offset ;
892
905
while self . more ( ) {
893
906
properties. push ( self . parse_property_type ( ) ) ;
894
907
if self . peek ( ) . tok == TokenType :: Comma {
895
908
self . consume ( ) ;
896
909
}
910
+
911
+ // If we parse the same token twice in a row,
912
+ // it means we've hit a parse error, and that
913
+ // we're now in an infinite loop.
914
+ let this = self . peek ( ) . start_offset ;
915
+ if last == this {
916
+ break ;
917
+ }
918
+ last = this;
897
919
}
898
920
properties
899
921
}
@@ -1928,6 +1950,8 @@ impl<'input> Parser<'input> {
1928
1950
val,
1929
1951
comma: comma. comments,
1930
1952
} ] ;
1953
+ // keep track of the last token's byte offsets
1954
+ let mut last = self . peek ( ) . start_offset ;
1931
1955
while self . more ( ) {
1932
1956
let key = self . parse_expression ( ) ;
1933
1957
self . expect ( TokenType :: Colon ) ;
@@ -1940,6 +1964,15 @@ impl<'input> Parser<'input> {
1940
1964
_ => vec ! [ ] ,
1941
1965
} ;
1942
1966
items. push ( DictItem { key, val, comma } ) ;
1967
+
1968
+ // If we parse the same token twice in a row,
1969
+ // it means we've hit a parse error, and that
1970
+ // we're now in an infinite loop.
1971
+ let this = self . peek ( ) . start_offset ;
1972
+ if last == this {
1973
+ break ;
1974
+ }
1975
+ last = this;
1943
1976
}
1944
1977
let end = self . close ( TokenType :: RBrack ) ;
1945
1978
Expression :: Dict ( Box :: new ( DictExpr {
@@ -2066,6 +2099,8 @@ impl<'input> Parser<'input> {
2066
2099
}
2067
2100
_ => {
2068
2101
let mut expr = self . parse_expression_suffix ( Expression :: Identifier ( key) ) ;
2102
+ // keep track of the last token's byte offsets
2103
+ let mut last = self . peek ( ) . start_offset ;
2069
2104
while self . more ( ) {
2070
2105
let rhs = self . parse_expression ( ) ;
2071
2106
if let Expression :: Bad ( _) = rhs {
@@ -2084,6 +2119,15 @@ impl<'input> Parser<'input> {
2084
2119
left : expr,
2085
2120
right : rhs,
2086
2121
} ) ) ;
2122
+
2123
+ // If we parse the same token twice in a row,
2124
+ // it means we've hit a parse error, and that
2125
+ // we're now in an infinite loop.
2126
+ let this = self . peek ( ) . start_offset ;
2127
+ if last == this {
2128
+ break ;
2129
+ }
2130
+ last = this;
2087
2131
}
2088
2132
let rparen = self . close ( TokenType :: RParen ) ;
2089
2133
Expression :: Paren ( Box :: new ( ParenExpr {
@@ -2180,6 +2224,8 @@ impl<'input> Parser<'input> {
2180
2224
fn parse_property_list ( & mut self ) -> Vec < Property > {
2181
2225
let mut params = Vec :: new ( ) ;
2182
2226
let mut errs = Vec :: new ( ) ;
2227
+ // keep track of the last token's byte offsets
2228
+ let mut last = self . peek ( ) . start_offset ;
2183
2229
while self . more ( ) {
2184
2230
let t = self . peek ( ) ;
2185
2231
let mut p: Property = match t. tok {
@@ -2198,6 +2244,15 @@ impl<'input> Parser<'input> {
2198
2244
}
2199
2245
2200
2246
params. push ( p) ;
2247
+
2248
+ // If we parse the same token twice in a row,
2249
+ // it means we've hit a parse error, and that
2250
+ // we're now in an infinite loop.
2251
+ let this = self . peek ( ) . start_offset ;
2252
+ if last == this {
2253
+ break ;
2254
+ }
2255
+ last = this;
2201
2256
}
2202
2257
self . errs . append ( & mut errs) ;
2203
2258
params
@@ -2285,13 +2340,24 @@ impl<'input> Parser<'input> {
2285
2340
}
2286
2341
fn parse_parameter_list ( & mut self ) -> Vec < Property > {
2287
2342
let mut params = Vec :: new ( ) ;
2343
+ // keep track of the last token's byte offsets
2344
+ let mut last = self . peek ( ) . start_offset ;
2288
2345
while self . more ( ) {
2289
2346
let mut p = self . parse_parameter ( ) ;
2290
2347
if self . peek ( ) . tok == TokenType :: Comma {
2291
2348
let t = self . scan ( ) ;
2292
2349
p. comma = t. comments ;
2293
2350
} ;
2294
2351
params. push ( p) ;
2352
+
2353
+ // If we parse the same token twice in a row,
2354
+ // it means we've hit a parse error, and that
2355
+ // we're now in an infinite loop.
2356
+ let this = self . peek ( ) . start_offset ;
2357
+ if last == this {
2358
+ break ;
2359
+ }
2360
+ last = this;
2295
2361
}
2296
2362
params
2297
2363
}
@@ -2394,6 +2460,8 @@ impl<'input> Parser<'input> {
2394
2460
fn parse_attribute_params ( & mut self ) -> Vec < AttributeParam > {
2395
2461
let mut params = Vec :: new ( ) ;
2396
2462
let mut errs = Vec :: new ( ) ;
2463
+ // keep track of the last token's byte offsets
2464
+ let mut last = self . peek ( ) . start_offset ;
2397
2465
while self . more ( ) {
2398
2466
let value = self . parse_primary_expression ( ) ;
2399
2467
let start_pos = value. base ( ) . location . start ;
@@ -2420,6 +2488,15 @@ impl<'input> Parser<'input> {
2420
2488
comma : comments,
2421
2489
} ;
2422
2490
params. push ( param) ;
2491
+
2492
+ // If we parse the same token twice in a row,
2493
+ // it means we've hit a parse error, and that
2494
+ // we're now in an infinite loop.
2495
+ let this = self . peek ( ) . start_offset ;
2496
+ if last == this {
2497
+ break ;
2498
+ }
2499
+ last = this;
2423
2500
}
2424
2501
self . errs . append ( & mut errs) ;
2425
2502
params
0 commit comments