From 7061051e19dc0ccbbdb694f030aedb05802287e4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 18 Aug 2026 01:57:02 +0900 Subject: refactor(preg): anchor A patterns at the call site The shim carried the PCRE A (anchored) modifier alongside every compiled pattern so preg_match2 could honour it by searching the sub-slice at the offset. Only two call sites ever passed such a pattern, and each can cut that slice itself, so the flag is gone from the cache, ResolvedPattern, PregPattern and the php_regex! macro, and a pattern still carrying A is now rejected rather than silently searched unanchored. StringInput::tokenize and PhpFileCleaner::match search from their cursor with a `^`-prefixed pattern instead. The rule is written down in docs/dev/regex-porting.md. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-class-map-generator/src/php_file_cleaner.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'crates/shirabe-class-map-generator') diff --git a/crates/shirabe-class-map-generator/src/php_file_cleaner.rs b/crates/shirabe-class-map-generator/src/php_file_cleaner.rs index 78cee261..cfd8f77f 100644 --- a/crates/shirabe-class-map-generator/src/php_file_cleaner.rs +++ b/crates/shirabe-class-map-generator/src/php_file_cleaner.rs @@ -1,7 +1,7 @@ //! ref: composer/vendor/composer/class-map-generator/src/PhpFileCleaner.php use indexmap::IndexMap; -use shirabe_php_shim::{PregMatches, preg_match2}; +use shirabe_php_shim::{PregMatches, preg_match, preg_match2}; use std::sync::Mutex; #[derive(Debug, Clone)] @@ -52,7 +52,7 @@ impl PhpFileCleaner { } let keys: String = type_config.keys().collect(); - let rest_pattern = format!("{{[^?\"'index`, so it must match starting exactly there. + // The `regex` crate anchors only at the head of the haystack, so the search runs over the part + // of the contents that begins at the index and the patterns carry a leading `^` instead of the + // `A` modifier. fn r#match(&self, regex: &str) -> Option> { - preg_match2(regex, &self.contents, self.index) + preg_match(regex, &self.contents[self.index..]) } } -- cgit v1.3.1-4-g156e