Skip to content

fix(faces): stop appending ; to -- comment lines in LucidScript#119

Merged
hyperpolymath merged 3 commits into
mainfrom
fix/faces-lucid-comment-semis
May 16, 2026
Merged

fix(faces): stop appending ; to -- comment lines in LucidScript#119
hyperpolymath merged 3 commits into
mainfrom
fix/faces-lucid-comment-semis

Conversation

@hyperpolymath
Copy link
Copy Markdown
Owner

Summary

Fixes stray ; being appended to -- comment lines in lib/lucid_face.ml.

Root cause: the previous pipeline applied convert_dashdash_comment to each raw line (turning -- text// text), then passed the result to strip_dashdash_comment. Because strip_dashdash_comment scans for -- and finds none in // text, it returned the full // text string as the code part with no comment. That code fell through to the expression handler, which appended ;, producing // text;.

Fix:

  • Remove convert_dashdash_comment entirely (now unused).
  • Apply strip_dashdash_comment directly to the raw (pre-conversion) line in transform_source. A -- comment line now yields an empty code part and a populated comment_opt, so it is emitted as // text\n with no trailing ;.
  • Update is_blank_line to treat canonical // lines as blank so the next-meaningful-indent scan correctly skips them.
  • Add a dispatch branch in transform_source that passes canonical ////* lines through unchanged before they can reach the equation handler.

Files changed

File Change
lib/lucid_face.ml Remove convert_dashdash_comment; fix strip_dashdash_comment application; add // passthrough; fix is_blank_line
tests/faces/hello-lucid.expected.txt Refreshed snapshot — no stray ; on comment lines

Test plan

  • opam exec -- dune build lib/ bin/ — confirms OCaml compiles
  • ./tools/run_face_transformer_tests.sh — snapshot regression: hello-lucid.expected.txt should match preview-lucid output
  • affinescript preview-lucid examples/faces/hello-lucid.affine — visually confirm no ; on comment lines
  • affinescript parse examples/faces/hello-lucid.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 3 commits May 16, 2026 09:38
The previous pipeline first called `convert_dashdash_comment` (turning
`-- text` into `// text`), then passed the result to
`strip_dashdash_comment`.  Because `strip_dashdash_comment` scans for
`--` and found none in the converted line, it returned the entire `//
text` string as the "code part".  That code part fell through to the
expression handler, which appended `;`, producing `// text;`.

Fix: apply `strip_dashdash_comment` directly to the raw (pre-conversion)
line.  A `-- comment` line now yields an empty code part and a populated
comment_opt, so it is emitted as `// text\n` with no trailing `;`.
As a side effect, `convert_dashdash_comment` becomes unused and is
deleted.

`is_blank_line` is updated to treat canonical `//` lines as blank (so
the next-meaningful-indent scan skips them), and a new dispatch branch
in `transform_source` passes canonical `//`/`/*` lines through unchanged
before they can reach the equation handler.

Updated snapshot `tests/faces/hello-lucid.expected.txt`.
When a `--`-comment line has no text (e.g. just `--`), `strip_dashdash_comment`
returns `Some ""`. The previous code would emit `"// " ^ "" ^ "\n"` = `"// \n"`,
leaving a trailing space. The expected snapshot (and readable output) needs
`"//\n"` with no trailing space.

Fix: check the trimmed comment text and emit bare `"//"` when it is empty.

https://claude.ai/code/session_01Vrh2f1G8tf7ZbNcKh9r5U9
When source ends with \n, String.split_on_char '\n' produces a trailing
empty string. The loop processes it as an empty line, emitting an extra
\n via Buffer.add_char — making output end with \n\n instead of \n.
Strip the redundant newline at the end of transform_source so the output
matches the snapshot (which was already updated to have exactly one
trailing newline).

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 d18b25f into main May 16, 2026
20 of 21 checks passed
@hyperpolymath hyperpolymath deleted the fix/faces-lucid-comment-semis 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