diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 12:02:23 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 12:02:23 +0100 |
| commit | 99e2ce71faa82e7b99574895e0fe24183ba9f6c3 (patch) | |
| tree | 10538bb91d187a3c1d281a87a3974a6036f2ad2f /lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs | |
| parent | 438e3f8c5dcdfeead15a6a9a1760f7c254fc54b2 (diff) | |
| download | lambda-nantes-99e2ce71faa82e7b99574895e0fe24183ba9f6c3.tar.gz | |
can parse whole programs and load them
Diffstat (limited to 'lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs')
| -rw-r--r-- | lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs b/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs index e6f05b9..932eff6 100644 --- a/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs +++ b/lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs @@ -10,7 +10,7 @@ import Data.Text (Text, pack) import qualified Data.Text as Text import Minilang.Lambda.Eval (Term (Lam)) import qualified Minilang.Lambda.Eval as Eval -import Minilang.Lambda.Parser (AST (..), desugar, initialChars, parse, pretty, restChars) +import Minilang.Lambda.Parser (AST (..), desugar, initialChars, parse, parseProgram, pretty, restChars) import Test.Hspec (Spec, it, parallel, shouldBe, shouldSatisfy) import Test.Hspec.QuickCheck (prop) import Test.QuickCheck @@ -103,6 +103,24 @@ spec = parallel $ do let text = pretty ast in parse text `shouldBe` Right ast + it "parses multiline program with blank lines" $ do + let program = + "(def id (lam (x) x))\n\ + \\n\ + \(def const (lam (x y) x))\n\ + \(def apply (lam (f x) (f x)))\n\ + \(apply id const)" + expected = + [ Def "id" (Abs ["x"] (Sym "x")), + Def "const" (Abs ["x", "y"] (Sym "x")), + Def "apply" (Abs ["f", "x"] (App (Sym "f") (Sym "x") [])), + App + (Sym "apply") + (Sym "id") + [Sym "const"] + ] + parseProgram program `shouldBe` Right expected + spine :: AST -> Int spine = \case App x _ rest -> 1 + spine x + length rest |
