Skip to content

Commit

Permalink
fix a few more issues with pp
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmuth committed May 7, 2024
1 parent 7b121c5 commit 9b28d27
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions FrontEnd/Lib/test.cw
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ Both must have derivable types as we use `auto`"""
(mlet $a_val auto $a_expr)
(AssertEq# (len $e_val) (len $a_val))
(for $i 0 (len $a_val) 1 :
(AssertApproxEq# (^ (pinc (front $e_val) $i)) (^ (pinc (front $a_val) $i))))
$epsilon)
(AssertApproxEq# (^ (pinc (front $e_val) $i)) (^ (pinc (front $a_val) $i)) $epsilon)))

@doc ""
@pub (macro AssertTrue# STMT_LIST [(mparam $e_expr EXPR)] [] :
Expand Down
13 changes: 9 additions & 4 deletions FrontEnd/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,6 @@ def EmitTokensCodeBlock(ts: TS, stmts):
ts.EmitColonEnd(beg_colon)




def TokensExprIndex(ts: TS, node: cwast.ExprIndex):
EmitTokens(ts, node.container)
beg_paren = ts.EmitBegParen("[")
Expand Down Expand Up @@ -714,12 +712,16 @@ def EmitTokensStatement(ts: TS, n):
EmitTokensCodeBlock(ts, n.body_for)
elif isinstance(n, cwast.MacroInvoke):
_TokensStmtMacroInvoke(ts, n)
elif isinstance(n, cwast.MacroId):
ts.EmitAttr(n.name)
ts.EmitNewline()
else:
assert False, f"unexpected stmt node {n}"
#
if not ts.LastTokenIsCodeBlock():
ts.EmitNewline()


def EmitTokensExprMacroBlock(ts: TS, stmts):
beg_colon = ts.EmitColonBeg()
for child in stmts:
Expand All @@ -730,6 +732,7 @@ def EmitTokensExprMacroBlock(ts: TS, stmts):
assert False
ts.EmitColonEnd(beg_colon)


def _EmitTokensToplevel(ts: TS, node):
# extra newline before every toplevel stanza
ts.EmitNewline()
Expand All @@ -746,10 +749,12 @@ def _EmitTokensToplevel(ts: TS, node):
ts.EmitStmtEnd(beg)
elif isinstance(node, cwast.Import):
beg = ts.EmitStmtBeg("import")
ts.EmitName(node.name)
if node.alias:
ts.EmitBinOp("as")
ts.EmitAttr(node.alias)
ts.EmitBinOp("=")
ts.EmitName(node.name)
if node.args_mod:
TokensParenList(ts, node.args_mod)
ts.EmitStmtEnd(beg)
elif isinstance(node, cwast.DefType):
beg = ts.EmitStmtBeg("type")
Expand Down

0 comments on commit 9b28d27

Please sign in to comment.