From be2969b15385c05983a1302230e6ddb04966a0fa Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Tue, 11 Jul 2017 16:08:28 -0700 Subject: [PATCH] Collapse argument assignments --- src/Language/Python/Syntax.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index bc0adaeaf..5bd2fe1f0 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -136,7 +136,8 @@ expressionStatement :: Assignment expressionStatement = symbol ExpressionStatement *> children declaration expression :: Assignment -expression = await +expression = argument + <|> await <|> binaryOperator <|> booleanOperator <|> call @@ -166,17 +167,20 @@ defaultParameter = makeTerm <$> symbol DefaultParameter <*> children (Statement. typedDefaultParameter :: Assignment typedDefaultParameter = symbol TypedDefaultParameter >>= \ loc -> children (makeAnnotation loc <$> expression <*> expression <*> expression) +argument :: Assignment +argument = makeTerm <$> symbol ListSplatArgument <*> (Syntax.Identifier <$> source) + <|> makeTerm <$> symbol DictionarySplatArgument <*> (Syntax.Identifier <$> source) + <|> makeTerm <$> symbol KeywordArgument <*> children (Statement.Assignment <$> expression <*> expression) + where makeAnnotation loc identifier' type' value' = makeTerm loc (Type.Annotation (makeAssignment loc identifier' value') type') makeAssignment loc identifier' value' = makeTerm loc (Statement.Assignment identifier' value') listSplat :: Assignment listSplat = makeTerm <$> symbol ListSplatParameter <*> (Syntax.Identifier <$> source) - <|> makeTerm <$> symbol ListSplatArgument <*> (Syntax.Identifier <$> source) dictionarySplat :: Assignment dictionarySplat = makeTerm <$> symbol DictionarySplatParameter <*> (Syntax.Identifier <$> source) - <|> makeTerm <$> symbol DictionarySplatArgument <*> (Syntax.Identifier <$> source) decoratedDefinition :: Assignment decoratedDefinition = makeTerm <$> symbol DecoratedDefinition <*> (children $ do @@ -263,7 +267,6 @@ notOperator = makeTerm <$> symbol NotOperator <*> children (Expression.Not <$> e keyword :: Assignment keyword = makeTerm <$> symbol KeywordIdentifier <*> children (Syntax.Identifier <$> source) - <|> makeTerm <$> symbol KeywordArgument <*> children (Statement.Assignment <$> expression <*> expression) tuple :: Assignment tuple = makeTerm <$> symbol Tuple <*> children (Literal.Tuple <$> (many expression))