From 99e2ce71faa82e7b99574895e0fe24183ba9f6c3 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Wed, 5 Nov 2025 12:02:23 +0100 Subject: can parse whole programs and load them --- .../haskell/test/Minilang/Lambda/ParserSpec.hs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lambda-calcul/haskell/test/Minilang/Lambda/ParserSpec.hs') 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 -- cgit v1.3.1