Skip to content

feat(lang): add assert statements to Forma-Pipe - #133

Draft
farisbasha wants to merge 1 commit into
wrong-nebula:mainfrom
farisbasha:feat-assert-statement
Draft

farisbasha wants to merge 1 commit into
wrong-nebula:mainfrom
farisbasha:feat-assert-statement

Conversation

@farisbasha

Copy link
Copy Markdown
Contributor

Implements the first step proposed in #132 (craftsmanship blueprint item 2). Opened as a draft so the shape can be agreed there first; happy to change the syntax or error format.

What it adds

a = box(1, 1, 1)
b = box(1, 1, 1, at=(2, 0, 0))
assert clearance(a, b) >= 0.5
assert section(a, 0) > 0.5, "a is cut at z=0"
  • assert <expr> <op> <expr> [, "message"], op in < <= > >= == !=. Both sides must be numbers, so it works with clearance(), section(), scalars and math.
  • A failing assert stops the script with both values, and the eval transaction rolls back like any other eval error:
    line 3: assert failed: gap too small: clearance(a, b) >= 1.5 (left 1, right 1.5)
  • Comparison tokens are only parsed inside assert; x = 1 < 2 is still an error. assert becomes a built-in name for def, but a part called assert (assert = box(...)) still works.
  • forma spec gets one line, and grammar/forma_pipe.gbnf gets assert-stmt and cmp-op rules. The compact dialect is unchanged.

Tests

  • New crates/forma-lang/tests/assert_statement.rs (7 tests): passing asserts, each operator failing, the error text with message, rollback of the script's parts after a failure, malformed asserts, comparisons outside assert, and spec/grammar entries.
  • CI command cargo test --locked --release -p forma-core -p forma-lang -p forma-cli -p forma-mcp -p forma-server -- --skip test_10000_fuzzed_modeling_operations_zero_crashes_zero_nans: 164 passed, 0 failed (Linux). I did not run the npm/WASM smoke tests.

This PR was prepared with AI assistance (Claude).

`assert lhs <op> rhs [, "message"]` compares two number expressions
(< <= > >= == !=). A false assert fails the script with both values,
so the eval transaction rolls back. Comparison operators are only
parsed inside assert. Adds a spec line and a GBNF rule.

Refs wrong-nebula#132
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