fix: do not create choice nodes for failed parses

This commit is contained in:
Sebastian Ullrich 2022-11-04 10:10:49 +01:00
parent 57320712f0
commit 246923886a
3 changed files with 6 additions and 2 deletions

View file

@ -1389,8 +1389,7 @@ def keepPrevError (s : ParserState) (oldStackSize : Nat) (oldStopPos : String.Po
def mergeErrors (s : ParserState) (oldStackSize : Nat) (oldError : Error) : ParserState :=
match s with
| ⟨stack, lhsPrec, pos, cache, some err⟩ =>
if oldError == err then s
else ⟨stack.shrink oldStackSize, lhsPrec, pos, cache, some (oldError.merge err)⟩
⟨stack.shrink oldStackSize, lhsPrec, pos, cache, if oldError == err then some err else some (oldError.merge err)⟩
| other => other
def keepLatest (s : ParserState) (startStackSize : Nat) : ParserState :=

3
tests/lean/1760.lean Normal file
View file

@ -0,0 +1,3 @@
-- should run in linear time
#check [[[[[[[[[[[[[[[[[[[[[[[[
#check (((((((((((((((((((((((())))))))))))))))))))))))

View file

@ -0,0 +1,2 @@
1760.lean:3:0: error: expected ':', ']' or term
() : Unit