fix: avoid choice nodes with LeadingIdentBehavior.both

This commit is contained in:
Sebastian Ullrich 2022-04-06 16:55:57 +02:00
parent e6954bb4f3
commit 80a92cceeb

View file

@ -1620,9 +1620,13 @@ def indexed {α : Type} (map : TokenMap α) (c : ParserContext) (s : ParserState
| none => find identKind
| LeadingIdentBehavior.both =>
match map.find? val with
| some as => match map.find? identKind with
| some as' => (s, as ++ as')
| _ => (s, as)
| some as =>
if val == identKind then
(s, as) -- avoid running the same parsers twice
else
match map.find? identKind with
| some as' => (s, as ++ as')
| _ => (s, as)
| none => find identKind
| Except.ok (Syntax.node _ k _) => find k
| Except.ok _ => (s, [])