git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
add ImportDeclaration parser
commit1821620ddf9f12bf9c9117982e4267b3c763ec11 authorBogdan Popa <popa.bogdanp@gmail.com> dateSat 16 Nov 2013, 20:49 (13 years ago) parentaf55178
1 file changed+14−1
src/Language/PureScript/Parser/Declarations.hs+14−1
src/Language/PureScript/Parser/Declarations.hs+14−1
@@ -96,6 +96,18 @@ parseModuleDeclaration = do
9696 decls <- mark (P.many (same *> parseDeclaration))
9797 return $ ModuleDeclaration name decls
9898
99+parseImportDeclaration :: P.Parsec String ParseState Declaration
100+parseImportDeclaration = do
101+ reserved "import"
102+ indented
103+ module_ <- P.sepBy1 properName (lexeme $ P.char '.')
104+ idents <- P.optionMaybe $ do
105+ lexeme $ indented *> P.char '('
106+ idents <- P.sepBy1 parseIdent (lexeme $ indented *> P.char ',')
107+ lexeme $ indented *> P.char ')'
108+ return idents
109+ return $ ImportDeclaration module_ idents
110+
99111parseDeclaration :: P.Parsec String ParseState Declaration
100112parseDeclaration = P.choice
101113 [ parseDataDeclaration
@@ -104,7 +116,8 @@ parseDeclaration = P.choice
104116 , parseValueDeclaration
105117 , parseExternDeclaration
106118 , parseFixityDeclaration
107− , parseModuleDeclaration ] P.<?> "declaration"
119+ , parseModuleDeclaration
120+ , parseImportDeclaration ] P.<?> "declaration"
108121
109122parseDeclarations :: P.Parsec String ParseState [Declaration]
110123parseDeclarations = whiteSpace *> mark (P.many (same *> parseDeclaration)) <* P.eof