ocaml: phase 4 'assert EXPR' (+3 tests, 487 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s

Tokenizer already classified 'assert' as a keyword; this commit wires
it through:
  parser  : parse-prefix dispatches like 'not' — advance, recur, wrap
            as (:assert EXPR).
  eval    : evaluate operand; nil on truthy, host-error 'Assert_failure'
            on false. Caught cleanly by existing try/with.

  assert true; 42                          = 42
  let x = 5 in assert (x = 5); x + 1       = 6
  try (assert false; 0) with _ -> 99       = 99
This commit is contained in:
2026-05-09 00:32:35 +00:00
parent bd2cd8aad1
commit 14b52cfaa7
4 changed files with 26 additions and 0 deletions

View File

@@ -622,6 +622,8 @@
(begin (advance-tok!) (list :deref (parse-prefix))))
((at-kw? "not")
(begin (advance-tok!) (list :not (parse-prefix))))
((at-kw? "assert")
(begin (advance-tok!) (list :assert (parse-prefix))))
(else (parse-app)))))
(set!
parse-binop-rhs