Skip to content

strict_commas(): reject the trailing commas OpenSCAD 2021.01 rejected - #12

Merged
revarbat merged 1 commit into
masterfrom
feat/strict-commas
Sep 25, 2026
Merged

revarbat merged 1 commit into
masterfrom
feat/strict-commas

Conversation

@revarbat

Copy link
Copy Markdown
Member

Ports openscad_cpp_parser #9: strict-commas mode.

with strict_commas():
    ast = getASTfromFile("model.scad")   # cube(1,) -> syntax error

The accept/reject table matches the one the C++ port measured against OpenSCAD 2021.01, case for case:

rejected when strict accepted either way
cube(1,), translate([0,0,0],), max(1, 2,), str("a","b",) [2, 4,]
let(x=1, y=2,), for (i=[0:2],), intersection_for(i=[0:1],) [for (i=[0:2]) i,], [each [1,2],]
module m(a, b,), function f(a, b,)
  • Two rules carry it: arguments and assignments_expr (let isn't a call in this grammar). They are rewritten for a second Lark parser that is built lazily on first strict use.
  • It's a contextvars context manager rather than a parameter on every entry point, the Python counterpart of the C++ thread-local StrictCommaScope. It nests and restores on exit, including when the body raises.
  • It's part of every cache key (memory, resolved and disk), so a file parsed leniently is never served to a strict parse. There's a test for exactly that case.
  • openscad-lalr --strict-commas.

🤖 Generated with Claude Code

Ports openscad_cpp_parser #9. Inside `with strict_commas():` a trailing
comma in a call's arguments or a let/for/intersection_for assignment
list is a syntax error, as in 2021.01; list literals, comprehensions and
parameter declarations keep theirs, since 2021.01 accepted them. The
two grammar rules carrying it (`arguments` and `assignments_expr` --
let is not a call) are rewritten for a second, lazily built parser.

A context variable, like the C++ parser's thread-local scope, so no
entry point grows a parameter: it nests, restores on exit even when the
body raises, and keys every cache -- memory, resolved and disk -- so a
strict parse is never served a lenient tree. CLI: --strict-commas.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@revarbat
revarbat merged commit ffcbafb into master Sep 25, 2026
3 checks passed
@revarbat
revarbat deleted the feat/strict-commas branch September 25, 2026 09:55
@revarbat revarbat mentioned this pull request Sep 25, 2026
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