Skip to content

Make parse_nat return Result<Nat, String> per spec (#174)#191

Merged
aallan merged 1 commit into
mainfrom
feature/parse-nat-result
Mar 4, 2026
Merged

Make parse_nat return Result<Nat, String> per spec (#174)#191
aallan merged 1 commit into
mainfrom
feature/parse-nat-result

Conversation

@aallan

@aallan aallan commented Mar 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Breaking change: parse_nat now returns Result<Nat, String> instead of bare Nat, matching the spec (Section 9). Returns Ok(n) on valid decimal input, Err("empty string") on empty/whitespace-only input, and Err("invalid digit") on non-numeric characters.
  • Digit validation: input bytes are checked against ASCII 48-57; leading and trailing spaces are tolerated.
  • Built-in ADT layouts: Result and Option constructor layouts are now registered in codegen, so match on Ok/Err/Some/None works without a user data declaration.
  • String pair extraction: _extract_constructor_fields now handles String (pair type) bindings inside ADT constructors, enabling Err(@String) match arms.

Test plan

  • vera run examples/string_ops.vera produces correct output
  • 6 new tests: Ok path (basic, zero, large, leading/trailing spaces), Err path (empty, invalid, mixed, string extraction)
  • Updated test_roundtrip and test_strip_then_parse to match on Result
  • All 1,353 tests pass, mypy clean, all 15 examples pass

Closes #174

Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.invalid>
@aallan aallan merged commit 830bef8 into main Mar 4, 2026
10 checks passed
@aallan aallan deleted the feature/parse-nat-result branch March 4, 2026 09:58
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.

parse_nat should return Result<Nat, String> per spec

1 participant