diff --git a/py/stencila/schema/interpreter.py b/py/stencila/schema/interpreter.py index cb3d6b78..9e79879f 100644 --- a/py/stencila/schema/interpreter.py +++ b/py/stencila/schema/interpreter.py @@ -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)) @@ -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) @@ -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':