@@ -1,4 +1,4 @@
1−module Parse.Expression (term, annotation, definition, expr, def) where
1+module Parse.Expression (term, expr, def) where
3import qualified Data.List as List
3import qualified Data.List as List
4import Text.Parsec hiding (newline, spaces)
4import Text.Parsec hiding (newline, spaces)
@@ -15,7 +15,6 @@ import qualified AST.Expression.General as E
15import qualified AST.Expression.Source as Source
15import qualified AST.Expression.Source as Source
16import qualified AST.Literal as L
16import qualified AST.Literal as L
17import qualified AST.Pattern as P
17import qualified AST.Pattern as P
18−import qualified AST.Type as T
19import qualified AST.Variable as Var
18import qualified AST.Variable as Var
20import qualified Reporting.Annotation as A
19import qualified Reporting.Annotation as A
@@ -267,8 +266,7 @@ letExpr :: IParser Source.Expr'
268 do try (reserved "let")
267 do try (reserved "let")
269 whitespace
268 whitespace
271− Indent.block (def <* whitespace)
269+ defs <- Indent.block (def <* whitespace)
272 whitespace
270 whitespace
273 reserved "in"
271 reserved "in"
274 whitespace
272 whitespace
@@ -277,49 +275,38 @@ letExpr =
278def :: IParser Source.Def
276def :: IParser Source.Def
278+ addLocation $ Indent.withPos $
279+ do start <- defStart
281+ A.A _ (P.Var name) ->
287+ return $ Source.Annotation name tipe
288+ , do args <- spacePrefix Pattern.term
291+ return $ Source.Definition start (makeFunction args body)
295+ do args <- spacePrefix Pattern.term
298+ return $ Source.Definition start (makeFunction args body)
302+defStart :: IParser P.Raw
281− [ annotation Source.Annotation
305+ [ addLocation (try (P.Var <$> parens Binop.infixOp))
282− , definition Source.Definition
306+ , Pattern.term
290−annotation :: (String -> T.Raw -> a) -> IParser (A.Located a)
294− do v <- lowVar <|> parens Binop.infixOp
298− addLocation (creator <$> try start <*> Type.expr)
305−definition :: (P.Raw -> Source.Expr -> a) -> IParser (A.Located a)
309− do (name, args) <- defStart
312− return . creator name $ makeFunction args body
315makeFunction :: [P.Raw] -> Source.Expr -> Source.Expr
310makeFunction :: [P.Raw] -> Source.Expr -> Source.Expr
316makeFunction args body@(A.A ann _) =
311makeFunction args body@(A.A ann _) =
317 foldr (\arg body' -> A.A ann $ E.Lambda arg body') body args
312 foldr (\arg body' -> A.A ann $ E.Lambda arg body') body args
320−defStart :: IParser (P.Raw, [P.Raw])
322− expecting "the definition of a value (x = ...)" $
323− do starter <- try Pattern.term <|> addLocation (P.Var <$> parens Binop.infixOp)
324− args <- spacePrefix Pattern.term
325− return (starter, args)