[Constraint 2.0 / C] Parametric expression grammar (+, -, *, /, min, max) #11
Labels
No labels
blocked:needs-attention
blocked:needs-decision
blocked:needs-decompose
blocked:needs-design
blocked:needs-triage
blocked:unclassified
bug
documentation
enhancement
gsd-spec
in-progress
needs-decompose
priority:high
priority:low
priority:medium
quickfix
test
triage-approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Mark/kimi_agent_openscad_parametric_gui#11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Parametric expression grammar —
plate_length = wall_thickness * 2 + clearanceWhy: today every numeric value in an annotation is parsed by
parseFloat()inconstraints.ts:159. So// @sf:place gap=${wall_thickness}+0.5is silently truncated. Engineering constraints need real expressions: variables, arithmetic, min/max.Spec: introduce a tiny expression layer. Grammar (EBNF):
Number=-?\d+(\.\d+)?(same as today)ParamName=[a-zA-Z_][\w]*— resolves through project-wide shared-param table (sub-issue #D) then file-localparamannotations.Implementation:
src/lib/scad/expr.ts(~120 LOC): tokenizer + recursive-descent parser + evaluator with aScope { params: Record<string, number> }interface.constraints.ts:159num()replaced withexprEval()on the parsed AST (cached on the constraint object).fmt()already rounds to 3 decimals — extend to format expressions as flat numeric results inserializeConstraint()(the constraint surface stays numeric; only the solver evaluates expressions).Design choice: AST or string round-trip?
.scadexport concrete (noplate_length + 0.5in real OpenSCAD, since OpenSCAD's parameter substitution doesn't see those). The expressions live in annotations only; the exported.scadalways contains solved numbers. This matches the current behavior ofconstraintCodegen.ts:23("Linked values across modules reference the variables declared here") — just with a smarter source.Files to change:
src/lib/scad/expr.ts— newsrc/lib/scad/constraints.ts— wirenum()toexprEval()src/lib/scad/solver.ts— passScopethrough during resolvesrc/lib/scad/constraintCodegen.ts— already solved-numbers-on-export, no change neededsrc/components/workbench/ConstraintPanel.tsx— when editing gap/distance/spacing, show formula input + live previewAcceptance:
// @sf:place gap=0.5+wall_thickness*2solves towall_thickness * 2.5wall_thicknesschanges; 3D viewport updatesOut of scope: unit conversions, conditional expressions, array formulas.
Labels: enhancement
Part of epic #8.