From 43401156eb88481ee30a2cd6774ceb30d0ba07ec Mon Sep 17 00:00:00 2001 From: Steve Dunham Date: Sun, 18 Jan 2026 22:03:34 -0800 Subject: [PATCH] Fix error in parser combinator --- TODO.md | 6 ++++-- src/Lib/Parser/Impl.newt | 2 +- tests/ErrMsg2.newt | 6 ++++++ tests/ErrMsg2.newt.fail | 6 ++++++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/ErrMsg2.newt create mode 100644 tests/ErrMsg2.newt.fail diff --git a/TODO.md b/TODO.md index 443448e..9126f0e 100644 --- a/TODO.md +++ b/TODO.md @@ -2,9 +2,10 @@ ## TODO - [ ] maybe add fat arrows, I keep wanting to type them, `{{...}}` is a little ugly -- [ ] get some names on add missing cases (if not too difficult) + - There may be ambiguity issues +- [x] get some names on add missing cases (if not too difficult) - [x] add optional types to case `case xxx : Maybe Int of ...` -- [ ] "Expected keyword" at `\ a ->` should be error at the `->` +- [x] "Expected keyword" at `\ a ->` should be error at the `->` - [x] Show Either - [ ] `local` for `where`-like `let` clauses? (I want a `where` that closes over more stuff) - I can do `let f : ... = \ a b c => ...`. But it doesn't work for recursion and cases are awkward. @@ -18,6 +19,7 @@ - [ ] add missing cases should handle `_::_` - [ ] add missing cases should share code between vscode and playground - [ ] "Not in scope" should offer to import + - [ ] Case split - [ ] Delay checking - We have things like `foldr (\ x acc => case x : ...`, where the lambda doesn't have a good type, so we have to be explicit. If we could defer the checking of that expression until more things are solved, we might not need the annotation (e.g. checking the other arguments). Some `case` statements may have a similar situation. - One idea is to throw the checks onto some sort of TODO list and run whatever works. (I think Idris may have a heuristic where it checks arguments backwards in some cases.) diff --git a/src/Lib/Parser/Impl.newt b/src/Lib/Parser/Impl.newt index a7bac3e..10a4ab1 100644 --- a/src/Lib/Parser/Impl.newt +++ b/src/Lib/Parser/Impl.newt @@ -101,7 +101,7 @@ instance Applicative Parser where instance Alternative Parser where (P pa) <|> (P pb) = P $ \last toks com ops col => case pa last toks False ops col of - OK a last' toks' _ ops => OK a last' toks' com ops + OK a last' toks' com' ops => OK a last' toks' (com || com') ops -- Fail err last' toks' com ops => Fail err last' toks' com ops Fail err last' toks' True ops => Fail err last' toks' True ops Fail err last' toks' False ops => pb last toks com ops col diff --git a/tests/ErrMsg2.newt b/tests/ErrMsg2.newt new file mode 100644 index 0000000..526fcc4 --- /dev/null +++ b/tests/ErrMsg2.newt @@ -0,0 +1,6 @@ +module ErrMsg2 + +import Prelude + +foo : Nat → (Nat → Nat) +foo x = \ x -> x diff --git a/tests/ErrMsg2.newt.fail b/tests/ErrMsg2.newt.fail new file mode 100644 index 0000000..ea490da --- /dev/null +++ b/tests/ErrMsg2.newt.fail @@ -0,0 +1,6 @@ +*** Process tests/ErrMsg2.newt +module Prelude +module ErrMsg2 +ERROR at tests/ErrMsg2.newt:6:13--6:15: Expected '=>' at Keyword:-> + +Compile failed