Skip to content

translation/13: Blocks language — CSP-aligned procedural subset - #23

Merged
ChrisMayfield merged 0 commit into
mainfrom
translation/13-blocks
Jul 15, 2026
Merged

translation/13: Blocks language — CSP-aligned procedural subset#23
ChrisMayfield merged 0 commit into
mainfrom
translation/13-blocks

Conversation

@ChrisMayfield

Copy link
Copy Markdown
Member

Brings the visual Blocks (Blockly) language up to a coherent, well-tested feature set. Rather than chasing full parity with the typed/OOP languages, Blocks now implements a deliberate subset of the Universal AST — the same procedural, untyped, non-OOP surface CSP exposes — because its audience is middle-school programming and AP CSP. Everything outside the subset simply has no block, so a student can't build a program that fails to run or translate (mirroring how CSP marks OOP unsupported).

Blocks feed the shared interpreter/translator, so this touches only src/language/blocks/*, tests, docs, and a sample — no changes to interpreter.ts/translator.ts or any text parser.

What's added

  • Loops: repeat forever (→ While(true)), for each … in a list, and recognition of the counting-for pattern AP CSP's REPEAT n TIMES lowers to.
  • Lists (1-based): literal (stock lists_create_with), get/set item, append/insert/remove, length.
  • Strings (1-based): substring, character-at, upper/lower case, contains.
  • Math / random / conversion: abs, sqrt, min, max; random / random-int / random-range (RANDOM) / seed; to integer/decimal/text.
  • Print: a terminator dropdown (newline / space / none) so Print.appendLineFeed and separator round-trip faithfully — notably CSP DISPLAY's trailing space.
  • Toolbox & theme: reorganized into Common / Logic / Loops / Math / Text / Lists / Variables / Functions, each with a distinct legible hue on the dark slate theme.
  • Docs & sample: specs/blocks.md (subset + intentional omissions), examples/demo.blocks.json, and README updates.

Indexing is 1-based in the UI and folded to the 0-based AST in fromAst/toAst, exactly as csp/parser.tscsp/emitter.ts do.

Intentional omissions (converters reject them): classes/OOP, typed declarations, try/catch, switch, ternary, ++/--, +=, C-style for, do-while, null.

Testing (Option B)

Fidelity is verified by interpreting: a program must produce the same output run directly and after AST → blocks JSON → real headless Blockly load/save → AST. The whole demo.csp passes this, alongside focused per-feature programs and a load+interpret check of demo.blocks.json. blocks.test.ts: 39 tests.

  • npx tsc --noEmit, npm run test:run → 508 passed
  • npm run build succeeds; dev server serves the editor
  • npm run test-browser (Selenium csv/) → 90 passed, 0 failed (text languages unaffected)

Two deviations from the plan

  • Kept praxly_repeat_until (post-condition) rather than retiring it — it round-trips cleanly and the pre-condition controls_whileUntil (UNTIL) already covers the CSP/Scratch "repeat until".
  • Deferred indexOf — its returned-position base convention isn't fixed by the CSP reference; noted in specs/blocks.md.

🤖 Generated with Claude Code

@ChrisMayfield
ChrisMayfield force-pushed the translation/12-specs-and-docs branch from d01beef to fe27402 Compare July 15, 2026 14:31
@ChrisMayfield
ChrisMayfield changed the base branch from translation/12-specs-and-docs to main July 15, 2026 14:31
@ChrisMayfield
ChrisMayfield force-pushed the translation/13-blocks branch from 6c93b49 to 9f7da01 Compare July 15, 2026 14:31
@ChrisMayfield
ChrisMayfield merged commit 9f7da01 into main Jul 15, 2026
@ChrisMayfield
ChrisMayfield deleted the translation/13-blocks branch July 15, 2026 14:40
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