git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
First attempt at reconciling user defined operators with modules
commit6deb41c8924e6e89bf020b95adee847fd8246e4e authorPhil Freeman <paf31@cantab.net> dateWed 13 Nov 2013, 22:36 (13 years ago) parent5bc25c9
12 files changed+206−93
purescript.cabal+12−12 src/Data/Generics/Extras.hs+24 src/Language/PureScript.hs+11−2 src/Language/PureScript/Operators.hs+128 src/Language/PureScript/Parser/Common.hs+8−5 src/Language/PureScript/Parser/Declarations.hs−3 src/Language/PureScript/Parser/State.hs+1−2 src/Language/PureScript/Parser/Values.hs+6−48 src/Language/PureScript/TypeChecker/Synonyms.hs+1−7 src/Language/PureScript/Values.hs+2 src/Main.hs+7−8 tests/Main.hs+6−6
purescript.cabal+12−12
@@ -17,17 +17,17 @@ library
1717 build-depends: base >=4 && <5, syb -any, cmdtheline -any,
1818 containers -any, mtl -any, transformers -any, parsec -any,
1919 utf8-string -any
20− exposed-modules: Language.PureScript.Optimize
21− Language.PureScript.Pretty.JS Language.PureScript.CodeGen.JS.AST
22− Main Language.PureScript Language.PureScript.Declarations
23− Language.PureScript.Names Language.PureScript.Types
24− Language.PureScript.Values Language.PureScript.Kinds
25− Language.PureScript.Pretty Language.PureScript.Pretty.Common
26− Language.PureScript.Pretty.Values Language.PureScript.Pretty.Types
27− Language.PureScript.Pretty.Kinds Language.PureScript.CodeGen
28− Language.PureScript.CodeGen.Externs Language.PureScript.CodeGen.JS
29− Language.PureScript.CodeGen.Monad Language.PureScript.Parser
30− Language.PureScript.Parser.Common
20+ exposed-modules: Data.Generics.Extras Language.PureScript.Operators
21+ Language.PureScript.Optimize Language.PureScript.Pretty.JS
22+ Language.PureScript.CodeGen.JS.AST Main Language.PureScript
23+ Language.PureScript.Declarations Language.PureScript.Names
24+ Language.PureScript.Types Language.PureScript.Values
25+ Language.PureScript.Kinds Language.PureScript.Pretty
26+ Language.PureScript.Pretty.Common Language.PureScript.Pretty.Values
27+ Language.PureScript.Pretty.Types Language.PureScript.Pretty.Kinds
28+ Language.PureScript.CodeGen Language.PureScript.CodeGen.Externs
29+ Language.PureScript.CodeGen.JS Language.PureScript.CodeGen.Monad
30+ Language.PureScript.Parser Language.PureScript.Parser.Common
3131 Language.PureScript.Parser.Declarations
3232 Language.PureScript.Parser.Types Language.PureScript.Parser.Values
3333 Language.PureScript.Parser.State Language.PureScript.Parser.Kinds
@@ -47,7 +47,7 @@ executable psc
4747 main-is: Main.hs
4848 buildable: True
4949 hs-source-dirs: src
50− other-modules: Language.PureScript.Optimize
50+ other-modules:
5151
5252test-suite tests
5353 build-depends: base >=4 && <5, syb -any, directory -any,
src/Data/Generics/Extras.hsnew file+24
@@ -0,0 +1,24 @@
1+-----------------------------------------------------------------------------
2+--
3+-- Module : Data.Generics.Extras
4+-- Copyright : (c) Phil Freeman 2013
5+-- License : MIT
6+--
7+-- Maintainer : Phil Freeman <paf31@cantab.net>
8+-- Stability : experimental
9+-- Portability :
10+--
11+-- |
12+--
13+-----------------------------------------------------------------------------
14+
15+{-# LANGUAGE Rank2Types #-}
16+
17+module Data.Generics.Extras where
18+
19+import Data.Data
20+
21+everywhereM' :: (Monad m, Data d) => (forall d. (Data d) => d -> m d) -> d -> m d
22+everywhereM' f x = do
23+ y <- f x
24+ gmapM (everywhereM' f) y
src/Language/PureScript.hs+11−2
@@ -12,7 +12,7 @@
1212--
1313-----------------------------------------------------------------------------
1414
15−module Language.PureScript (module P) where
15+module Language.PureScript (module P, compile) where
1616
1717import Language.PureScript.Values as P
1818import Language.PureScript.Types as P
@@ -24,6 +24,15 @@ import Language.PureScript.CodeGen as P
2424import Language.PureScript.TypeChecker as P
2525import Language.PureScript.Pretty as P
2626import Language.PureScript.Optimize as P
27+import Language.PureScript.Operators as P
2728
29+import Data.List (intercalate)
30+import Data.Maybe (mapMaybe)
2831
29−
32+compile :: [Declaration] -> Either String (String, String, Environment)
33+compile decls = do
34+ bracketted <- rebracket decls
35+ (_, env) <- check (typeCheckAll bracketted)
36+ let js = intercalate "; " . map (prettyPrintJS . optimize) . concat . mapMaybe (declToJs Nothing global) $ bracketted
37+ let exts = intercalate "\n" . mapMaybe (externToPs 0 global env) $ bracketted
38+ return (js, exts, env)
src/Language/PureScript/Operators.hsnew file+128
@@ -0,0 +1,128 @@
1+-----------------------------------------------------------------------------
2+--
3+-- Module : Language.PureScript.Operators
4+-- Copyright : (c) Phil Freeman 2013
5+-- License : MIT
6+--
7+-- Maintainer : Phil Freeman <paf31@cantab.net>
8+-- Stability : experimental
9+-- Portability :
10+--
11+-- |
12+--
13+-----------------------------------------------------------------------------
14+
15+{-# LANGUAGE Rank2Types #-}
16+
17+module Language.PureScript.Operators (
18+ rebracket
19+) where
20+
21+import Language.PureScript.Names
22+import Language.PureScript.Declarations
23+import Language.PureScript.Values
24+
25+import qualified Data.Data as D
26+import Data.Function (on)
27+import Data.List (groupBy, sortBy)
28+import qualified Data.Map as M
29+import qualified Data.Generics as G
30+import qualified Data.Generics.Extras as G
31+import Control.Monad.State
32+import Control.Applicative
33+import qualified Text.Parsec as P
34+import qualified Text.Parsec.Pos as P
35+import qualified Text.Parsec.Expr as P
36+
37+rebracket :: [Declaration] -> Either String [Declaration]
38+rebracket ds = do
39+ m <- collectFixities ds
40+ let opTable = customOperatorTable m
41+ ds' <- G.everywhereM (G.mkM (matchOperators opTable)) ds
42+ return $ G.everywhere (G.mkT removeParens) ds'
43+
44+removeParens :: Value -> Value
45+removeParens (Parens val) = val
46+removeParens val = val
47+
48+customOperatorTable :: M.Map (Qualified Ident) Fixity -> [[(Qualified Ident, Value -> Value -> Value, Associativity)]]
49+customOperatorTable fixities =
50+ let
51+ applyUserOp name t1 t2 = App (App (Var name) [t1]) [t2]
52+ userOps = map (\(name, Fixity a p) -> (name, applyUserOp name, p, a)) . M.toList $ fixities
53+ sorted = sortBy (compare `on` (\(_, _, p, _) -> p)) (userOps ++ builtIns)
54+ groups = groupBy ((==) `on` (\(_, _, p, _) -> p)) sorted
55+ in
56+ map (map (\(name, f, _, a) -> (name, f, a))) groups
57+
58+type Chain = [Either Value (Qualified Ident)]
59+
60+matchOperators :: [[(Qualified Ident, Value -> Value -> Value, Associativity)]] -> Value -> Either String Value
61+matchOperators ops val = G.everywhereM' (G.mkM parseChains) val
62+ where
63+ parseChains :: Value -> Either String Value
64+ parseChains b@(BinaryNoParens _ _ _) = bracketChain (extendChain b)
65+ parseChains val = return val
66+ extendChain :: Value -> Chain
67+ extendChain (BinaryNoParens name l r) = Left l : Right name : extendChain r
68+ extendChain val = [Left val]
69+ bracketChain :: Chain -> Either String Value
70+ bracketChain = either (Left . show) Right . P.parse (P.buildExpressionParser opTable parseValue <* P.eof) "operator expression"
71+ opTable = map (map (\(name, f, a) -> P.Infix (P.try (matchOp name) >> return f) (toAssoc a))) ops
72+ ++ [[P.Infix (P.try (parseOp >>= \ident -> return (\t1 t2 -> App (App (Var ident) [t1]) [t2]))) P.AssocLeft]]
73+
74+toAssoc :: Associativity -> P.Assoc
75+toAssoc Infixl = P.AssocLeft
76+toAssoc Infixr = P.AssocRight
77+
78+parseValue :: P.Parsec Chain () Value
79+parseValue = P.token show (const (P.initialPos "")) (either Just (const Nothing)) P.<?> "expression"
80+
81+parseOp :: P.Parsec Chain () (Qualified Ident)
82+parseOp = P.token show (const (P.initialPos "")) (either (const Nothing) Just) P.<?> "operator"
83+
84+matchOp :: Qualified Ident -> P.Parsec Chain () ()
85+matchOp op = do
86+ ident <- parseOp
87+ guard (ident == op)
88+
89+collectFixities :: [Declaration] -> Either String (M.Map (Qualified Ident) Fixity)
90+collectFixities = go M.empty global
91+ where
92+ go :: M.Map (Qualified Ident) Fixity -> ModulePath -> [Declaration] -> Either String (M.Map (Qualified Ident) Fixity)
93+ go m _ [] = return m
94+ go m p (FixityDeclaration fixity name : rest) = do
95+ let qual = Qualified p (Op name)
96+ when (qual `M.member` m) (Left $ "redefined fixity for " ++ show name)
97+ go (M.insert qual fixity m) p rest
98+ go m p (ModuleDeclaration name decls : rest) = do
99+ m' <- go m (subModule p name) decls
100+ go m' p rest
101+ go m p (_:ds) = go m p ds
102+
103+globalOp :: String -> Qualified Ident
104+globalOp = Qualified global . Op
105+
106+builtIns :: [(Qualified Ident, Value -> Value -> Value, Precedence, Associativity)]
107+builtIns = [ (globalOp "!!", flip Indexer, 3, Infixl)
108+ , (globalOp "&&", Binary And, 3, Infixr)
109+ , (globalOp "||", Binary Or, 3, Infixr)
110+ , (globalOp "<=", Binary LessThanOrEqualTo, 4, Infixl)
111+ , (globalOp ">=", Binary GreaterThanOrEqualTo, 4, Infixl)
112+ , (globalOp "<", Binary LessThan, 4, Infixl)
113+ , (globalOp ">", Binary GreaterThan, 4, Infixl)
114+ , (globalOp "==", Binary EqualTo, 4, Infixl)
115+ , (globalOp "!=", Binary NotEqualTo, 4, Infixl)
116+ , (globalOp "*", Binary Multiply, 7, Infixl)
117+ , (globalOp "/", Binary Divide, 7, Infixl)
118+ , (globalOp "%", Binary Modulus, 7, Infixl)
119+ , (globalOp "++", Binary Concat, 5, Infixr)
120+ , (globalOp "+", Binary Add, 6, Infixl)
121+ , (globalOp "-", Binary Subtract, 6, Infixl)
122+ , (globalOp "<<", Binary ShiftLeft, 7, Infixl)
123+ , (globalOp ">>>", Binary ZeroFillShiftRight, 7, Infixl)
124+ , (globalOp ">>", Binary ShiftRight, 7, Infixl)
125+ , (globalOp "&", Binary BitwiseAnd, 7, Infixl)
126+ , (globalOp "^", Binary BitwiseXor, 7, Infixl)
127+ , (globalOp "|", Binary BitwiseOr, 7, Infixl)
128+ ]
src/Language/PureScript/Parser/Common.hs+8−5
@@ -77,7 +77,7 @@ reservedNames = [ "case"
7777
7878reservedOpNames :: [String]
7979reservedOpNames = [ "!", "~", "-", "<=", ">=", "<", ">", "*", "/", "%", "++", "+", "<<", ">>>", ">>"
80− , "==", "!=", "&", "^", "|", "&&", "||", "->", "!" ]
80+ , "==", "!=", "&", "^", "|", "&&", "||", "->", "!!" ]
8181
8282identStart :: P.Parsec String u Char
8383identStart = P.lower <|> P.oneOf "_$"
@@ -161,11 +161,14 @@ fold first more combine = do
161161buildPostfixParser :: P.Stream s m t => [P.ParsecT s u m (a -> a)] -> P.ParsecT s u m a -> P.ParsecT s u m a
162162buildPostfixParser f x = fold x (P.choice f) (flip ($))
163163
164+operatorOrReserved :: P.Parsec String u String
165+operatorOrReserved = P.try operator <|> P.choice (map (\s -> P.try (reservedOp s) >> return s) reservedOpNames)
166+
164167parseIdent :: P.Parsec String u Ident
165−parseIdent = (Ident <$> identifier) <|> (Op <$> parens operator)
168+parseIdent = (Ident <$> identifier) <|> (Op <$> parens operatorOrReserved)
166169
167−parseIdentInfix :: P.Parsec String u Ident
168−parseIdentInfix = (Ident <$> P.between tick tick identifier) <|> (Op <$> operator)
170+parseIdentInfix :: P.Parsec String ParseState (Qualified Ident)
171+parseIdentInfix = (P.between tick tick (parseQualified (Ident <$> identifier))) <|> parseQualified (Op <$> operatorOrReserved)
169172
170173mark :: P.Parsec String ParseState a -> P.Parsec String ParseState a
171174mark p = do
@@ -189,4 +192,4 @@ same :: P.Parsec String ParseState ()
189192same = checkIndentation (==) P.<?> "no indentation"
190193
191194runIndentParser :: P.Parsec String ParseState a -> String -> Either P.ParseError a
192−runIndentParser p = P.runParser p (ParseState 0 M.empty) ""
195+runIndentParser p = P.runParser p (ParseState 0) ""
src/Language/PureScript/Parser/Declarations.hs−3
@@ -85,9 +85,6 @@ parseFixityDeclaration = do
8585 fixity <- parseFixity
8686 indented
8787 name <- operator
88− current <- fixities <$> P.getState
89− when (name `M.member` current) (P.unexpected $ "redefined fixity for " ++ show name)
90− P.modifyState $ \st -> st { fixities = M.insert name fixity current }
9188 return $ FixityDeclaration fixity name
9289
9390parseModuleDeclaration :: P.Parsec String ParseState Declaration
src/Language/PureScript/Parser/State.hs+1−2
@@ -21,7 +21,6 @@ import qualified Text.Parsec as P
2121import qualified Data.Map as M
2222
2323data ParseState = ParseState
24− { indentationLevel :: P.Column
25− , fixities :: M.Map String Fixity } deriving Show
24+ { indentationLevel :: P.Column } deriving Show
2625
2726
src/Language/PureScript/Parser/Values.hs+6−48
@@ -117,7 +117,7 @@ parseValueAtom = C.indented *> P.choice
117117 , parseBlock
118118 , parseCase
119119 , parseIfThenElse
120− , C.parens parseValue ]
120+ , Parens <$> C.parens parseValue ]
121121
122122parsePropertyUpdate :: P.Parsec String ParseState (String, Value)
123123parsePropertyUpdate = do
@@ -127,9 +127,8 @@ parsePropertyUpdate = do
127127 return (name, value)
128128
129129parseValue :: P.Parsec String ParseState Value
130−parseValue = do
131− customOps <- fixities <$> P.getState
132− (buildExpressionParser (operators customOps)
130+parseValue =
131+ (buildExpressionParser operators
133132 . C.buildPostfixParser postfixTable2
134133 $ indexersAndAccessors) P.<?> "expression"
135134 where
@@ -139,55 +138,14 @@ parseValue = do
139138 postfixTable2 = [ P.try (C.indented *> indexersAndAccessors >>= \t2 -> return (\t1 -> App t1 [t2]))
140139 , P.try $ flip App <$> (C.indented *> C.parens (parseValue `P.sepBy` (C.indented *> C.comma)))
141140 , flip TypedValue <$> (P.try (C.lexeme (C.indented *> P.string "::")) *> parsePolyType) ]
142− operators user =
143− [ [ Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "!") >> return (Unary Not)
141+ operators = [ [ Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "!") >> return (Unary Not)
144142 , Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "~") >> return (Unary BitwiseNot)
145143 , Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "-") >> return (Unary Negate)
146144 , Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "+") >> return id ]
147− ] ++ customOperatorTable user ++
148− [ [ Infix (C.lexeme (P.try (C.indented *> C.parseQualified C.parseIdentInfix P.<?> "operator") >>= \ident -> return $ \t1 t2 -> App (App (Var ident) [t1]) [t2])) AssocLeft ]
149− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "!!") >> return (flip Indexer)) AssocRight ]
150− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "<=") >> return (Binary LessThanOrEqualTo)) AssocRight
151− , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp ">=") >> return (Binary GreaterThanOrEqualTo)) AssocRight ]
152− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "<") >> return (Binary LessThan)) AssocRight
153− , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp ">") >> return (Binary GreaterThan)) AssocRight ]
154− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "*") >> return (Binary Multiply)) AssocRight
155− , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "/") >> return (Binary Divide)) AssocRight
156− , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "%") >> return (Binary Modulus)) AssocRight ]
157− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "++") >> return (Binary Concat)) AssocRight
158− , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "+") >> return (Binary Add)) AssocRight
159− , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "-") >> return (Binary Subtract)) AssocRight ]
160− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "<<") >> return (Binary ShiftLeft)) AssocRight
161− , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp ">>>") >> return (Binary ZeroFillShiftRight)) AssocRight
162− , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp ">>") >> return (Binary ShiftRight)) AssocRight ]
163− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "==") >> return (Binary EqualTo)) AssocRight
164− , Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "!=") >> return (Binary NotEqualTo)) AssocRight ]
165− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "&") >> return (Binary BitwiseAnd)) AssocRight ]
166− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "^") >> return (Binary BitwiseXor)) AssocRight ]
167− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "|") >> return (Binary BitwiseOr)) AssocRight ]
168− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "&&") >> return (Binary And)) AssocRight ]
169− , [ Infix (C.lexeme (P.try $ C.indented *> C.reservedOp "||") >> return (Binary Or)) AssocRight ]
145+ , [ Infix (C.lexeme (P.try (C.indented *> C.parseIdentInfix P.<?> "operator") >>= \ident ->
146+ return (BinaryNoParens ident))) AssocLeft ]
170147 ]
171148
172−customOperatorTable :: M.Map String Fixity -> OperatorTable String ParseState Identity Value
173−customOperatorTable fixities =
174− let
175− ops = map (\(name, Fixity a p) -> (name, (a, p))) . M.toList $ fixities
176− sorted = sortBy (compare `on` (snd . snd)) ops
177− levels = groupBy ((==) `on` (snd . snd)) sorted
178− in
179− map (map $ \(name, (a, _)) ->
180− flip Infix (toAssoc a) $
181− C.lexeme $ P.try $ do
182− C.indented
183− C.reservedOp name P.<?> "operator"
184− return $ \t1 t2 -> App (App (Var (Qualified global (Op name))) [t1]) [t2])
185− levels
186−
187−toAssoc :: Associativity -> Assoc
188−toAssoc Infixl = AssocLeft
189−toAssoc Infixr = AssocRight
190−
191149parseVariableIntroduction :: P.Parsec String ParseState Statement
192150parseVariableIntroduction = do
193151 C.reserved "var"
src/Language/PureScript/TypeChecker/Synonyms.hs+1−7
@@ -12,8 +12,6 @@
1212--
1313-----------------------------------------------------------------------------
1414
15−{-# LANGUAGE Rank2Types #-}
16−
1715module Language.PureScript.TypeChecker.Synonyms (
1816 saturateTypeSynonym,
1917 saturateAllTypeSynonyms
@@ -26,6 +24,7 @@ import Language.PureScript.Names
2624import Data.Maybe (fromMaybe)
2725import Data.Data
2826import Data.Generics
27+import Data.Generics.Extras
2928import Control.Arrow
3029import Control.Monad.Writer
3130import Control.Monad.Error
@@ -40,11 +39,6 @@ buildTypeSubstitution name n = go n []
4039 go n args (TypeApp f arg) = go (n - 1) (arg:args) f
4140 go _ _ _ = return Nothing
4241
43−everywhereM' :: (Monad m, Data d) => (forall d. (Data d) => d -> m d) -> d -> m d
44−everywhereM' f x = do
45− y <- f x
46− gmapM (everywhereM' f) y
47−
4842saturateTypeSynonym :: (Data d) => Qualified ProperName -> Int -> d -> Either String d
4943saturateTypeSynonym name n = everywhereM' (mkM replace)
5044 where
src/Language/PureScript/Values.hs+2
@@ -54,6 +54,8 @@ data Value
5454 | BooleanLiteral Bool
5555 | Unary UnaryOperator Value
5656 | Binary BinaryOperator Value Value
57+ | BinaryNoParens (Qualified Ident) Value Value
58+ | Parens Value
5759 | ArrayLiteral [Value]
5860 | Indexer Value Value
5961 | ObjectLiteral [(String, Value)]
src/Main.hs+7−8
@@ -14,7 +14,7 @@
1414
1515module Main where
1616
17−import Language.PureScript
17+import qualified Language.PureScript as P
1818import Data.Maybe (mapMaybe)
1919import Data.List (intercalate)
2020import System.Console.CmdTheLine
@@ -29,24 +29,23 @@ compile :: [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()
2929compile inputFiles outputFile externsFile = do
3030 asts <- fmap (fmap concat . sequence) $ forM inputFiles $ \inputFile -> do
3131 text <- U.readFile inputFile
32− return $ runIndentParser parseDeclarations text
32+ return $ P.runIndentParser P.parseDeclarations text
3333 case asts of
3434 Left err -> do
3535 U.print err
3636 exitFailure
3737 Right decls ->
38− case check (typeCheckAll decls) of
39− Left typeError -> do
40− U.putStrLn typeError
38+ case P.compile decls of
39+ Left error -> do
40+ U.putStrLn error
4141 exitFailure
42− Right (_, env) -> do
43− let js = intercalate "; " . map (prettyPrintJS . optimize) . concat . mapMaybe (declToJs Nothing global) $ decls
42+ Right (js, exts, _) -> do
4443 case outputFile of
4544 Just path -> U.writeFile path js
4645 Nothing -> U.putStrLn js
4746 case externsFile of
4847 Nothing -> return ()
49− Just filePath -> U.writeFile filePath $ intercalate "\n" $ mapMaybe (externToPs 0 global env) decls
48+ Just filePath -> U.writeFile filePath exts
5049 exitSuccess
5150
5251inputFiles :: Term [FilePath]
tests/Main.hs+6−6
@@ -14,7 +14,7 @@
1414
1515module Main (main) where
1616
17−import Language.PureScript
17+import qualified Language.PureScript as P
1818
1919import Data.List (isSuffixOf)
2020import Control.Applicative
@@ -25,20 +25,20 @@ import System.Directory (getCurrentDirectory, getDirectoryContents)
2525import qualified System.IO.UTF8 as U
2626import qualified Data.Map as M
2727
28−compile :: FilePath -> IO (Either String Environment)
28+compile :: FilePath -> IO (Either String P.Environment)
2929compile inputFile = do
30− ast <- runIndentParser parseDeclarations <$> U.readFile inputFile
30+ ast <- P.runIndentParser P.parseDeclarations <$> U.readFile inputFile
3131 case ast of
3232 Left parseError -> do
3333 return (Left $ show parseError)
3434 Right decls -> do
35− case check (typeCheckAll decls) of
35+ case P.compile decls of
3636 Left typeError -> do
3737 return (Left typeError)
38− Right (_, env) -> do
38+ Right (_, _, env) -> do
3939 return (Right env)
4040
41−assert :: FilePath -> (Either String Environment -> Maybe String) -> IO ()
41+assert :: FilePath -> (Either String P.Environment -> Maybe String) -> IO ()
4242assert inputFile f = do
4343 e <- compile inputFile
4444 case f e of