Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

Commit

Permalink
feat(Py): Added Exception parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
beneboy committed Sep 2, 2019
1 parent 0199b1e commit 5e55bcb
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions py/stencila/schema/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,17 @@ def parse_statement(self, statement: typing.Union[ast.stmt, typing.List[ast.stmt
self.parse_statement(statement.value)
elif isinstance(statement, ast.AugAssign):
self.parse_aug_assign(statement)
elif isinstance(statement, ast.If):
self.parse_if(statement)
elif isinstance(statement, (ast.If, ast.While)):
self.parse_if_while(statement)
elif isinstance(statement, ast.Compare):
self.parse_compare(statement)
elif isinstance(statement, ast.For):
self.parse_for(statement)
elif isinstance(statement, (ast.ClassDef, ast.Num, ast.Str)):
elif isinstance(statement, ast.Try):
self.parse_try(statement)
elif isinstance(statement, ast.ExceptHandler):
self.parse_except_handler(statement)
elif isinstance(statement, (ast.ClassDef, ast.Num, ast.Str, ast.Pass)):
pass
else:
raise TypeError('Unrecognized statement: {}'.format(statement))
Expand Down Expand Up @@ -372,7 +376,7 @@ def parse_aug_assign(self, statement: ast.AugAssign) -> None:

self.parse_statement(statement.value)

def parse_if(self, statement: ast.If) -> None:
def parse_if_while(self, statement: typing.Union[ast.If, ast.While]) -> None:
self.parse_statement(statement.test)
self.parse_statement(statement.body)
self.parse_statement(statement.orelse)
Expand All @@ -387,6 +391,15 @@ def parse_for(self, statement: ast.For) -> None:
self.parse_statement(statement.iter)
self.parse_statement(statement.body)

def parse_try(self, statement: ast.Try) -> None:
self.parse_statement(statement.handlers)
self.parse_statement(statement.body)
self.parse_statement(statement.finalbody)
self.parse_statement(statement.orelse)

def parse_except_handler(self, statement: ast.ExceptHandler) -> None:
self.parse_statement(statement.body)

def find_file_reads(self, chunk_ast: ast.Module) -> None:
for node in ast.walk(chunk_ast):
if isinstance(node, ast.Call) and hasattr(node, 'func') and node.func.id == 'open':
Expand Down

0 comments on commit 5e55bcb

Please sign in to comment.