diff --git a/TODO.md b/TODO.md index 60d2a17..d9248f4 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,7 @@ ## TODO -- [ ] change "in prefix position" and "trailing operator" errors to do sections +- [x] change "in prefix position" and "trailing operator" errors to do sections - [ ] maybe add fat arrows, I keep wanting to type them, `{{...}}` is a little ugly - There may be ambiguity issues at the parsing level, but we don't have typecase, so... - [x] get some names on add missing cases (if not too difficult) @@ -211,7 +211,7 @@ - Makes inference easier, cleaner output, and allows `foo $ \ x => ...` - [ ] `$` no longer works inside ≡⟨ ⟩ - sort out how to support both that and `$ \ x => ...` (or don't bother) - We'd either need to blacklist all non-initial mixfix bits at the appropriate spots or always pass around a terminating token. - - I'm leaning towards _no_ here, because I may want to lift mixfix processing out of the parsing step in the future. This isn't + - I'm leaning towards _no_ here, because I may want to lift mixfix processing out of the parsing step in the future. - [x] **Translate newt to newt** - [x] Support @ on the LHS - [x] if / then / else sugar diff --git a/scripts/test b/scripts/test index ae44abf..0909682 100755 --- a/scripts/test +++ b/scripts/test @@ -30,7 +30,7 @@ for fn in tests/*.newt ; do fi # if there is a golden file, run the code and compare output if [ -f ${fn}.golden ]; then - bun run out.js > tmp/${bn}.out + node out.js > tmp/${bn}.out if [ $? != "0" ]; then echo Run failed for $fn failed=$((failed + 1)) diff --git a/src/Lib/Parser.newt b/src/Lib/Parser.newt index 712dd84..9883ff7 100644 --- a/src/Lib/Parser.newt +++ b/src/Lib/Parser.newt @@ -219,7 +219,11 @@ pratt ops prec stop left spine = do ((_, fc, right) :: rest) => do (right, rest) <- pratt ops pr stop right rest pratt ops prec stop (RApp (getFC left + getFC right) left right Explicit) rest - _ => fail "trailing operator" + _ => + -- Trailing operator section, like (2 +) + pratt ops prec stop left Nil + -- fail "trailing operator" + runRule p fix stop (nm :: rule) left spine = do case spine of @@ -240,8 +244,10 @@ pratt ops prec stop left spine = do -- TODO False should be an error here Just (MkOp name p fix True rule) => do runRule p fix stop rule (RVar fc name) spine - Just (MkOp name p fix False rule) => do - fail "got infix \{show name} in prefix position" + Just (MkOp name p fix False rule) => + -- REVIEW We could also use a lambda with a fresh name + runRule p fix stop rule (RApp fc (RVar fc "flip") (RVar fc name) Explicit) spine + -- fail "got infix \{show name} in prefix position" _ => pure (left, spine) runPrefix stop left spine = pure (left, spine) diff --git a/tests/ErrMsg.newt b/tests/ErrMsg.newt deleted file mode 100644 index e943018..0000000 --- a/tests/ErrMsg.newt +++ /dev/null @@ -1,14 +0,0 @@ -module ErrMsg - -import Prelude - -infixl 5 _$$_ - -_$$_ : Nat → (Nat → Nat) → Nat -a $$ b = a + b a - --- Say something other than expected record --- Why do we get there? shouldn't the progress made by parseDef short circuit the <|>? -blah : Nat → Nat -blah x = x $$ $ \ y => y - diff --git a/tests/ErrMsg.newt.fail b/tests/ErrMsg.newt.fail deleted file mode 100644 index 3c6909b..0000000 --- a/tests/ErrMsg.newt.fail +++ /dev/null @@ -1,6 +0,0 @@ -*** Process tests/ErrMsg.newt -module Prelude -module ErrMsg -ERROR at tests/ErrMsg.newt:13:15--13:16: trailing operator - -Compile failed diff --git a/tests/Section.newt b/tests/Section.newt new file mode 100644 index 0000000..798a87f --- /dev/null +++ b/tests/Section.newt @@ -0,0 +1,20 @@ +module Section + +import Prelude + +-- got infix in prefix position +add : Int → Int → Int +add = (+) + +add2 : Int → Int +add2 = (+ 2) + +-- trailing operator +add2' : Int → Int +add2' = (2 +) + +main : IO Unit +main = do + printLn $ (+) 2 3 + printLn $ (+ 3) 2 + printLn $ (2 +) 3 diff --git a/tests/Section.newt.golden b/tests/Section.newt.golden new file mode 100644 index 0000000..f6ba75d --- /dev/null +++ b/tests/Section.newt.golden @@ -0,0 +1,3 @@ +5 +5 +5 diff --git a/tests/TrailDollar.newt b/tests/TrailDollar.newt new file mode 100644 index 0000000..010ba2d --- /dev/null +++ b/tests/TrailDollar.newt @@ -0,0 +1,13 @@ +module TrailDollar + +import Prelude + +infixl 5 _$$_ + +_$$_ : Nat → (Nat → Nat) → Nat +a $$ b = a + b a + +-- Previously this didn't parse, but it does with operator section support. +blah : Nat → Nat +blah x = x $$ $ \ y => y +