feat(library/init/lean/parser/parser): change optional p behavior
It ignores error only if `p` does not consume any input. This change improves the quality of the error messages. The previous behavior can be obtained by using `optional (try p)`.
This commit is contained in:
parent
9d50b3ca47
commit
ee2d3faa63
1 changed files with 1 additions and 1 deletions
|
|
@ -276,7 +276,7 @@ instance hashOrelse {k : ParserKind} : HasOrelse (Parser k) :=
|
|||
let iniSz := s.stackSize;
|
||||
let iniPos := s.pos;
|
||||
let s := p a c s;
|
||||
let s := if s.hasError then s.restore iniSz iniPos else s;
|
||||
let s := if s.hasError && s.pos == iniPos then s.restore iniSz iniPos else s;
|
||||
s.mkNode nullKind iniSz
|
||||
|
||||
@[inline] def optional {k : ParserKind} (p : Parser k) : Parser k :=
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue