[ parser ] Fix issue where Alt drops incoming commit tag

This commit is contained in:
Steve Dunham 2022-09-02 07:35:19 -07:00 committed by G. Allais
parent 2e45902048
commit 351b5ba720
6 changed files with 23 additions and 6 deletions

View File

@ -329,7 +329,7 @@ doParse s com (Alt {c1} {c2} x y) xs
-- Only add the errors together if the second branch
-- is also non-committed and non-fatal.
then Failure com'' fatal' errs'
else Failure False False (errs ++ errs')
else Failure com False (errs ++ errs')
(Res s _ val xs) => Res s com val xs
-- Successfully parsed the first option, so use the outer commit flag
Res s _ val xs => Res s com val xs

View File

@ -355,7 +355,7 @@ doParse s ws com (Alt {c1} {c2} x y) xs
-- Only add the errors together if the second branch
-- is also non-committed and non-fatal.
then Failure com'' fatal' errs'
else Failure False False (errs ++ errs')
else Failure com False (errs ++ errs')
(Res s ws _ val xs) => Res s ws com val xs
-- Successfully parsed the first option, so use the outer commit flag
Res s ws _ val xs => Res s ws com val xs

View File

@ -0,0 +1,5 @@
test : Int -> Int
test a = if a < 10
then if a < 0 the 0 else 5
else a

View File

@ -8,3 +8,14 @@ ParseIf:3:26--3:30
3 | test a = if a < 10 the 0 else a
^^^^
... (14 others)
1/1: Building ParseIf2 (ParseIf2.idr)
Error: Couldn't parse any alternatives:
1: Expected 'then'.
ParseIf2:4:33--4:37
1 |
2 | test : Int -> Int
3 | test a = if a < 10
4 | then if a < 0 the 0 else 5
^^^^
... (28 others)

View File

@ -1,3 +1,4 @@
rm -rf build
$1 --no-color --console-width 0 --check ParseIf.idr || true
$1 --no-color --console-width 0 --check ParseIf2.idr || true

View File

@ -35,10 +35,10 @@ Mismatch between: Vect 0 ?elem and List ?a.
Main> the (Maybe Integer) (pure 4) : Maybe Integer
Main> Couldn't parse any alternatives:
1: Expected 'case', 'if', 'do', application or operator expression.
1: Expected namespaced name.
(Interactive):1:4--1:8
(Interactive):1:10--1:11
1 | :t with [] 4
^^^^
... (45 others)
^
... (16 others)
Main> Bye for now!