Skip to content

Commit

Permalink
Handle SL2 as clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
CensoredUsername committed Feb 25, 2020
1 parent d1a58cc commit d1f8934
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions decompiler/sl2decompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ def print_displayable(self, ast, has_block=False):
self.write(name)
if ast.positional:
self.write(" " + " ".join(ast.positional))
if hasattr(ast, 'variable'):
variable = ast.variable
else:
variable = None
# The AST contains no indication of whether or not "has" blocks
# were used. We'll use one any time it's possible (except for
# directly nesting them, or if they wouldn't contain any children),
Expand All @@ -214,7 +218,7 @@ def print_displayable(self, ast, has_block=False):
ast.children[0].children and (not ast.keyword or
ast.children[0].location[1] > ast.keyword[-1][1].linenumber)):
self.print_keywords_and_children(ast.keyword, [],
ast.location[1], needs_colon=True)
ast.location[1], needs_colon=True, variable=variable)
self.advance_to_line(ast.children[0].location[1])
with self.increase_indent():
self.indent()
Expand All @@ -223,7 +227,7 @@ def print_displayable(self, ast, has_block=False):
self.print_displayable(ast.children[0], True)
else:
self.print_keywords_and_children(ast.keyword, ast.children,
ast.location[1], has_block=has_block)
ast.location[1], has_block=has_block, variable=variable)

displayable_names = {
(behavior.OnEvent, None): ("on", 0),
Expand Down Expand Up @@ -261,14 +265,18 @@ def print_displayable(self, ast, has_block=False):
(layout.MultiBox, "hbox"): ("hbox", 'many')
}

def print_keywords_and_children(self, keywords, children, lineno, needs_colon=False, has_block=False, tag=None):
def print_keywords_and_children(self, keywords, children, lineno, needs_colon=False, has_block=False, tag=None, variable=None):
# This function prints the keyword arguments and child nodes
# Used in a displayable screen statement

# If lineno is None, we're already inside of a block.
# Otherwise, we're on the line that could start a block.
keywords_by_line = []
current_line = (lineno, [])
if variable is not None:
keywords_by_line.append(current_line)
current_line = (0, [])
current_line[1].extend(("as", variable))
if tag is not None:
keywords_by_line.append(current_line)
current_line = (0, [])
Expand Down

0 comments on commit d1f8934

Please sign in to comment.