@@ -1,4 +1,4 @@
1−module Parse.Expression (def,term) where
1+module Parse.Expression (def,term,typeAnnotation) where
3import Control.Arrow ((***))
3import Control.Arrow ((***))
4import Control.Applicative ((<$>), (<*>))
4import Control.Applicative ((<$>), (<*>))
@@ -208,7 +208,8 @@ expr = addLocation (choice [ ifExpr, letExpr, caseExpr ])
208 <|> binaryExpr
208 <|> binaryExpr
209 <?> "an expression"
209 <?> "an expression"
211−funcDef =
211+defStart :: IParser [Pattern]
212 choice [ do p1 <- try Pattern.term
213 choice [ do p1 <- try Pattern.term
213 infics p1 <|> func p1
214 infics p1 <|> func p1
214 , func =<< (PVar <$> parens symOp)
215 , func =<< (PVar <$> parens symOp)
@@ -231,19 +232,20 @@ makeFunction :: [Pattern] -> LExpr t v -> LExpr t v
231makeFunction args body@(L s _) =
232makeFunction args body@(L s _) =
232 foldr (\arg body' -> L s $ Lambda arg body') body args
233 foldr (\arg body' -> L s $ Lambda arg body') body args
234−assignExpr :: IParser (Def t v)
235+definition :: IParser (Def t v)
235−assignExpr = withPos $ do
236+definition = withPos $ do
236− (name:args) <- funcDef
237+ (name:args) <- defStart
237 whitespace >> string "=" >> whitespace
238 whitespace >> string "=" >> whitespace
238 body <- expr
239 body <- expr
239 return . Def name $ makeFunction args body
240 return . Def name $ makeFunction args body
241typeAnnotation :: IParser (Def t v)
242typeAnnotation :: IParser (Def t v)
242typeAnnotation = TypeAnnotation <$> try start <*> Type.expr
243typeAnnotation = TypeAnnotation <$> try start <*> Type.expr
244− start = do v <- lowVar <|> parens symOp
246+ v <- lowVar <|> parens symOp
245− whitespace ; hasType ; whitespace
247+ whitespace ; hasType ; whitespace
246− return v
248+ return v
248def :: IParser (Def t v)
250def :: IParser (Def t v)
249−def = typeAnnotation <|> assignExpr
251+def = typeAnnotation <|> definition