From 27e79fecb155ae5277aa39489bcd64109c070a61 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Wed, 17 May 2017 15:47:40 -0700 Subject: [PATCH] Assign Arithmetic BinaryOperators --- src/Language/Python/Syntax.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index 16c03f923..35e32c0c5 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -18,6 +18,7 @@ type Syntax = Union Syntax' type Syntax' = '[ Comment.Comment , Declaration.Import + , Expression.Arithmetic , Expression.Tuple , Expression.Unary , Literal.Boolean @@ -51,13 +52,23 @@ tuple :: HasCallStack => Assignment (Node Grammar) (Term Syntax Location) tuple = makeTerm <$> symbol Tuple <*> children (Expression.Tuple <$> (many expression)) expression :: HasCallStack => Assignment (Node Grammar) (Term Syntax Location) -expression = identifier <|> statement <|> unaryOperator <|> tuple <|> literal +expression = identifier <|> statement <|> unaryOperator <|> binaryOperator <|> tuple <|> literal unaryOperator :: HasCallStack => Assignment (Node Grammar) (Term Syntax Location) unaryOperator = makeTerm <$> symbol UnaryOperator <*> children ( Expression.UCompliment <$> (symbol AnonTilde *> expression) <|> Expression.UMinus <$> (symbol AnonMinus *> expression) <|> Expression.UPlus <$> (symbol AnonPlus *> expression)) +binaryOperator :: HasCallStack => Assignment (Node Grammar) (Term Syntax Location) +binaryOperator = makeTerm <$> symbol BinaryOperator <*> children ( expression >>= \ lexpression -> arithmetic lexpression ) + where + arithmetic lexpression = symbol AnonPlus *> (Expression.Plus lexpression <$> expression) + <|> symbol AnonMinus *> (Expression.Minus lexpression <$> expression) + <|> symbol AnonStar *> (Expression.Times lexpression <$> expression) + <|> symbol AnonSlash *> (Expression.DividedBy lexpression <$> expression) + <|> symbol AnonSlashSlash *> (Expression.DividedBy lexpression <$> expression) + <|> symbol AnonPercent *> (Expression.Modulo lexpression <$> expression) + <|> symbol AnonStarStar *> (Expression.Power lexpression <$> expression) identifier :: HasCallStack => Assignment (Node Grammar) (Term Syntax Location) identifier = makeTerm <$> symbol Identifier <*> (Syntax.Identifier <$> source)