Skip to content

Commit

Permalink
zfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnibs committed May 14, 2024
1 parent 9696c22 commit eb58396
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions zfmt/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ func (c *canon) expr(e ast.Expr, parent string) {
c.ret()
c.flush()
c.write(")")
case *ast.FString:
c.write("f\"")
for _, elem := range e.Elems {
switch elem := elem.(type) {
case *ast.FStringExpr:
c.write("{")
c.expr(elem.Expr, "")
c.write("}")
case *ast.FStringText:
c.write(elem.Text)
}
}
c.write("\"")
default:
c.write("(unknown expr %T)", e)
}
Expand Down
7 changes: 7 additions & 0 deletions zfmt/ztests/f-string.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
script: |
zc -C 'yield f"hello {f"world"}"'
outputs:
- name: stdout
data: |
yield f"hello {f"world"}"

0 comments on commit eb58396

Please sign in to comment.