Skip to content

Commit

Permalink
Always eagerly advance to the line before the first block contents in…
Browse files Browse the repository at this point in the history
… the ATL parser.
  • Loading branch information
CensoredUsername committed Feb 21, 2024
1 parent edd730c commit ed4e330
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions decompiler/atldecompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ def print_node(self, ast):
# Line advancement logic:
if hasattr(ast, "loc"):
if isinstance(ast, renpy.atl.RawBlock):
# note: the location property of a RawBlock points to the first line of the block,
# not the statement that created it.
# it can also contain the following nonsense if there was no block for some reason.
if ast.loc != ('', 0):
self.advance_to_line(ast.loc[1] - 1)
self.advance_to_block(ast)

else:
self.advance_to_line(ast.loc[1])
Expand All @@ -58,6 +54,13 @@ def print_block(self, block):
self.indent()
self.write("pass")

def advance_to_block(self, block):
# note: the location property of a RawBlock points to the first line of the block,
# not the statement that created it.
# it can also contain the following nonsense if there was no block for some reason.
if block.loc != ('', 0):
self.advance_to_line(block.loc[1] - 1)

@dispatch(renpy.atl.RawMultipurpose)
def print_atl_rawmulti(self, ast):
warp_words = WordConcatenator(False)
Expand Down Expand Up @@ -130,13 +133,15 @@ def print_atl_rawblock(self, ast):
@dispatch(renpy.atl.RawChild)
def print_atl_rawchild(self, ast):
for child in ast.children:
self.advance_to_block(child)
self.indent()
self.write("contains:")
self.print_block(child)

@dispatch(renpy.atl.RawChoice)
def print_atl_rawchoice(self, ast):
for chance, block in ast.choices:
self.advance_to_block(block)
self.indent()
self.write("choice")
if chance != "1.0":
Expand Down Expand Up @@ -167,13 +172,15 @@ def print_atl_rawfunction(self, ast):
def print_atl_rawon(self, ast):
for name, block in sorted(ast.handlers.items(),
key=lambda i: i[1].loc[1]):
self.advance_to_block(block)
self.indent()
self.write("on %s:" % name)
self.print_block(block)

@dispatch(renpy.atl.RawParallel)
def print_atl_rawparallel(self, ast):
for block in ast.blocks:
self.advance_to_block(block)
self.indent()
self.write("parallel:")
self.print_block(block)
Expand Down

0 comments on commit ed4e330

Please sign in to comment.