From 351b5ba7202b64923713eef5e6a669ba29b6bc26 Mon Sep 17 00:00:00 2001 From: Steve Dunham Date: Fri, 2 Sep 2022 07:35:19 -0700 Subject: [PATCH] [ parser ] Fix issue where Alt drops incoming commit tag --- libs/contrib/Text/Parser/Core.idr | 2 +- src/Libraries/Text/Parser/Core.idr | 2 +- tests/idris2/perror016/ParseIf2.idr | 5 +++++ tests/idris2/perror016/expected | 11 +++++++++++ tests/idris2/perror016/run | 1 + tests/idris2/with003/expected | 8 ++++---- 6 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 tests/idris2/perror016/ParseIf2.idr diff --git a/libs/contrib/Text/Parser/Core.idr b/libs/contrib/Text/Parser/Core.idr index e508ac450..93db72bb9 100644 --- a/libs/contrib/Text/Parser/Core.idr +++ b/libs/contrib/Text/Parser/Core.idr @@ -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 diff --git a/src/Libraries/Text/Parser/Core.idr b/src/Libraries/Text/Parser/Core.idr index d08f697e6..af067044c 100644 --- a/src/Libraries/Text/Parser/Core.idr +++ b/src/Libraries/Text/Parser/Core.idr @@ -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 diff --git a/tests/idris2/perror016/ParseIf2.idr b/tests/idris2/perror016/ParseIf2.idr new file mode 100644 index 000000000..572d43d73 --- /dev/null +++ b/tests/idris2/perror016/ParseIf2.idr @@ -0,0 +1,5 @@ + +test : Int -> Int +test a = if a < 10 + then if a < 0 the 0 else 5 + else a diff --git a/tests/idris2/perror016/expected b/tests/idris2/perror016/expected index 1ada435c2..2db05dbea 100644 --- a/tests/idris2/perror016/expected +++ b/tests/idris2/perror016/expected @@ -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) diff --git a/tests/idris2/perror016/run b/tests/idris2/perror016/run index e79281599..6ab809d70 100755 --- a/tests/idris2/perror016/run +++ b/tests/idris2/perror016/run @@ -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 diff --git a/tests/idris2/with003/expected b/tests/idris2/with003/expected index 78a67d9ef..48db416b2 100644 --- a/tests/idris2/with003/expected +++ b/tests/idris2/with003/expected @@ -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!