git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Parse newtypes
e7a32d5Gary Burgess
src/Language/PureScript/Parser/Common.hs+1
@@ -31,6 +31,7 @@ import Language.PureScript.Names
31--
31--
32reservedPsNames :: [String]
32reservedPsNames :: [String]
33reservedPsNames = [ "data"
33reservedPsNames = [ "data"
34+ , "newtype"
34 , "type"
35 , "type"
35 , "foreign"
36 , "foreign"
36 , "import"
37 , "import"
src/Language/PureScript/Parser/Declarations.hs+10
@@ -56,6 +56,15 @@ parseDataDeclaration = do
56 sepBy1 ((,) <$> properName <*> P.many (indented *> parseTypeAtom)) pipe
56 sepBy1 ((,) <$> properName <*> P.many (indented *> parseTypeAtom)) pipe
57 return $ DataDeclaration Data name tyArgs ctors
57 return $ DataDeclaration Data name tyArgs ctors
58
58
59+parseNewtypeDeclaration :: P.Parsec String ParseState Declaration
60+parseNewtypeDeclaration = do
61+ reserved "newtype"
62+ name <- indented *> properName
63+ tyArg <- P.option [] $ return <$> (indented *> identifier)
64+ _ <- lexeme $ indented *> P.char '='
65+ ctor <- (,) <$> properName <*> (return <$> (indented *> parseTypeAtom))
66+ return $ DataDeclaration Newtype name tyArg [ctor]
67+
59parseTypeDeclaration :: P.Parsec String ParseState Declaration
68parseTypeDeclaration :: P.Parsec String ParseState Declaration
60parseTypeDeclaration =
69parseTypeDeclaration =
61 TypeDeclaration <$> P.try (parseIdent <* lexeme (indented *> P.string "::"))
70 TypeDeclaration <$> P.try (parseIdent <* lexeme (indented *> P.string "::"))
@@ -181,6 +190,7 @@ positioned d = PositionedDeclaration <$> sourcePos <*> d
181parseDeclaration :: P.Parsec String ParseState Declaration
190parseDeclaration :: P.Parsec String ParseState Declaration
182parseDeclaration = positioned (P.choice
191parseDeclaration = positioned (P.choice
183 [ parseDataDeclaration
192 [ parseDataDeclaration
193+ , parseNewtypeDeclaration
184 , parseTypeDeclaration
194 , parseTypeDeclaration
185 , parseTypeSynonymDeclaration
195 , parseTypeSynonymDeclaration
186 , parseValueDeclaration
196 , parseValueDeclaration