Stop reserving builtin module names as lexer keywords (v3.5 final item)#76
Merged
Merged
Conversation
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
commented
Jul 17, 2026
particlesector
left a comment
Owner
Author
There was a problem hiding this comment.
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
…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
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.
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, orfor/letloop variable — e.g.cube = 5; sphere(cube);ormodule box(scale) { cylinder(h=scale, r=1); }now parse correctly.if/else/for/each/module/function/let/include/use/undef/true/false). Builtin construct names lex as plainIdent.kBuiltinNodeNameslookup 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 likescale=4that 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
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.for/letloop variables, and named call arguments.cube,scale, androtateas both variables/parameters and builtin calls in the same file — parses with zero errors.Generated by Claude Code