on master help sign in
Update Parse/ module for new AST structure
commit0725fe3872b7fed05e62e0ca8054207651aa040a authorEvan Czaplicki <info@elm-lang.org> dateSat 12 Apr 2014, 13:48 (13 years ago) parent9f82256
9 files changed+131−110
compiler/Parse/Binop.hs+19−17 compiler/Parse/Declaration.hs+7−8 compiler/Parse/Expression.hs+31−29 compiler/Parse/Helpers.hs+8−7 compiler/Parse/Literal.hs+1−1 compiler/Parse/Module.hs+18−11 compiler/Parse/Parse.hs+13−9 compiler/Parse/Pattern.hs+16−13 compiler/Parse/Type.hs+18−15
compiler/Parse/Binop.hs+19−17
@@ -5,9 +5,11 @@ import Control.Applicative ((<$>))
55import qualified Data.List as List
66import qualified Data.Map as Map
77
8−import SourceSyntax.Annotation (merge)
9−import qualified SourceSyntax.Expression as E
10−import SourceSyntax.Declaration (Assoc(..))
8+import AST.Annotation (merge)
9+import AST.Declaration (Assoc(..))
10+import AST.Expression.General (Expr'(Binop))
11+import qualified AST.Expression.Source as Source
12+import qualified AST.Variable as Var
1113import Text.Parsec
1214import Parse.Helpers
1315
@@ -17,13 +19,13 @@ opLevel table op = fst $ Map.findWithDefault (9,L) op table
1719opAssoc :: OpTable -> String -> Assoc
1820opAssoc table op = snd $ Map.findWithDefault (9,L) op table
1921
20−hasLevel :: OpTable -> Int -> (String, E.ParseExpr) -> Bool
22+hasLevel :: OpTable -> Int -> (String, Source.Expr) -> Bool
2123hasLevel table n (op,_) = opLevel table op == n
2224
23−binops :: IParser E.ParseExpr
24− -> IParser E.ParseExpr
25+binops :: IParser Source.Expr
26+ -> IParser Source.Expr
2527 -> IParser String
26− -> IParser E.ParseExpr
28+ -> IParser Source.Expr
2729binops term last anyOp =
2830 do e <- term
2931 table <- getState
@@ -39,9 +41,9 @@ binops term last anyOp =
3941
4042split :: OpTable
4143 -> Int
42− -> E.ParseExpr
43− -> [(String, E.ParseExpr)]
44− -> IParser E.ParseExpr
44+ -> Source.Expr
45+ -> [(String, Source.Expr)]
46+ -> IParser Source.Expr
4547split _ _ e [] = return e
4648split table n e eops = do
4749 assoc <- getAssoc table n eops
@@ -50,26 +52,26 @@ split table n e eops = do
5052 case assoc of R -> joinR es ops
5153 _ -> joinL es ops
5254
53−splitLevel :: OpTable -> Int -> E.ParseExpr -> [(String, E.ParseExpr)]
54− -> [IParser E.ParseExpr]
55+splitLevel :: OpTable -> Int -> Source.Expr -> [(String, Source.Expr)]
56+ -> [IParser Source.Expr]
5557splitLevel table n e eops =
5658 case break (hasLevel table n) eops of
5759 (lops, (_op,e'):rops) ->
5860 split table (n+1) e lops : splitLevel table n e' rops
5961 (lops, []) -> [ split table (n+1) e lops ]
6062
61−joinL :: [E.ParseExpr] -> [String] -> IParser E.ParseExpr
63+joinL :: [Source.Expr] -> [String] -> IParser Source.Expr
6264joinL [e] [] = return e
63−joinL (a:b:es) (op:ops) = joinL (merge a b (E.Binop op a b) : es) ops
65+joinL (a:b:es) (op:ops) = joinL (merge a b (Binop (Var.Raw op) a b) : es) ops
6466joinL _ _ = failure "Ill-formed binary expression. Report a compiler bug."
6567
66−joinR :: [E.ParseExpr] -> [String] -> IParser E.ParseExpr
68+joinR :: [Source.Expr] -> [String] -> IParser Source.Expr
6769joinR [e] [] = return e
6870joinR (a:b:es) (op:ops) = do e <- joinR (b:es) ops
69− return (merge a e (E.Binop op a e))
71+ return (merge a e (Binop (Var.Raw op) a e))
7072joinR _ _ = failure "Ill-formed binary expression. Report a compiler bug."
7173
72−getAssoc :: OpTable -> Int -> [(String,E.ParseExpr)] -> IParser Assoc
74+getAssoc :: OpTable -> Int -> [(String,Source.Expr)] -> IParser Assoc
7375getAssoc table n eops
7476 | all (==L) assocs = return L
7577 | all (==R) assocs = return R
compiler/Parse/Declaration.hs+7−8
@@ -7,16 +7,15 @@ import Text.Parsec hiding (newline,spaces)
77import Parse.Helpers
88import qualified Parse.Expression as Expr
99import qualified Parse.Type as Type
10−import qualified SourceSyntax.Declaration as D
10+import qualified AST.Declaration as D
1111
12−
13−declaration :: IParser D.ParseDeclaration
12+declaration :: IParser D.SourceDecl
1413declaration = alias <|> datatype <|> infixDecl <|> port <|> definition
1514
16−definition :: IParser D.ParseDeclaration
15+definition :: IParser D.SourceDecl
1716definition = D.Definition <$> Expr.def
1817
19−alias :: IParser D.ParseDeclaration
18+alias :: IParser D.SourceDecl
2019alias = do
2120 reserved "type" <?> "type alias (type Point = {x:Int, y:Int})"
2221 forcedWS
@@ -26,7 +25,7 @@ alias = do
2625 tipe <- Type.expr
2726 return (D.TypeAlias name args tipe)
2827
29−datatype :: IParser D.ParseDeclaration
28+datatype :: IParser D.SourceDecl
3029datatype = do
3130 reserved "data" <?> "datatype definition (data T = A | B | ...)"
3231 forcedWS
@@ -37,7 +36,7 @@ datatype = do
3736 return $ D.Datatype name args tcs
3837
3938
40−infixDecl :: IParser D.ParseDeclaration
39+infixDecl :: IParser D.SourceDecl
4140infixDecl = do
4241 assoc <- choice [ reserved "infixl" >> return D.L
4342 , reserved "infix" >> return D.N
@@ -48,7 +47,7 @@ infixDecl = do
4847 D.Fixity assoc (read [n]) <$> anyOp
4948
5049
51−port :: IParser D.ParseDeclaration
50+port :: IParser D.SourceDecl
5251port =
5352 do try (reserved "port")
5453 whitespace
compiler/Parse/Expression.hs+31−29
@@ -11,39 +11,41 @@ import Parse.Literal
1111import qualified Parse.Pattern as Pattern
1212import qualified Parse.Type as Type
1313
14−import SourceSyntax.Annotation as Annotation
15−import qualified SourceSyntax.Pattern as P
16−import qualified SourceSyntax.Literal as L
17−import SourceSyntax.Expression
14+import AST.Annotation as Annotation
15+import AST.Expression.General
16+import qualified AST.Expression.Source as Source
17+import qualified AST.Literal as L
18+import qualified AST.Pattern as P
19+import qualified AST.Variable as Var
1820
1921
2022-------- Basic Terms --------
2123
22−varTerm :: IParser ParseExpr'
24+varTerm :: IParser Source.Expr'
2325varTerm = toVar <$> var <?> "variable"
2426
25−toVar :: String -> ParseExpr'
27+toVar :: String -> Source.Expr'
2628toVar v = case v of "True" -> Literal (L.Boolean True)
2729 "False" -> Literal (L.Boolean False)
2830 _ -> rawVar v
2931
30−accessor :: IParser ParseExpr'
32+accessor :: IParser Source.Expr'
3133accessor = do
3234 (start, lbl, end) <- located (try (string "." >> rLabel))
3335 let loc e = Annotation.at start end e
3436 return (Lambda (P.Var "_") (loc $ Access (loc $ rawVar "_") lbl))
3537
36−negative :: IParser ParseExpr'
38+negative :: IParser Source.Expr'
3739negative = do
3840 (start, nTerm, end) <-
3941 located (try (char '-' >> notFollowedBy (char '.' <|> char '-')) >> term)
4042 let loc e = Annotation.at start end e
41− return (Binop "-" (loc $ Literal (L.IntNum 0)) nTerm)
43+ return (Binop (Var.Raw "-") (loc $ Literal (L.IntNum 0)) nTerm)
4244
4345
4446-------- Complex Terms --------
4547
46−listTerm :: IParser ParseExpr'
48+listTerm :: IParser Source.Expr'
4749listTerm = markdown' <|> braces (try range <|> ExplicitList <$> commaSep expr)
4850 where
4951 range = do
@@ -66,14 +68,14 @@ listTerm = markdown' <|> braces (try range <|> ExplicitList <$> commaSep expr)
6668 string "}}"
6769 return (span uid (length exprs), exprs ++ [e])
6870
69−parensTerm :: IParser ParseExpr
71+parensTerm :: IParser Source.Expr
7072parensTerm = try (parens opFn) <|> parens (tupleFn <|> parened)
7173 where
7274 opFn = do
7375 (start, op, end) <- located anyOp
7476 let loc = Annotation.at start end
7577 return . loc . Lambda (P.Var "x") . loc . Lambda (P.Var "y") . loc $
76− Binop op (loc $ rawVar "x") (loc $ rawVar "y")
78+ Binop (Var.Raw op) (loc (rawVar "x")) (loc (rawVar "y"))
7779
7880 tupleFn = do
7981 let comma = char ',' <?> "comma ','"
@@ -89,7 +91,7 @@ parensTerm = try (parens opFn) <|> parens (tupleFn <|> parened)
8991 [e] -> e
9092 _ -> Annotation.at start end (tuple es)
9193
92−recordTerm :: IParser ParseExpr
94+recordTerm :: IParser Source.Expr
9395recordTerm = brackets $ choice [ misc, addLocation record ]
9496 where
9597 field = do
@@ -123,14 +125,14 @@ recordTerm = brackets $ choice [ misc, addLocation record ]
123125 Nothing -> try (insert record) <|> try (modify record)
124126
125127
126−term :: IParser ParseExpr
128+term :: IParser Source.Expr
127129term = addLocation (choice [ Literal <$> literal, listTerm, accessor, negative ])
128130 <|> accessible (addLocation varTerm <|> parensTerm <|> recordTerm)
129131 <?> "basic term (4, x, 'c', etc.)"
130132
131133-------- Applications --------
132134
133−appExpr :: IParser ParseExpr
135+appExpr :: IParser Source.Expr
134136appExpr = do
135137 t <- term
136138 ts <- constrainedSpacePrefix term $ \str ->
@@ -141,12 +143,12 @@ appExpr = do
141143
142144-------- Normal Expressions --------
143145
144−binaryExpr :: IParser ParseExpr
146+binaryExpr :: IParser Source.Expr
145147binaryExpr = binops appExpr lastExpr anyOp
146148 where lastExpr = addLocation (choice [ ifExpr, letExpr, caseExpr ])
147149 <|> lambdaExpr
148150
149−ifExpr :: IParser ParseExpr'
151+ifExpr :: IParser Source.Expr'
150152ifExpr = reserved "if" >> whitespace >> (normal <|> multiIf)
151153 where
152154 normal = do
@@ -162,7 +164,7 @@ ifExpr = reserved "if" >> whitespace >> (normal <|> multiIf)
162164 b <- expr ; padded arrow
163165 (,) b <$> expr
164166
165−lambdaExpr :: IParser ParseExpr
167+lambdaExpr :: IParser Source.Expr
166168lambdaExpr = do char '\\' <|> char '\x03BB' <?> "anonymous function"
167169 whitespace
168170 args <- spaceSep1 Pattern.term
@@ -170,17 +172,17 @@ lambdaExpr = do char '\\' <|> char '\x03BB' <?> "anonymous function"
170172 body <- expr
171173 return (makeFunction args body)
172174
173−defSet :: IParser [ParseDef]
175+defSet :: IParser [Source.Def]
174176defSet = block (do d <- def ; whitespace ; return d)
175177
176−letExpr :: IParser ParseExpr'
178+letExpr :: IParser Source.Expr'
177179letExpr = do
178180 reserved "let" ; whitespace
179181 defs <- defSet
180182 padded (reserved "in")
181183 Let defs <$> expr
182184
183−caseExpr :: IParser ParseExpr'
185+caseExpr :: IParser Source.Expr'
184186caseExpr = do
185187 reserved "case"; e <- padded expr; reserved "of"; whitespace
186188 Case e <$> (with <|> without)
@@ -190,13 +192,13 @@ caseExpr = do
190192 with = brackets (semiSep1 (case_ <?> "cases { x -> ... }"))
191193 without = block (do c <- case_ ; whitespace ; return c)
192194
193−expr :: IParser ParseExpr
195+expr :: IParser Source.Expr
194196expr = addLocation (choice [ ifExpr, letExpr, caseExpr ])
195197 <|> lambdaExpr
196198 <|> binaryExpr
197199 <?> "an expression"
198200
199−defStart :: IParser [P.Pattern]
201+defStart :: IParser [Pattern.RawPattern]
200202defStart =
201203 choice [ do p1 <- try Pattern.term
202204 infics p1 <|> func p1
@@ -216,24 +218,24 @@ defStart =
216218 return $ if o == '`' then [ P.Var $ takeWhile (/='`') p, p1, p2 ]
217219 else [ P.Var (o:p), p1, p2 ]
218220
219−makeFunction :: [P.Pattern] -> ParseExpr -> ParseExpr
221+makeFunction :: [Pattern.RawPattern] -> Source.Expr -> Source.Expr
220222makeFunction args body@(A ann _) =
221223 foldr (\arg body' -> A ann $ Lambda arg body') body args
222224
223−definition :: IParser ParseDef
225+definition :: IParser Source.Def
224226definition = withPos $ do
225227 (name:args) <- defStart
226228 padded equals
227229 body <- expr
228− return . Def name $ makeFunction args body
230+ return . Source.Definition name $ makeFunction args body
229231
230−typeAnnotation :: IParser ParseDef
231−typeAnnotation = TypeAnnotation <$> try start <*> Type.expr
232+typeAnnotation :: IParser Source.Def
233+typeAnnotation = Source.TypeAnnotation <$> try start <*> Type.expr
232234 where
233235 start = do
234236 v <- lowVar <|> parens symOp
235237 padded hasType
236238 return v
237239
238−def :: IParser ParseDef
240+def :: IParser Source.Def
239241def = typeAnnotation <|> definition
compiler/Parse/Helpers.hs+8−7
@@ -12,12 +12,13 @@ import Text.Parsec hiding (newline,spaces,State)
1212import Text.Parsec.Indent
1313import qualified Text.Parsec.Token as T
1414
15−import SourceSyntax.Annotation as Annotation
16−import SourceSyntax.Declaration (Assoc)
17−import SourceSyntax.Expression
18−import SourceSyntax.Helpers as Help
19−import SourceSyntax.PrettyPrint
20−import SourceSyntax.Variable as Variable
15+import AST.Annotation as Annotation
16+import AST.Declaration (Assoc)
17+import AST.Expression.General
18+import qualified AST.Expression.Source as Source
19+import AST.Helpers as Help
20+import AST.PrettyPrint
21+import qualified AST.Variable as Variable
2122
2223reserveds = [ "if", "then", "else"
2324 , "case", "of"
@@ -197,7 +198,7 @@ located p = do
197198 end <- getPosition
198199 return (start, e, end)
199200
200−accessible :: IParser ParseExpr -> IParser ParseExpr
201+accessible :: IParser Source.Expr -> IParser Source.Expr
201202accessible expr = do
202203 start <- getPosition
203204 ce@(A _ e) <- expr
compiler/Parse/Literal.hs+1−1
@@ -4,7 +4,7 @@ module Parse.Literal (literal) where
44import Control.Applicative ((<$>))
55import Text.Parsec hiding (newline,spaces)
66import Parse.Helpers
7−import SourceSyntax.Literal
7+import AST.Literal
88
99literal :: IParser Literal
1010literal = num <|> (Str <$> str) <|> (Chr <$> chr) <?> "literal"
compiler/Parse/Module.hs+18−11
@@ -5,10 +5,8 @@ import Data.List (intercalate)
55import Text.Parsec hiding (newline,spaces)
66
77import Parse.Helpers
8−import SourceSyntax.Module (ImportMethod(..), Imports)
9−
10−varList :: IParser [String]
11−varList = commaSep1 (var <|> parens symOp)
8+import AST.Module (ImportMethod(..))
9+import AST.Variable (Listing(..), Value(..))
1210
1311getModuleName :: String -> Maybe String
1412getModuleName source =
@@ -21,18 +19,18 @@ getModuleName source =
2119 (names, _) <- moduleDef
2220 return (intercalate "." names)
2321
24−moduleDef :: IParser ([String], [String])
22+moduleDef :: IParser ([String], Listing Value)
2523moduleDef = do
2624 try (reserved "module")
2725 whitespace
2826 names <- dotSep1 capVar <?> "name of module"
2927 whitespace
30− exports <- option [] (parens varList)
28+ exports <- option (Listing [] True) (listing value)
3129 whitespace <?> "reserved word 'where'"
3230 reserved "where"
3331 return (names, exports)
3432
35−imports :: IParser Imports
33+imports :: IParser [(String, ImportMethod)]
3634imports = option [] ((:) <$> import' <*> many (try (freshLine >> import')))
3735
3836import' :: IParser (String, ImportMethod)
@@ -53,7 +51,16 @@ import' =
5351 As <$> capVar <?> "alias for module"
5452
5553 importing' :: IParser ImportMethod
56− importing' =
57− parens (choice [ const (Hiding []) <$> string ".."
58− , Importing <$> varList
59− ] <?> "listing of imported values (x,y,z)")
54+ importing' = Open <$> listing value
55+
56+listing :: IParser a -> IParser (Listing a)
57+listing item =
58+ parens (choice [ const (Listing [] True) <$> string ".."
59+ , Listing <$> commaSep1 item <*> return False
60+ ] <?> "listing of values (x,y,z)")
61+
62+value :: IParser Value
63+value = choice [ Value <$> (lowVar <|> parens symOp)
64+ , ADT <$> capVar <*> listing capVar
65+ ]
66+
compiler/Parse/Parse.hs+13−9
@@ -7,8 +7,9 @@ import qualified Data.Map as Map
77import Text.Parsec hiding (newline,spaces)
88import qualified Text.PrettyPrint as P
99
10−import qualified SourceSyntax.Declaration as D
11−import qualified SourceSyntax.Module as M
10+import qualified AST.Declaration as D
11+import qualified AST.Module as M
12+import qualified AST.Variable as Var
1213import Parse.Helpers
1314import Parse.Declaration (infixDecl)
1415import Parse.Module
@@ -22,21 +23,24 @@ freshDef = commitIf (freshLine >> (letter <|> char '_')) $ do
2223decls = do d <- Decl.declaration <?> "at least one datatype or variable definition"
2324 (d:) <$> many freshDef
2425
25−program :: OpTable -> String -> Either [P.Doc] (M.Module D.Declaration)
26+program :: OpTable -> String -> Either [P.Doc] M.ValidModule
2627program table src =
27− do (M.Module names exs ims parseDecls) <- setupParserWithTable table programParser src
28− decls <- either (\err -> Left [P.text err]) Right (combineAnnotations parseDecls)
29− return $ M.Module names exs ims decls
28+ do (M.Module names filePath exs ims parseDecls) <-
29+ setupParserWithTable table programParser src
30+ decls <-
31+ either (\err -> Left [P.text err]) Right (combineAnnotations parseDecls)
32+ return $ M.Module names filePath exs ims decls
3033
31−programParser :: IParser (M.Module D.ParseDeclaration)
34+programParser :: IParser M.SourceModule
3235programParser =
3336 do optional freshLine
34− (names,exports) <- option (["Main"],[]) (moduleDef `followedBy` freshLine)
37+ (names,exports) <-
38+ option (["Main"], Var.openListing) (moduleDef `followedBy` freshLine)
3539 is <- (do try (lookAhead $ reserved "import")
3640 imports `followedBy` freshLine) <|> return []
3741 declarations <- decls
3842 optional freshLine ; optional spaces ; eof
39− return $ M.Module names exports is declarations
43+ return $ M.Module names "" exports is declarations
4044
4145dependencies :: String -> Either [P.Doc] (String, [String])
4246dependencies =
compiler/Parse/Pattern.hs+16−13
@@ -1,5 +1,5 @@
11{-# OPTIONS_GHC -W #-}
2−module Parse.Pattern (term, expr) where
2+module Parse.Pattern (term, expr, RawPattern) where
33
44import Control.Applicative ((<$>))
55import Data.Char (isUpper)
@@ -8,54 +8,57 @@ import Text.Parsec hiding (newline,spaces,State)
88
99import Parse.Helpers
1010import Parse.Literal
11−import SourceSyntax.Literal
12−import qualified SourceSyntax.Pattern as P
11+import AST.Literal
12+import qualified AST.Pattern as P
13+import qualified AST.Variable as Var
1314
14−basic :: IParser P.Pattern
15+type RawPattern = P.Pattern Var.Raw
16+
17+basic :: IParser RawPattern
1518basic = choice
1619 [ char '_' >> return P.Anything
1720 , do v <- var
1821 return $ case v of
1922 "True" -> P.Literal (Boolean True)
2023 "False" -> P.Literal (Boolean False)
21− c:_ | isUpper c -> P.Data v []
24+ c:_ | isUpper c -> P.Data (Var.Raw v) []
2225 _ -> P.Var v
2326 , P.Literal <$> literal
2427 ]
2528
26−asPattern :: P.Pattern -> IParser P.Pattern
29+asPattern :: RawPattern -> IParser RawPattern
2730asPattern pattern = do
2831 var <- optionMaybe (try (whitespace >> reserved "as" >> whitespace >> lowVar))
2932 return $ case var of
3033 Just v -> P.Alias v pattern
3134 Nothing -> pattern
3235
33−record :: IParser P.Pattern
36+record :: IParser RawPattern
3437record = P.Record <$> brackets (commaSep1 lowVar)
3538
36−tuple :: IParser P.Pattern
39+tuple :: IParser RawPattern
3740tuple = do
3841 ps <- parens (commaSep expr)
3942 return $ case ps of
4043 [p] -> p
4144 _ -> P.tuple ps
4245
43−list :: IParser P.Pattern
46+list :: IParser RawPattern
4447list = P.list <$> braces (commaSep expr)
4548
46−term :: IParser P.Pattern
49+term :: IParser RawPattern
4750term =
4851 (choice [ record, tuple, list, basic ]) <?> "pattern"
4952
50−patternConstructor :: IParser P.Pattern
53+patternConstructor :: IParser RawPattern
5154patternConstructor = do
5255 v <- List.intercalate "." <$> dotSep1 capVar
5356 case v of
5457 "True" -> return $ P.Literal (Boolean True)
5558 "False" -> return $ P.Literal (Boolean False)
56− _ -> P.Data v <$> spacePrefix term
59+ _ -> P.Data (Var.Raw v) <$> spacePrefix term
5760
58−expr :: IParser P.Pattern
61+expr :: IParser RawPattern
5962expr = do
6063 patterns <- consSep1 (patternConstructor <|> term)
6164 asPattern (foldr1 P.cons patterns) <?> "pattern"
compiler/Parse/Type.hs+18−15
@@ -5,22 +5,25 @@ import Control.Applicative ((<$>),(<*>),(<*))
55import Data.List (intercalate)
66import Text.Parsec
77
8−import SourceSyntax.Type as T
8+import qualified AST.Type as T
9+import qualified AST.Variable as Var
910import Parse.Helpers
1011
11−tvar :: IParser T.Type
12+type RawType = T.Type Var.Raw
13+
14+tvar :: IParser RawType
1215tvar = T.Var <$> lowVar <?> "type variable"
1316
14−list :: IParser T.Type
15−list = listOf <$> braces expr
17+list :: IParser RawType
18+list = T.listOf <$> braces expr
1619
17−tuple :: IParser T.Type
20+tuple :: IParser RawType
1821tuple = do ts <- parens (commaSep expr)
1922 return $ case ts of
2023 [t] -> t
21− _ -> tupleOf ts
24+ _ -> T.tupleOf ts
2225
23−record :: IParser T.Type
26+record :: IParser RawType
2427record =
2528 do char '{' ; whitespace
2629 rcrd <- extended <|> normal
@@ -33,7 +36,7 @@ record =
3336 extended = do
3437 ext <- try (lowVar <* (whitespace >> string "|"))
3538 whitespace
36− flip T.Record (Just ext) <$> commaSep1 field
39+ flip T.Record (Just (T.Var ext)) <$> commaSep1 field
3740
3841 field = do
3942 lbl <- rLabel
@@ -43,25 +46,25 @@ record =
4346capTypeVar :: IParser String
4447capTypeVar = intercalate "." <$> dotSep1 capVar
4548
46−constructor0 :: IParser T.Type
49+constructor0 :: IParser RawType
4750constructor0 =
4851 do name <- capTypeVar
49− return (T.Data name [])
52+ return (T.Data (Var.Raw name) [])
5053
51−term :: IParser T.Type
54+term :: IParser RawType
5255term = list <|> tuple <|> record <|> tvar <|> constructor0
5356
54−app :: IParser T.Type
57+app :: IParser RawType
5558app =
5659 do name <- capTypeVar <|> try tupleCtor <?> "type constructor"
5760 args <- spacePrefix term
58− return (T.Data name args)
61+ return (T.Data (Var.Raw name) args)
5962 where
6063 tupleCtor = do
6164 n <- length <$> parens (many (char ','))
6265 return $ "_Tuple" ++ show (if n == 0 then 0 else n+1)
6366
64−expr :: IParser T.Type
67+expr :: IParser RawType
6568expr =
6669 do t1 <- app <|> term
6770 arr <- optionMaybe $ try (whitespace >> arrow)
@@ -69,6 +72,6 @@ expr =
6972 Just _ -> T.Lambda t1 <$> (whitespace >> expr)
7073 Nothing -> return t1
7174
72−constructor :: IParser (String, [T.Type])
75+constructor :: IParser (String, [RawType])
7376constructor = (,) <$> (capTypeVar <?> "another type constructor")
7477 <*> spacePrefix term