Skip to content

fix(pstack): write non-ASCII chart captions as strings TLC can parse - #871

Open
rudycelekli wants to merge 1 commit into
cursor:mainfrom
rudycelekli:fix/chart-unicode-20261024c
Open

rudycelekli wants to merge 1 commit into
cursor:mainfrom
rudycelekli:fix/chart-unicode-20261024c

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

statechart.mjs from-chart cannot check a chart whose state captions contain any non-ASCII character. chart-to-tla.mjs copies each caption into the generated spec as a TLA+ string, and SANY only accepts ASCII inside strings, so a caption like Don’t pay (curly apostrophe), Waiting…, Café, or one with an emoji makes TLC stop with "Parsing or semantic analysis failed" before it checks a single rule. The skill tells people to write captions in the reader's own words, and editors often turn a typed apostrophe or ... into these characters, so ordinary hand-drawn charts run into this.

The fix writes each non-ASCII character into the TLA+ string as a Mermaid-style #code; entity (for example "Don#8217;t pay"), so every string the spec contains is ASCII. The generated map file gets a CAPTIONS table from each encoded string back to the original caption, and state() looks values up there, so the charts, stories, and the from-chart comparison all keep showing the captions exactly as drawn. Captions that are already ASCII, transition labels (which only end up in comments and in the JavaScript map), and the rest of the output stay the same.

The new test/chart-to-tla-ascii.test.mjs adds two tests. The first draws a chart with …, ’, é, and an emoji, then checks that every string in the generated spec is printable ASCII and that the map reads each one back as its caption. It runs without TLC. The second runs from-chart on the same chart through TLC, expects the %% never rule to break, and expects the spec to draw the chart back unchanged. Both fail on main (a non-ASCII string, then the SANY parse failure) and pass with this change. The from-chart, chart-to-tla, and guard tests in statechart.test.mjs still pass with TLC available, and the harness tree is regenerated.


Note

Low Risk
Scoped to statechart code generation and map display; behavior for ASCII-only charts is unchanged aside from the optional CAPTIONS lookup.

Overview
Fixes TLC/SANY parse failures when Mermaid state captions include typographic or Unicode text (curly quotes, ellipsis, accents, emoji).

chart-to-tla.mjs now runs state names through an ascii() encoder before they become TLA+ string literals, emitting Mermaid-style #code; entities so every string in the spec stays printable ASCII. The generated *.map.mjs adds a CAPTIONS table (encoded → original) and state() decodes through it, so from-chart comparisons and displayed labels still match the chart verbatim.

Adds chart-to-tla-ascii.test.mjs: one test asserts ASCII-only .tla strings and map round-trip without TLC; another (when TLC is present) runs from-chart on the same chart and expects the never-rule break plus an unchanged redraw.

Reviewed by Cursor Bugbot for commit 2babb8e. Bugbot is set up for automated code reviews on this repo. Configure here.

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.

1 participant