translation/13: Blocks language — CSP-aligned procedural subset - #23
Merged
Conversation
ChrisMayfield
force-pushed
the
translation/12-specs-and-docs
branch
from
July 15, 2026 14:31
d01beef to
fe27402
Compare
ChrisMayfield
changed the base branch from
translation/12-specs-and-docs
to
main
July 15, 2026 14:31
ChrisMayfield
force-pushed
the
translation/13-blocks
branch
from
July 15, 2026 14:31
6c93b49 to
9f7da01
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 tointerpreter.ts/translator.tsor any text parser.What's added
repeat forever(→While(true)),for each … ina list, and recognition of the counting-forpattern AP CSP'sREPEAT n TIMESlowers to.lists_create_with), get/set item, append/insert/remove, length.RANDOM) / seed; to integer/decimal/text.Print.appendLineFeedandseparatorround-trip faithfully — notably CSPDISPLAY's trailing space.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 ascsp/parser.ts↔csp/emitter.tsdo.Intentional omissions (converters reject them): classes/OOP, typed declarations, try/catch, switch, ternary,
++/--,+=, C-stylefor, 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.csppasses this, alongside focused per-feature programs and a load+interpret check ofdemo.blocks.json.blocks.test.ts: 39 tests.npx tsc --noEmit,npm run test:run→ 508 passednpm run buildsucceeds; dev server serves the editornpm run test-browser(Seleniumcsv/) → 90 passed, 0 failed (text languages unaffected)Two deviations from the plan
praxly_repeat_until(post-condition) rather than retiring it — it round-trips cleanly and the pre-conditioncontrols_whileUntil(UNTIL) already covers the CSP/Scratch "repeat until".indexOf— its returned-position base convention isn't fixed by the CSP reference; noted inspecs/blocks.md.🤖 Generated with Claude Code