on master help sign in
Begin parsing types and patterns such as A.B.C
6f94400Evan Czaplicki
compiler/Parse/Pattern.hs+2−1
@@ -5,6 +5,7 @@ import Control.Applicative ((<$>),(<*>),pure)
5import Control.Monad
5import Control.Monad
6import Control.Monad.State
6import Control.Monad.State
7import Data.Char (isUpper)
7import Data.Char (isUpper)
8+import Data.List (intercalate)
8import Unique
9import Unique
9import Text.Parsec hiding (newline,spaces,State)
10import Text.Parsec hiding (newline,spaces,State)
10import Text.Parsec.Indent
11import Text.Parsec.Indent
@@ -53,7 +54,7 @@ term =
53
54
54patternConstructor :: IParser Pattern
55patternConstructor :: IParser Pattern
55patternConstructor = do
56patternConstructor = do
56− v <- capVar
57+ v <- intercalate "." <$> dotSep1 capVar
57 case v of
58 case v of
58 "True" -> return $ PLiteral (Boolean True)
59 "True" -> return $ PLiteral (Boolean True)
59 "False" -> return $ PLiteral (Boolean False)
60 "False" -> return $ PLiteral (Boolean False)
compiler/Parse/Type.hs+4−3
@@ -40,10 +40,11 @@ record =
40 whitespace >> hasType >> whitespace
40 whitespace >> hasType >> whitespace
41 (,) lbl <$> expr
41 (,) lbl <$> expr
42
42
43+capTypeVar = intercalate "." <$> dotSep1 capVar
43
44
44constructor0 :: IParser T.Type
45constructor0 :: IParser T.Type
45constructor0 =
46constructor0 =
46− do name <- capVar
47+ do name <- capTypeVar
47 return (T.Data name [])
48 return (T.Data name [])
48
49
49term :: IParser T.Type
50term :: IParser T.Type
@@ -51,7 +52,7 @@ term = list <|> tuple <|> record <|> tvar <|> constructor0
51
52
52app :: IParser T.Type
53app :: IParser T.Type
53app =
54app =
54− do name <- capVar <|> try tupleCtor <?> "type constructor"
55+ do name <- capTypeVar <|> try tupleCtor <?> "type constructor"
55 args <- spacePrefix term
56 args <- spacePrefix term
56 return (T.Data name args)
57 return (T.Data name args)
57 where
58 where
@@ -70,7 +71,7 @@ expr =
70 Nothing -> return t1
71 Nothing -> return t1
71
72
72constructor :: IParser (String, [T.Type])
73constructor :: IParser (String, [T.Type])
73−constructor = (,) <$> (capVar <?> "another type constructor")
74+constructor = (,) <$> (capTypeVar <?> "another type constructor")
74 <*> spacePrefix term
75 <*> spacePrefix term
75
76
76readType :: String -> Type
77readType :: String -> Type