WIP parsec

This commit is contained in:
jackjohn7 2026-05-15 00:57:16 -05:00
parent 632b2c4a6a
commit 7df5b0eeac
3 changed files with 69 additions and 6 deletions

View file

@ -1,10 +1,49 @@
module ParserSpec (spec) where
import Parser (Expr (Abstraction, Variable), parse)
import Parser (Expr (Abstraction, Application, Variable), parse)
import Test.Hspec
spec :: Spec
spec = do
describe "Parser" $ do
it "can parse basic expressions" $
it "can parse variable" $
(parse "x") `shouldBe` Right (Variable "x")
it "can parse identity abstraction" $
(parse "λx.x") `shouldBe` Right (Abstraction ("x", Variable "x"))
it "can parse mockingbird of identity" $
(parse "(λx.x x) (λx.x)") -- (λx.x) (λx.x) -> (λx.x)
`shouldBe` Right
( Application
( Abstraction
( "x",
Application
( Variable "x",
Variable "x"
)
),
Abstraction ("x", Variable "x")
)
)
it "it can parse successor" $
(parse "λn.λf.λx.f (n f x)")
`shouldBe` Right
( Abstraction
( "n",
Abstraction
( "f",
Abstraction
( "x",
Application
( Variable "f",
Application
( Application
( Variable "n",
Variable "f"
),
Variable "x"
)
)
)
)
)
)