@@ -6,7 +6,7 @@ import Text.Parsec hiding (newline,spaces)
66
77import Parse.Helpers
88import AST.Module (ImportMethod(..))
9−import AST.Variable (Listing(..), Value(..))
9+import AST.Variable (Listing(..), Value(..), openListing)
1010
1111getModuleName :: String -> Maybe String
1212getModuleName source =
@@ -41,12 +41,11 @@ import' =
4141 (,) name <$> option (As name) method
4242 where
4343 method :: IParser ImportMethod
44− method = try $ do whitespace
45− as' <|> importing'
44+ method = as' <|> importing'
4645
4746 as' :: IParser ImportMethod
4847 as' = do
49− reserved "as"
48+ try (whitespace >> reserved "as")
5049 whitespace
5150 As <$> capVar <?> "alias for module"
5251
@@ -54,13 +53,24 @@ import' =
5453 importing' = Open <$> listing value
5554
5655listing :: IParser a -> IParser (Listing a)
57−listing item =
58− parens (choice [ const (Listing [] True) <$> string ".."
59− , Listing <$> commaSep1 item <*> return False
60− ] <?> "listing of values (x,y,z)")
56+listing item =
57+ do try (whitespace >> char '(')
58+ whitespace
59+ listing <- choice [ const openListing <$> string ".."
60+ , Listing <$> commaSep1 item <*> return False
61+ ] <?> "listing of values (x,y,z)"
62+ whitespace
63+ char ')'
64+ return listing
6165
6266value :: IParser Value
63−value = choice [ Value <$> (lowVar <|> parens symOp)
64− , ADT <$> capVar <*> listing capVar
65− ]
67+value = val <|> tipe
68+ where
69+ val = Value <$> (lowVar <|> parens symOp)
6670
71+ tipe = do
72+ name <- capVar
73+ maybeCtors <- optionMaybe (listing capVar)
74+ case maybeCtors of
75+ Nothing -> return (Alias name)
76+ Just ctors -> return (ADT name ctors)