@@ -1,4 +1,4 @@
1−module Parse.Parser (parseProgram, parseDependencies, parseInfix) where
1+module Parse.Parser (parseProgram) where
22
33import SourceSyntax.Module
44import Control.Applicative ((<$>), (<*>))
@@ -6,6 +6,7 @@ import Control.Monad
66import Data.Char (isSymbol, isDigit)
77import Data.List (foldl',intercalate)
88import Text.Parsec hiding (newline,spaces)
9+import qualified Text.PrettyPrint as P
910
1011import Parse.Helpers
1112import Parse.Binop (infixStmt, OpTable)
@@ -30,26 +31,11 @@ program = do
3031 optional freshLine ; optional spaces ; eof
3132 return $ Module names exports is declarations
3233
34+parseProgram :: String -> Either [P.Doc] (Module t v)
3335parseProgram = setupParser program
3436
35−parseDependencies :: String -> Either String (String, [String])
36−parseDependencies =
37− setupParser $ do
38− optional skip
39− (,) <$> option "Main" moduleName <*> option [] imprts
40− where
41− skip = try (manyTill anyChar (try (string "/**")))
42− imprts = fmap (map fst) imports `followedBy` freshLine
43− getName = intercalate "." . fst
44− moduleName = do optional freshLine
45− getName <$> moduleDef `followedBy` freshLine
46−
47−parseInfix :: String -> Either String OpTable
48−parseInfix = setupParser . many $ do
49− manyTill ((whitespace >> return ' ') <|> anyChar) freshLine
50− infixStmt
51−
37+setupParser :: IParser a -> String -> Either [P.Doc] a
5238setupParser p source =
5339 case iParse p "" source of
5440 Right result -> Right result
55− Left err -> Left $ "Parse error at " ++ show err
41+ Left err -> Left [ P.sep . map P.text . words $ "Parse error at " ++ show err ]