on master help sign in
Begin parsing types and patterns such as A.B.C
commit6f94400f2dde92f61f20efc85b3f71c8b5517f66 authorEvan Czaplicki <info@elm-lang.org> dateMon 22 Jul 2013, 14:40 (13 years ago) parent97bd68a
2 files changed+6−4
compiler/Parse/Pattern.hs+2−1 compiler/Parse/Type.hs+4−3
compiler/Parse/Pattern.hs+2−1
@@ -5,6 +5,7 @@ import Control.Applicative ((<$>),(<*>),pure)
55import Control.Monad
66import Control.Monad.State
77import Data.Char (isUpper)
8+import Data.List (intercalate)
89import Unique
910import Text.Parsec hiding (newline,spaces,State)
1011import Text.Parsec.Indent
@@ -53,7 +54,7 @@ term =
5354
5455patternConstructor :: IParser Pattern
5556patternConstructor = do
56− v <- capVar
57+ v <- intercalate "." <$> dotSep1 capVar
5758 case v of
5859 "True" -> return $ PLiteral (Boolean True)
5960 "False" -> return $ PLiteral (Boolean False)
compiler/Parse/Type.hs+4−3
@@ -40,10 +40,11 @@ record =
4040 whitespace >> hasType >> whitespace
4141 (,) lbl <$> expr
4242
43+capTypeVar = intercalate "." <$> dotSep1 capVar
4344
4445constructor0 :: IParser T.Type
4546constructor0 =
46− do name <- capVar
47+ do name <- capTypeVar
4748 return (T.Data name [])
4849
4950term :: IParser T.Type
@@ -51,7 +52,7 @@ term = list <|> tuple <|> record <|> tvar <|> constructor0
5152
5253app :: IParser T.Type
5354app =
54− do name <- capVar <|> try tupleCtor <?> "type constructor"
55+ do name <- capTypeVar <|> try tupleCtor <?> "type constructor"
5556 args <- spacePrefix term
5657 return (T.Data name args)
5758 where
@@ -70,7 +71,7 @@ expr =
7071 Nothing -> return t1
7172
7273constructor :: IParser (String, [T.Type])
73−constructor = (,) <$> (capVar <?> "another type constructor")
74+constructor = (,) <$> (capTypeVar <?> "another type constructor")
7475 <*> spacePrefix term
7576
7677readType :: String -> Type