Skip to content

Commit

Permalink
Breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dipankar committed Sep 21, 2024
1 parent aaccd90 commit b192960
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions stxscript/clarity_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def generate_Program(self, node: Program):
return '\n'.join(self.generate(stmt) for stmt in node.statements)

def generate_FunctionDeclaration(self, node: FunctionDeclaration):
is_public = any(d.name == '@public' for d in node.decorators)
is_public = any(d == '@public' for d in node.decorators)
func_type = 'public' if is_public else 'private'
params = ' '.join(self.generate(param) for param in node.parameters)
body = self.generate(node.body)
Expand All @@ -83,7 +83,7 @@ def generate_AssetDeclaration(self, node: AssetDeclaration):
return f'(define-non-fungible-token {node.name} {fields})'

def generate_TraitDeclaration(self, node: TraitDeclaration):
functions = '\n'.join(f'({self.generate(func)})' for func in node.functions)
functions = '\n'.join(self.generate(func) for func in node.functions)
return f'(define-trait {node.name}\n{self.indent()}({functions}))'

def generate_Parameter(self, node: Parameter):
Expand All @@ -98,8 +98,11 @@ def generate_Block(self, node: Block):
def generate_IfStatement(self, node: IfStatement):
condition = self.generate(node.condition)
true_block = self.generate(node.true_block)
else_block = self.generate(node.else_block) if node.else_block else ''
return f'(if {condition}\n{self.indent()}{true_block}\n{self.indent()}{else_block})'
else_block = self.generate(node.else_block) if node.else_block else None
if else_block:
return f'(if {condition}\n{self.indent()}{true_block}\n{self.indent()}{else_block})'
else:
return f'(if {condition}\n{self.indent()}{true_block}\n{self.indent()})'

def generate_TryCatchStatement(self, node: TryCatchStatement):
try_block = self.generate(node.try_block)
Expand Down Expand Up @@ -209,7 +212,7 @@ def generate_FoldExpression(self, node: FoldExpression):
list_expr = self.generate(node.list)
initial = self.generate(node.initial)
function = self.generate(node.function)
return f'(fold {list_expr} {initial} {function})'
return f'(fold {function} {initial} {list_expr})'

def generate_ListComprehension(self, node: ListComprehension):
expression = self.generate(node.expression)
Expand Down
3 changes: 2 additions & 1 deletion stxscript/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def call_expression(self, tree):
print(f"Debug: tree.children = {tree.children}")

if not tree.children:
raise ValueError(f"call_expression requires at least a callee. Tree: {tree}")
print(f"call_expression requires at least a callee. Tree: {tree}")
return CallExpression(callee=None, arguments=[])

callee = tree.children[0]
args = tree.children[1] if len(tree.children) > 1 else []
Expand Down

0 comments on commit b192960

Please sign in to comment.