From 55816f31276905ec610e3cf51655ccf7c16a23e9 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Fri, 9 Jun 2017 12:03:54 -0700 Subject: [PATCH] Assign function definitions --- src/Language/Python/Syntax.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index 5d24ba296..467317b7d 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -96,7 +96,7 @@ assignment :: Assignment assignment = makeTerm <$> symbol Module <*> children (many declaration) declaration :: Assignment -declaration = handleError $ comment <|> statement <|> expression +declaration = handleError $ asyncFunctionDefinition <|> comment <|> functionDefinition <|> statement <|> expression statement :: Assignment statement = assertStatement @@ -127,8 +127,7 @@ expressionStatement :: Assignment expressionStatement = symbol ExpressionStatement *> children expression expression :: Assignment -expression = asyncFunctionDefinition - <|> await +expression = await <|> binaryOperator <|> booleanOperator <|> call @@ -170,6 +169,14 @@ asyncFunctionDefinition = makeTerm <$> symbol AsyncFunctionDefinition <*> childr functionBody <- expressionStatement return $ Declaration.Function functionType functionName' functionParameters functionBody) +functionDefinition :: Assignment +functionDefinition = makeTerm <$> symbol FunctionDefinition <*> children (do + functionName' <- identifier + functionParameters <- (symbol Parameters *> children (many expression)) + functionType <- optional (type') + functionBody <- expressionStatement + return $ Declaration.Function functionType functionName' functionParameters functionBody) + typedParameter :: Assignment typedParameter = makeTerm <$> symbol TypedParameter <*> children (flip Syntax.TypedIdentifier <$> identifier <*> type')