@@ -6,7 +6,7 @@ import Text.Parsec hiding (newline,spaces)
7import Parse.Helpers
7import Parse.Helpers
8import AST.Module (ImportMethod(..))
8import AST.Module (ImportMethod(..))
9−import AST.Variable (Listing(..), Value(..))
9+import AST.Variable (Listing(..), Value(..), openListing)
11getModuleName :: String -> Maybe String
11getModuleName :: String -> Maybe String
12getModuleName source =
12getModuleName source =
@@ -41,12 +41,11 @@ import' =
41 (,) name <$> option (As name) method
41 (,) name <$> option (As name) method
43 method :: IParser ImportMethod
43 method :: IParser ImportMethod
44− method = try $ do whitespace
45− as' <|> importing'
44+ method = as' <|> importing'
47 as' :: IParser ImportMethod
46 as' :: IParser ImportMethod
49− reserved "as"
48+ try (whitespace >> reserved "as")
50 whitespace
49 whitespace
51 As <$> capVar <?> "alias for module"
50 As <$> capVar <?> "alias for module"
@@ -54,13 +53,24 @@ import' =
54 importing' = Open <$> listing value
53 importing' = Open <$> listing value
56listing :: IParser a -> IParser (Listing a)
55listing :: IParser a -> IParser (Listing a)
57−listing item =
56+listing item =
57+ do try (whitespace >> char '(')
58− parens (choice [ const (Listing [] True) <$> string ".."
59+ listing <- choice [ const openListing <$> string ".."
59− , Listing <$> commaSep1 item <*> return False
60+ , Listing <$> commaSep1 item <*> return False
60− ] <?> "listing of values (x,y,z)")
61+ ] <?> "listing of values (x,y,z)"
62value :: IParser Value
66value :: IParser Value
63−value = choice [ Value <$> (lowVar <|> parens symOp)
69+ val = Value <$> (lowVar <|> parens symOp)
64− , ADT <$> capVar <*> listing capVar
73+ maybeCtors <- optionMaybe (listing capVar)
75+ Nothing -> return (Alias name)
76+ Just ctors -> return (ADT name ctors)