From 921be5bfca4e4a79d930a98b015cfff3818d2a87 Mon Sep 17 00:00:00 2001 From: Rick Winfrey Date: Thu, 13 Jul 2017 15:52:03 -0700 Subject: [PATCH] Assign Let statements in Except clauses --- src/Language/Python/Syntax.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index fd94c19d7..70c272bbe 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -216,6 +216,12 @@ tryStatement :: Assignment tryStatement = makeTerm <$> symbol TryStatement <*> children (Statement.Try <$> expression <*> (many (expression <|> elseClause))) where elseClause = makeTerm <$> symbol ElseClause <*> children (Statement.Else <$> emptyTerm <*> (makeTerm <$> location <*> (many expression))) +exceptClause :: Assignment +exceptClause = makeTerm <$> symbol ExceptClause <*> children + (Statement.Catch <$> ((makeTerm <$> location <*> (uncurry Statement.Let . swap <$> ((,) <$> identifier <* symbol AnonAs <*> identifier) <*> emptyTerm)) + <|> (makeTerm <$> location <*> (many identifier))) + <*> (makeTerm <$> location <*> (many expression))) + functionDefinition :: Assignment functionDefinition = (symbol FunctionDefinition >>= \ loc -> children (makeFunctionDeclaration loc <$> identifier <*> (symbol Parameters *> children (many expression)) <*> (optional (symbol Type *> children expression)) <*> (makeTerm <$> location <*> many declaration))) <|> (symbol AsyncFunctionDefinition >>= \ loc -> children (makeAsyncFunctionDeclaration loc <$> async' <*> identifier <*> (symbol Parameters *> children (many expression)) <*> (optional (symbol Type *> children expression)) <*> (makeTerm <$> location <*> many declaration))) @@ -235,10 +241,6 @@ classDefinition = makeTerm <$> symbol ClassDefinition <*> children (Declaration. type' :: Assignment type' = symbol Type *> children expression --- TODO: support As expressions -exceptClause :: Assignment -exceptClause = makeTerm <$> symbol ExceptClause <*> children (Statement.Catch <$> (makeTerm <$> location <*> (many identifier)) <*> (makeTerm <$> location <*> (many expression))) - finallyClause :: Assignment finallyClause = makeTerm <$> symbol FinallyClause <*> children (Statement.Finally <$> expression)