on master help sign in
Be more aggressive in committing to args in definitions
commit6de79b8bce49c44716b97600ed0afa91e6697063 authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 10 Oct 2016, 13:53 (10 years ago) parentcf107f9
1 file changed+24−18
src/Parse/Expression.hs+24−18
src/Parse/Expression.hs+24−18
@@ -277,26 +277,19 @@ def :: IParser Source.Def
277277def =
278278 addLocation $ Indent.withPos $
279279 do start <- defStart
280+ whitespace
280281 case start of
281282 A.A _ (P.Var name) ->
282− do whitespace
283− choice
284− [ do hasType
285− whitespace
286− tipe <- Type.expr
287− return $ Source.Annotation name tipe
288− , do args <- spacePrefix Pattern.term
289− padded equals
290− body <- expr
291− return $ Source.Definition start (makeFunction args body)
292− ]
283+ choice
284+ [ do hasType
285+ whitespace
286+ tipe <- Type.expr
287+ return $ Source.Annotation name tipe
288+ , defEnd start []
289+ ]
293290
294291 _ ->
295− do args <- spacePrefix Pattern.term
296− padded equals
297− body <- expr
298− return $ Source.Definition start (makeFunction args body)
299−
292+ defEnd start []
300293
301294
302295defStart :: IParser P.Raw
@@ -307,6 +300,19 @@ defStart =
307300 ]
308301
309302
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+
310316makeFunction :: [P.Raw] -> Source.Expr -> Source.Expr
311−makeFunction args body@(A.A ann _) =
312− foldr (\arg body' -> A.A ann $ E.Lambda arg body') body args
317+makeFunction revArgs body@(A.A ann _) =
318+ List.foldl' (\expr arg -> A.A ann $ E.Lambda arg expr) body revArgs