@@ -24,7 +24,7 @@ import Language.PureScript.Parser.Common
24import Control.Applicative
24import Control.Applicative
25import qualified Text.Parsec as P
25import qualified Text.Parsec as P
26import qualified Text.Parsec.Expr as P
26import qualified Text.Parsec.Expr as P
27−import Control.Monad (unless)
27+import Control.Monad (when, unless)
29parseNumber :: P.Parsec String ParseState Type
29parseNumber :: P.Parsec String ParseState Type
30parseNumber = const Number <$> reserved "Number"
30parseNumber = const Number <$> reserved "Number"
@@ -42,7 +42,7 @@ parseArrayOf :: P.Parsec String ParseState Type
42parseArrayOf = squares $ TypeApp Array <$> parseType
42parseArrayOf = squares $ TypeApp Array <$> parseType
44parseObject :: P.Parsec String ParseState Type
44parseObject :: P.Parsec String ParseState Type
45−parseObject = braces $ Object <$> parseRow
45+parseObject = braces $ Object <$> parseRow False
47parseFunction :: P.Parsec String ParseState Type
47parseFunction :: P.Parsec String ParseState Type
48parseFunction = do
48parseFunction = do
@@ -69,11 +69,10 @@ parseTypeAtom = indented *> P.choice (map P.try
69 , parseArray
69 , parseArray
70 , parseArrayOf
70 , parseArrayOf
71 , parseObject
71 , parseObject
73 , parseTypeVariable
72 , parseTypeVariable
74 , parseTypeConstructor
73 , parseTypeConstructor
75 , parseForAll
74 , parseForAll
76− , parens parseRow
75+ , parens (parseRow True)
77 , parens parseType ])
76 , parens parseType ])
79parseConstrainedType :: P.Parsec String ParseState Type
78parseConstrainedType :: P.Parsec String ParseState Type
@@ -91,11 +90,10 @@ parseConstrainedType = do
91 return $ maybe ty (flip ConstrainedType ty) constraints
90 return $ maybe ty (flip ConstrainedType ty) constraints
93parseAnyType :: P.Parsec String ParseState Type
92parseAnyType :: P.Parsec String ParseState Type
94−parseAnyType = (P.buildExpressionParser operators . buildPostfixParser postfixTable $ parseTypeAtom) P.<?> "type"
93+parseAnyType = (P.buildExpressionParser operators $ parseTypeAtom) <|> parseFunction P.<?> "type"
96− postfixTable :: [Type -> P.Parsec String ParseState Type]
95+ operators = [ [ P.Infix (return TypeApp) P.AssocLeft ]
97− postfixTable = [ \x -> TypeApp x <$> P.try (indented *> parseTypeAtom) ]
98− operators = [ [ P.Infix (lexeme (P.try (P.string "->")) >> return (\t1 t2 -> Function [t1] t2)) P.AssocRight ] ]
96+ , [ P.Infix (P.try (lexeme (P.string "->")) >> return (\t1 t2 -> Function [t1] t2)) P.AssocRight ] ]
101-- Parse a monotype
99-- Parse a monotype
@@ -121,9 +119,6 @@ parseNameAndType p = (,) <$> (indented *> identifier <* indented <* lexeme (P.st
121parseRowEnding :: P.Parsec String ParseState Type
119parseRowEnding :: P.Parsec String ParseState Type
122parseRowEnding = P.option REmpty (TypeVar <$> (lexeme (indented *> P.char '|') *> indented *> identifier))
120parseRowEnding = P.option REmpty (TypeVar <$> (lexeme (indented *> P.char '|') *> indented *> identifier))
124−parseRow :: P.Parsec String ParseState Type
122+parseRow :: Bool -> P.Parsec String ParseState Type
125−parseRow = (fromList <$> (commaSep $ parseNameAndType parsePolyType) <*> parseRowEnding) P.<?> "row"
123+parseRow nonEmpty = (curry rowFromList <$> (many $ parseNameAndType parsePolyType) <*> parseRowEnding) P.<?> "row"
126− where
124+ where many = if nonEmpty then commaSep1 else commaSep
127− fromList :: [(String, Type)] -> Type -> Type
129− fromList ((name, t):ts) r = RCons name t (fromList ts r)