Skip to content

Stop reserving builtin module names as lexer keywords (v3.5 final item)#76

Merged
particlesector merged 2 commits into
mainfrom
claude/openscad-v3.5-final-item-h3ho6s
Jul 17, 2026
Merged

Stop reserving builtin module names as lexer keywords (v3.5 final item)#76
particlesector merged 2 commits into
mainfrom
claude/openscad-v3.5-final-item-h3ho6s

Conversation

@particlesector

Copy link
Copy Markdown
Owner

Summary

  • cube/sphere/translate/scale/etc. are no longer reserved lexer keywords. Matching real OpenSCAD (where builtin modules and variables live in separate namespaces), a script can now use one of those names as an ordinary variable, module/function parameter, or for/let loop variable — e.g. cube = 5; sphere(cube); or module box(scale) { cylinder(h=scale, r=1); } now parse correctly.
  • The Lexer's keyword table is trimmed to genuine OpenSCAD grammar keywords only (if/else/for/each/module/function/let/include/use/undef/true/false). Builtin construct names lex as plain Ident.
  • The Parser gained a kBuiltinNodeNames lookup used only at statement-start call position (name(...)) to route to the existing primitive/boolean/transform/extrusion parsing helpers by name instead of by dedicated token kind. Everywhere else (assignments, parameter lists, loop variables, named call arguments) these names now behave as ordinary identifiers, which incidentally also fixes named module/function-call arguments like scale=4 that previously failed to parse.

This was the one item explicitly deferred from the v3.5 completeness audit (docs/roadmap.md) and closes out feature completeness against OpenSCAD's builtin/keyword surface.

Test plan

  • Full test suite (chiselcad_tests, Lexer/Parser/Interpreter/CsgEvaluator/loader suites) built standalone with g++ + system Catch2 (no Vulkan/Manifold toolchain in this sandbox) — 2915 assertions / 539 cases pass.
  • Added 6 new parser test cases covering builtin names used as top-level variables, transform arguments, module parameters, for/let loop variables, and named call arguments.
  • Updated existing lexer tests that asserted the now-removed keyword token kinds.
  • Manual end-to-end parse check of a script mixing cube, scale, and rotate as both variables/parameters and builtin calls in the same file — parses with zero errors.

Generated by Claude Code

cube/sphere/translate/scale/etc. no longer occupy their own TokenKind —
the Lexer's keyword table now holds only genuine OpenSCAD grammar
keywords (if/else/for/each/module/function/let/include/use/undef/true/
false). The Parser recognises builtin constructs by name only at
statement-start call position (new kBuiltinNodeNames table), so a script
is free to use e.g. `cube`, `scale`, or `rotate` as an ordinary variable,
module/function parameter, or for/let-loop variable — matching real
OpenSCAD, where builtins and variables live in separate namespaces.

This was the one item explicitly deferred from the v3.5 completeness
pass and closes out feature completeness with OpenSCAD's builtin/
keyword surface.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UAoehmbCynYJC5K28qBVxs

@particlesector particlesector left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed. This correctly closes the last v3.5 gap: builtin names (cube, scale, etc.) are dropped from the lexer's keyword table and instead resolved by name only at statement-start call position via kBuiltinNodeNames in the Parser. Verified the logic handles modifiers (#cube();), named module-call args (scale=4), and that no other code depends on the Lexer tagging builtins specially — the TokenKind values are now purely internal Parser tags. Test coverage (new parser cases + updated lexer expectations) looks appropriately targeted, and CI is green. One minor robustness nit left inline on the fallthrough behavior if the builtin map/switch ever diverge; not blocking.


Generated by Claude Code

Comment thread src/lang/Parser.cpp Outdated
…h divergence

Per PR review: the previous default: break; in parseNodeInner's builtin
dispatch switch would silently fall through to parseModuleCall() if a
name were ever added to kBuiltinNodeNames without a matching case,
misparsing a builtin call as a user-defined module call with no
diagnostic. Replace with an assert so any future divergence fails fast
during development instead of misbehaving silently.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UAoehmbCynYJC5K28qBVxs
@particlesector
particlesector merged commit 4ba7132 into main Jul 17, 2026
4 checks passed
@particlesector
particlesector deleted the claude/openscad-v3.5-final-item-h3ho6s branch July 17, 2026 06:52
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