@@ -282,11 +282,18 @@ private RegExpTerm parseQuantifierOpt(SourceLocation loc, RegExpTerm atom) {
282282 if (this .match ("+" )) return this .finishTerm (new Plus (loc , atom , !this .match ("?" )));
283283 if (this .match ("?" )) return this .finishTerm (new Opt (loc , atom , !this .match ("?" )));
284284 if (this .match ("{" )) {
285- Double lo = toNumber (this .readDigits (false )), hi ;
285+ String matched = "{" ; // keeping track of the string matched so far, in case this turns out not to be a quantifier.
286+ String digits = this .readDigits (false );
287+ matched += digits ;
288+ Double lo = toNumber (digits ), hi ;
289+ int prevPos = this .pos ;
286290 if (this .match ("," )) {
291+ matched += "," ;
287292 if (!this .lookahead ("}" )) {
288293 // atom{lo, hi}
289- hi = toNumber (this .readDigits (false ));
294+ digits = this .readDigits (false );
295+ matched += digits ;
296+ hi = toNumber (digits );
290297 } else {
291298 // atom{lo,}
292299 hi = null ;
@@ -295,7 +302,11 @@ private RegExpTerm parseQuantifierOpt(SourceLocation loc, RegExpTerm atom) {
295302 // atom{lo}
296303 hi = lo ;
297304 }
298- this .expectRBrace ();
305+ if (!this .match ("}" )) {
306+ // Not a quantifier, just parsing it as a constant.
307+ // E.g. a Regexp such as `/a{|X/`, where there is no matching `}`.
308+ return this .finishTerm (new Sequence (loc , Arrays .asList (atom , new Constant (loc , matched ))));
309+ }
299310 return this .finishTerm (new Range (loc , atom , !this .match ("?" ), lo , hi ));
300311 }
301312 return atom ;
0 commit comments