on master help sign in
Be more aggressive in committing to args in definitions
6de79b8Evan Czaplicki
src/Parse/Expression.hs+24−18
@@ -277,26 +277,19 @@ def :: IParser Source.Def
277def =
277def =
278 addLocation $ Indent.withPos $
278 addLocation $ Indent.withPos $
279 do start <- defStart
279 do start <- defStart
280+ whitespace
280 case start of
281 case start of
281 A.A _ (P.Var name) ->
282 A.A _ (P.Var name) ->
282− do whitespace
283− choice
283+ choice
284− [ do hasType
284+ [ do hasType
285− whitespace
285+ whitespace
286− tipe <- Type.expr
286+ tipe <- Type.expr
287− return $ Source.Annotation name tipe
287+ return $ Source.Annotation name tipe
288− , do args <- spacePrefix Pattern.term
288+ , defEnd start []
289− padded equals
290− body <- expr
291− return $ Source.Definition start (makeFunction args body)
292− ]
289+ ]
293
290
294 _ ->
291 _ ->
295− do args <- spacePrefix Pattern.term
292+ defEnd start []
296− padded equals
297− body <- expr
298− return $ Source.Definition start (makeFunction args body)
299−
300
293
301
294
302defStart :: IParser P.Raw
295defStart :: IParser P.Raw
@@ -307,6 +300,19 @@ defStart =
307 ]
300 ]
308
301
309
302
303+defEnd :: P.Raw -> [P.Raw] -> IParser Source.Def'
304+defEnd start revArgs =
305+ choice
306+ [ do arg <- Pattern.term
307+ whitespace
308+ defEnd start (arg : revArgs)
309+ , do equals
310+ whitespace
311+ body <- expr
312+ return $ Source.Definition start (makeFunction revArgs body)
313+ ]
314+
315+
310makeFunction :: [P.Raw] -> Source.Expr -> Source.Expr
316makeFunction :: [P.Raw] -> Source.Expr -> Source.Expr
311−makeFunction args body@(A.A ann _) =
317+makeFunction revArgs body@(A.A ann _) =
312− foldr (\arg body' -> A.A ann $ E.Lambda arg body') body args
318+ List.foldl' (\expr arg -> A.A ann $ E.Lambda arg expr) body revArgs