git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
add ImportDeclaration parser
1821620Bogdan Popa
src/Language/PureScript/Parser/Declarations.hs+14−1
@@ -96,6 +96,18 @@ parseModuleDeclaration = do
96 decls <- mark (P.many (same *> parseDeclaration))
96 decls <- mark (P.many (same *> parseDeclaration))
97 return $ ModuleDeclaration name decls
97 return $ ModuleDeclaration name decls
98
98
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+
99parseDeclaration :: P.Parsec String ParseState Declaration
111parseDeclaration :: P.Parsec String ParseState Declaration
100parseDeclaration = P.choice
112parseDeclaration = P.choice
101 [ parseDataDeclaration
113 [ parseDataDeclaration
@@ -104,7 +116,8 @@ parseDeclaration = P.choice
104 , parseValueDeclaration
116 , parseValueDeclaration
105 , parseExternDeclaration
117 , parseExternDeclaration
106 , parseFixityDeclaration
118 , parseFixityDeclaration
107− , parseModuleDeclaration ] P.<?> "declaration"
119+ , parseModuleDeclaration
120+ , parseImportDeclaration ] P.<?> "declaration"
108
121
109parseDeclarations :: P.Parsec String ParseState [Declaration]
122parseDeclarations :: P.Parsec String ParseState [Declaration]
110parseDeclarations = whiteSpace *> mark (P.many (same *> parseDeclaration)) <* P.eof
123parseDeclarations = whiteSpace *> mark (P.many (same *> parseDeclaration)) <* P.eof