Skip to content

fix(faces): fix four PseudoScript transformer bugs#118

Merged
hyperpolymath merged 2 commits into
mainfrom
fix/faces-pseudo-bugs
May 16, 2026
Merged

fix(faces): fix four PseudoScript transformer bugs#118
hyperpolymath merged 2 commits into
mainfrom
fix/faces-pseudo-bugs

Conversation

@hyperpolymath
Copy link
Copy Markdown
Owner

Summary

Fixes four text-transformer bugs in lib/pseudocode_face.ml:

  • output XIO.println(X) (wrong prefix)transform_io_output was emitting IO.println( instead of println(. Dropped the stray IO. prefix.
  • Keyword bleed into -- commentstransform_double_dash_comment converted -- SPDX-License-Identifier: AGPL-3.0-or-later to // SPDX-License-Identifier: AGPL-3.0-or-later, but the line then fell through to apply_boolean_ops, turning or|| to produce // SPDX-License-Identifier: AGPL-3.||-||-later. Fixed by adding an early return in transform_line for any line that starts with // after the -- conversion step.
  • Condition strings not loweredif/else if/while/for/match condition text was emitted verbatim without running through apply_comparisons, apply_boolean_ops, or apply_literal_subs. Added apply_cond_subs helper and applied it everywhere.
  • No semicolons between statementstransform_source was a trivial List.map that never inserted ;, so multi-statement function bodies were syntactically invalid. Replaced with a brace-depth-tracking pass that inserts ; after non-tail statements inside blocks (tail = the statement immediately before the matching }).

Files changed

File Change
lib/pseudocode_face.ml All four fixes
examples/faces/hello-pseudo.affine Now exercises set X to Y + output X in a two-statement body
tests/faces/hello-pseudo.expected.txt Refreshed snapshot
examples/faces/README.adoc Removed the now-fixed Pseudocode row from the gaps table

Test plan

  • opam exec -- dune build lib/ bin/ — confirms OCaml compiles
  • ./tools/run_face_transformer_tests.sh — snapshot regression: hello-pseudo.expected.txt should match preview-pseudocode output
  • affinescript preview-pseudocode examples/faces/hello-pseudo.affine — visually confirm output matches tests/faces/hello-pseudo.expected.txt
  • affinescript parse examples/faces/hello-pseudo.affine — confirm the lowered file parses without errors

Note: OCaml toolchain is not available in the authoring environment; changes were manually traced through the transformer logic. CI is the source of truth for build correctness.


Generated by Claude Code

hyperpolymath and others added 2 commits May 16, 2026 09:35
- `output X` / `print X` / `display X` now lowers to `println(X)`
  instead of `IO.println(X)` (dropped stray `IO.` prefix).
- `--` comment lines converted by `transform_double_dash_comment` no
  longer fall through to `apply_boolean_ops`, so `or` inside a comment
  is not clobbered with `||`.
- `if`/`else if`/`while`/`for`/`match` condition strings now go through
  `apply_comparisons`, `apply_boolean_ops`, and `apply_literal_subs`
  before being emitted, so pseudocode operators in conditions lower
  correctly.
- `transform_source` replaced with a brace-depth-tracking pass that
  inserts `;` after non-tail statements inside blocks, enabling
  multi-statement function bodies.

Updated `examples/faces/hello-pseudo.affine` to exercise `set X to Y`
and `output X` in a two-statement body.  Updated snapshot.
Removed the now-fixed Pseudocode row from `examples/faces/README.adoc`.
`transform_set` was calling `String.trim line` immediately, discarding
any leading whitespace. Statements like `    set x to expr` inside a
function body would lower to `let x = expr` at column 0, producing a
snapshot mismatch with the 4-space-indented expected output.

Fix: capture the leading indent before trimming and prepend it to the
generated `let`/`let mut` expression.

https://claude.ai/code/session_01Vrh2f1G8tf7ZbNcKh9r5U9
@hyperpolymath hyperpolymath marked this pull request as ready for review May 16, 2026 12:33
@hyperpolymath hyperpolymath merged commit 872d13c into main May 16, 2026
20 of 21 checks passed
@hyperpolymath hyperpolymath deleted the fix/faces-pseudo-bugs branch May 16, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants