Skip to content

Commit

Permalink
fix: calc of indentation inside a try block when exception raised
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Wojnarski committed Jun 19, 2021
1 parent 7595c1f commit 21ec1ab
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

## [1.1.4] -

- Bug fix in the import of hypertags from other scripts: local state now includes
all local symbols, not just the output ones.
- Bug fix: exception raised in a "try" block caused "dedent" operations to be skipped,
leading to incorrect calculation of indentations of subsequent blocks.
Changed to always revert to an initial indentation when translating a body node.
- Bug fix: post-translation state of an imported module included only output symbols.
Changed to include all symbols (slots), since they can also be needed
for hypertag expansion.

## [1.1.3] - 2021-04-10

Expand Down
12 changes: 9 additions & 3 deletions src/hypertag/core/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,15 @@ def evaluate(self, state):

class body(node):
def translate(self, state):
return DOM(n.translate(state) for n in self.children)
# return self._translate_all(self.children, state)

indent = state.indentation
try:
return DOM(n.translate(state) for n in self.children)
# return self._translate_all(self.children, state)
finally:
# if an intermediate child node raised an exception, we need to revert the indentation
# manually to make up for missing calls to NODES.dedent.translate()
state.indentation = indent

class xbody_control(body): pass
class xbody_struct (body): pass

Expand Down
33 changes: 33 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,39 @@ def test_101_varia():
"""
assert render(src).strip() == out.strip()

def test_102_bugfix_try_indent():
"""The examples below raised an exception due to skipped dedenting after exception raised inside a try block."""
src = """
html
h2
table
try
a href={int('a')}
try
a href={int('b')}
"""
out = """
<html>
<h2></h2>
<table></table>
</html>
"""
assert render(src).strip() == out.strip()
src = """
tr
try
| {int('a')}
| x
try
| {int('b')}
"""
out = """
<tr>
x
</tr>
"""
assert render(src).strip() == out.strip()


#####################################################################################################################################################
#####
Expand Down

0 comments on commit 21ec1ab

Please sign in to comment.