git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Parse newtypes
commite7a32d58092d0ca8fa921f02c9a766aac3d3b95b authorGary Burgess <gary.burgess@gmail.com> dateSat 26 Jul 2014, 12:08 (12 years ago) parent11930f0
2 files changed+11
src/Language/PureScript/Parser/Common.hs+1 src/Language/PureScript/Parser/Declarations.hs+10
src/Language/PureScript/Parser/Common.hs+1
@@ -31,6 +31,7 @@ import Language.PureScript.Names
3131--
3232reservedPsNames :: [String]
3333reservedPsNames = [ "data"
34+ , "newtype"
3435 , "type"
3536 , "foreign"
3637 , "import"
src/Language/PureScript/Parser/Declarations.hs+10
@@ -56,6 +56,15 @@ parseDataDeclaration = do
5656 sepBy1 ((,) <$> properName <*> P.many (indented *> parseTypeAtom)) pipe
5757 return $ DataDeclaration Data name tyArgs ctors
5858
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+
5968parseTypeDeclaration :: P.Parsec String ParseState Declaration
6069parseTypeDeclaration =
6170 TypeDeclaration <$> P.try (parseIdent <* lexeme (indented *> P.string "::"))
@@ -181,6 +190,7 @@ positioned d = PositionedDeclaration <$> sourcePos <*> d
181190parseDeclaration :: P.Parsec String ParseState Declaration
182191parseDeclaration = positioned (P.choice
183192 [ parseDataDeclaration
193+ , parseNewtypeDeclaration
184194 , parseTypeDeclaration
185195 , parseTypeSynonymDeclaration
186196 , parseValueDeclaration