Skip to content

feature - implement std.regex RFC 059 (#294)#584

Merged
dannymeijer merged 14 commits into
mainfrom
feature/294-implement-rfc-059-std-regex
May 18, 2026
Merged

feature - implement std.regex RFC 059 (#294)#584
dannymeijer merged 14 commits into
mainfrom
feature/294-implement-rfc-059-std-regex

Conversation

@dannymeijer
Copy link
Copy Markdown
Contributor

@dannymeijer dannymeijer commented May 18, 2026

Summary

This PR implements RFC 059 by adding std.regex as the safe-default regular expression surface for compiled patterns, matches, captures, splitting, and replacement. The public API and behavior live in Incan stdlib source: regex.incn imports regex::Regex / RegexBuilder directly through Rust interop, materializes borrowed engine matches/captures in Incan code, and keeps Rust limited to the actual external regex crate binding.

The PR also adds RFC 100 for the next std.re slice so Pythonic/backtracking-capable regex can share infrastructure without weakening the std.regex safety contract.

Type of change

  • Bug fix
  • New feature
  • Refactor / maintenance
  • Documentation
  • CI / tooling
  • RFC (adds/updates docs/RFCs/*)

Area(s)

Select the primary areas touched (used for review routing; labels are managed separately):

  • Incan Language (syntax/semantics)
  • Compiler (frontend/backend/codegen)
  • Tooling (CLI/formatter/test runner)
  • Editor integration (LSP/VS Code extension)
  • Runtime / Core crates (stdlib/core/derive)
  • Documentation

Key details

  • User-facing behavior: from std.regex import Regex, RegexError now provides compiled regex values with constructor flags, is_match, find, find_iter, captures, captures_iter, full_match, split, splitn, literal/capture-aware replacements, callable replacements, match spans, indexed/named captures, and explicit None for unmatched optional groups.
  • Compiler interop: Direct Regex(...) construction lowers through the generic __incan_new hook rather than regex-specific hardcoding. rusttype aliases now resolve method calls through their underlying Rust canonical path, and metadata-backed Rust calls record borrowed scalar return coercions (&str/&[u8] -> owned Incan values) generically.
  • Stdlib dogfooding: std.regex now dogfoods Incan source for compile flags, match/capture wrapper types, iterators, full-match logic, split/splitn, replacement interpolation, literal replacement, callable replacement, and borrowed engine materialization. The previous incan_stdlib::regex Rust snapshot module has been removed.
  • Tooling hygiene: CLI structured logs now write to stderr so rust-inspect warnings cannot contaminate generated program stdout.

Testing / verification

  • make test / cargo test
  • make examples (if relevant)
  • incan fmt --check . (if relevant)
  • Manual verification described below

Manual verification notes:

  • make pre-commit-full-gate passed after merging origin/main: formatting, rustdoc gate, 2349 nextest tests, clippy, and cargo-deny all passed.
  • make smoke-test-fast passed: release build, rust-inspect focused tests, assertion canary, web/nested project builds, examples runner, and benchmark build smoke all passed.
  • cargo test -p incan std_regex passed.
  • incan run tests/fixtures/valid/std_regex_surface.incn passed.
  • Added end-to-end regex fixture coverage for matching, captures, iterators, split/splitn, replacement strings, literal replacements, callable replacement, bounded replacement, and unsupported safe-engine pattern diagnostics.
  • Added compiler regression coverage for rusttype aliases resolving underlying Rust methods and borrowed Rust method returns being owned as Incan str.
  • Added a layering guard proving std.regex uses direct rust::regex interop and preventing a Rust runtime-helper module from returning.

Docs impact

  • No docs changes needed
  • Docs updated
  • Docs follow Divio intent (tutorial/how-to/reference/explanation) where applicable

If docs updated:

  • Link(s): workspaces/docs-site/docs/language/reference/stdlib/regex.md, workspaces/docs-site/docs/release_notes/0_3.md, workspaces/docs-site/docs/RFCs/closed/implemented/059_std_regex.md, workspaces/docs-site/docs/RFCs/100_std_re_pythonic_regex.md

Checklist

  • I kept public docs user-focused and moved internals to contributing docs when appropriate
  • I avoided duplicating canonical install/run instructions in multiple places
  • I added/updated tests where it materially reduces regressions

Closes #294

@incan-triage-bot incan-triage-bot Bot added documentation Improvements or additions to documentation incan compiler Suggestions, features, or bugs related to the Compiler (frontend/backend/codegen) incan language semantics Suggestions, features, or bugs related to the Incan Language itself (syntax and semantics) runtime / core crates Suggestions, features, or bugs related to the `incan-core`, `incan-stdlib`, 'incan-derive` crates labels May 18, 2026
@dannymeijer dannymeijer self-assigned this May 18, 2026
@dannymeijer dannymeijer added this to the 0.3 Release milestone May 18, 2026
@incan-triage-bot incan-triage-bot Bot added the tooling Suggestions, features, or bugs related to the Tooling (CLI/formatter/test runner) label May 18, 2026
@dannymeijer dannymeijer marked this pull request as ready for review May 18, 2026 18:14
@dannymeijer dannymeijer merged commit 737259c into main May 18, 2026
33 checks passed
@dannymeijer dannymeijer deleted the feature/294-implement-rfc-059-std-regex branch May 18, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation incan compiler Suggestions, features, or bugs related to the Compiler (frontend/backend/codegen) incan language semantics Suggestions, features, or bugs related to the Incan Language itself (syntax and semantics) runtime / core crates Suggestions, features, or bugs related to the `incan-core`, `incan-stdlib`, 'incan-derive` crates tooling Suggestions, features, or bugs related to the Tooling (CLI/formatter/test runner)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC 059: std.regex - regular expressions, matches, captures, and replacement

1 participant