From 0e5a22da2bc367a2b3550a071066eabc9d176391 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Wed, 12 Jul 2017 18:51:14 -0700 Subject: [PATCH] Assign nested decorators --- src/Language/Python/Syntax.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index e0281e1d4..4cf296d88 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -185,10 +185,11 @@ parameter = makeTerm <$> symbol DefaultParameter <*> children (Statement.Assign makeAssignment loc identifier' value' = makeTerm loc (Statement.Assignment identifier' value') decoratedDefinition :: Assignment -decoratedDefinition = makeTerm <$> symbol DecoratedDefinition <*> (children $ do - (a, b) <- (symbol Decorator *> (children ((,) <$> expression <*> (symbol ArgumentList *> children ((many expression) <|> (many emptyTerm)))))) - dec <- declaration - pure (Declaration.Decorator a b dec)) +decoratedDefinition = symbol DecoratedDefinition *> children (makeDecorator <$> partialDecorator <*> (flip (foldr makeDecorator) <$> many partialDecorator <*> declaration)) + where + makeDecorator (loc, partialDecorator') next = makeTerm loc (partialDecorator' next) + partialDecorator = (,) <$> symbol Decorator <*> children decorator' + decorator' = Declaration.Decorator <$> expression <* symbol ArgumentList <*> children (many expression <|> many emptyTerm) withStatement :: Assignment withStatement = makeTerm <$> symbol WithStatement <*> (children $ do