11{-# LANGUAGE OverloadedStrings #-}
2- {-# OPTIONS_GHC -fno-warn-orphans #-}
3-
42module Main (main ) where
53
64import Data.String
@@ -22,19 +20,17 @@ import Data.Term
2220
2321-- * Helpers
2422
25- true , false :: Term Core Name
26- true = Bool True
27- false = Bool False
28-
29- instance IsString Name where fromString = User . fromString
23+ true , false :: Term Core User
24+ true = bool True
25+ false = bool False
3026
3127parseEither :: Trifecta. Parser a -> String -> Either String a
3228parseEither p = Trifecta. foldResult (Left . show . Trifecta. _errDoc) Right . Trifecta. parseString (p <* Trifecta. eof) mempty
3329
3430-- * Parser roundtripping properties. Note that parsing and prettyprinting is generally
3531-- not a roundtrip, because the parser inserts 'Ann' nodes itself.
3632
37- prop_roundtrips :: Gen (Term Core Name ) -> Property
33+ prop_roundtrips :: Gen (Term Core User ) -> Property
3834prop_roundtrips gen = property $ do
3935 input <- forAll gen
4036 tripping input showCore (parseEither (Parse. core <* Trifecta. eof))
@@ -49,7 +45,7 @@ parserProps = testGroup "Parsing: roundtripping"
4945
5046-- * Parser specs
5147
52- parsesInto :: String -> Term Core Name -> Assertion
48+ parsesInto :: String -> Term Core User -> Assertion
5349parsesInto str res = case parseEither Parse. core str of
5450 Right x -> x @?= res
5551 Left m -> assertFailure m
@@ -59,35 +55,35 @@ assert_booleans_parse = do
5955 parseEither Parse. core " #true" @?= Right true
6056 parseEither Parse. core " #false" @?= Right false
6157
62- a , f , g , h :: Term Core Name
63- (a, f, g, h) = (Var " a" , Var " f" , Var " g" , Var " h" )
58+ a , f , g , h :: Term Core User
59+ (a, f, g, h) = (pure " a" , pure " f" , pure " g" , pure " h" )
6460
6561assert_ifthen_parse :: Assertion
66- assert_ifthen_parse = " if #true then #true else #false" `parsesInto` (If true true false)
62+ assert_ifthen_parse = " if #true then #true else #false" `parsesInto` (if' true true false)
6763
6864assert_application_parse :: Assertion
69- assert_application_parse = " f g" `parsesInto` (f : $ g)
65+ assert_application_parse = " f g" `parsesInto` (f $ $ g)
7066
7167assert_application_left_associative :: Assertion
72- assert_application_left_associative = " f g h" `parsesInto` (f :$ g : $ h)
68+ assert_application_left_associative = " f g h" `parsesInto` (f $$ g $ $ h)
7369
7470assert_push_left_associative :: Assertion
75- assert_push_left_associative = " f.g.h" `parsesInto` (f :. g : . h)
71+ assert_push_left_associative = " f.g.h" `parsesInto` (f ... g .. . h)
7672
7773assert_ascii_lambda_parse :: Assertion
78- assert_ascii_lambda_parse = " \\ a -> a" `parsesInto` Lam " a" a
74+ assert_ascii_lambda_parse = " \\ a -> a" `parsesInto` lam (named' " a" ) a
7975
8076assert_unicode_lambda_parse :: Assertion
81- assert_unicode_lambda_parse = " λa → a" `parsesInto` Lam " a" a
77+ assert_unicode_lambda_parse = " λa → a" `parsesInto` lam (named' " a" ) a
8278
8379assert_quoted_name_parse :: Assertion
84- assert_quoted_name_parse = " #{(NilClass)}" `parsesInto` Var ( User " (NilClass)" )
80+ assert_quoted_name_parse = " #{(NilClass)}" `parsesInto` pure " (NilClass)"
8581
8682assert_let_dot_precedence :: Assertion
87- assert_let_dot_precedence = " let a = f.g.h" `parsesInto` (Let " a" : = (f :. g : . h))
83+ assert_let_dot_precedence = " let a = f.g.h" `parsesInto` (let' " a" . = (f ... g .. . h))
8884
8985assert_let_in_push_precedence :: Assertion
90- assert_let_in_push_precedence = " f.let g = h" `parsesInto` (f :. ( Let " g" : = h))
86+ assert_let_in_push_precedence = " f.let g = h" `parsesInto` (f ... (let' " g" . = h))
9187
9288parserSpecs :: TestTree
9389parserSpecs = testGroup " Parsing: simple specs"
@@ -103,8 +99,8 @@ parserSpecs = testGroup "Parsing: simple specs"
10399 , testCase " let in push" assert_let_in_push_precedence
104100 ]
105101
106- assert_roundtrips :: File (Term Core Name ) -> Assertion
107- assert_roundtrips (File _ core) = parseEither Parse. core (showCore core) @?= Right (stripAnnotations core)
102+ assert_roundtrips :: File (Term Core User ) -> Assertion
103+ assert_roundtrips (File _ core) = parseEither Parse. core (showCore core) @?= Right core
108104
109105parserExamples :: TestTree
110106parserExamples = testGroup " Parsing: Eval.hs examples"
0 commit comments