feature - implement std.regex RFC 059 (#294)#584
Merged
Conversation
…-rfc-059-std-regex # Conflicts: # workspaces/docs-site/docs/release_notes/0_3.md
…-rfc-059-std-regex
…-rfc-059-std-regex # Conflicts: # src/frontend/typechecker/tests.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements RFC 059 by adding
std.regexas 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.incnimportsregex::Regex/RegexBuilderdirectly 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.reslice so Pythonic/backtracking-capable regex can share infrastructure without weakening thestd.regexsafety contract.Type of change
docs/RFCs/*)Area(s)
Select the primary areas touched (used for review routing; labels are managed separately):
Key details
from std.regex import Regex, RegexErrornow 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 explicitNonefor unmatched optional groups.Regex(...)construction lowers through the generic__incan_newhook rather than regex-specific hardcoding.rusttypealiases 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.std.regexnow 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 previousincan_stdlib::regexRust snapshot module has been removed.Testing / verification
make test/cargo testmake examples(if relevant)incan fmt --check .(if relevant)Manual verification notes:
make pre-commit-full-gatepassed after mergingorigin/main: formatting, rustdoc gate, 2349 nextest tests, clippy, and cargo-deny all passed.make smoke-test-fastpassed: 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_regexpassed.incan run tests/fixtures/valid/std_regex_surface.incnpassed.rusttypealiases resolving underlying Rust methods and borrowed Rust method returns being owned as Incanstr.std.regexuses directrust::regexinterop and preventing a Rust runtime-helper module from returning.Docs impact
If docs updated:
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.mdChecklist
Closes #294