diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index fbe86c03b..5ab012c5f 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -28,6 +28,7 @@ import qualified Term type Syntax = '[ Comment.Comment + , Declaration.Class , Declaration.Comprehension , Declaration.Function , Declaration.Import @@ -96,7 +97,7 @@ assignment :: Assignment assignment = makeTerm <$> symbol Module <*> children (many declaration) declaration :: Assignment -declaration = handleError $ comment <|> statement <|> expression <|> functionDefinition +declaration = handleError $ classDefinition <|> comment <|> functionDefinition <|> expression <|> statement statement :: Assignment statement = assertStatement @@ -173,6 +174,11 @@ functionDefinition = makeTerm <$> symbol FunctionDefinition <*> children f functionBody <- expressionStatement return $ Declaration.Function functionType functionName' functionParameters functionBody +classDefinition :: Assignment +classDefinition = makeTerm <$> symbol ClassDefinition <*> children (Declaration.Class <$> identifier <*> argumentList <*> (many declaration)) + where argumentList = symbol ArgumentList *> children (many expression) + <|> pure [] + typedParameter :: Assignment typedParameter = makeTerm <$> symbol TypedParameter <*> children (flip Syntax.TypedIdentifier <$> identifier <*> type')