Repository navigation
grep: align PCRE syntax behavior and digit options with GNU grep - #255
yunusarda-sudo wants to merge 2 commits into
Conversation
Under -P, configure Oniguruma syntax behavior and options to match GNU grep: - Retain ONIG_SYN_ISOLATED_OPTION_CONTINUE_BRANCH so inline (?i) carries over across branches. - Enable ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND so look-behind alternatives of differing lengths (e.g. (?<=Host: |host=)) are accepted. - Clear ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP so numbered backreferences (\1) work alongside named capture groups. - Set ONIG_OPTION_DIGIT_IS_ASCII so \d matches ASCII [0-9] only. Fixes uutils#182
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #255 +/- ##
==========================================
+ Coverage 97.22% 97.23% +0.01%
==========================================
Files 6 6
Lines 2270 2279 +9
Branches 245 246 +1
==========================================
+ Hits 2207 2216 +9
Misses 63 63
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
| let raw_syntax = &raw mut syntax as *mut onig_sys::OnigSyntaxType; | ||
| let mut behavior = unsafe { onig_sys::onig_get_syntax_behavior(raw_syntax) }; | ||
| behavior |= onig_sys::ONIG_SYN_ISOLATED_OPTION_CONTINUE_BRANCH; | ||
| behavior |= onig_sys::ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND; | ||
| behavior &= !onig_sys::ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP; | ||
| unsafe { onig_sys::onig_set_syntax_behavior(raw_syntax, behavior) }; |
There was a problem hiding this comment.
Are these not exposed via onig?
There was a problem hiding this comment.
Good question! I originally checked Syntax::enable_behavior() and Syntax::disable_behavior(), but hit an issue with onig's wrapper:
onig::SyntaxBehavioronly defines flags up to0x4000(soONIG_SYN_ISOLATED_OPTION_CONTINUE_BRANCHis omitted in the bitflags definition).- More crucially,
Syntax::enable_behavior()andSyntax::disable_behavior()internally callself.behavior(), which usesSyntaxBehavior::from_bits_truncate(). Callingenable_behavior()onSyntax::perl()silently drops any bits not explicitly bound inonig::SyntaxBehavior—truncating the Perl behavior mask from0x88a0040bdown to0xa0004band breaking(?i). - I've updated the write-back in commit 0e4e008 to use
syntax.set_behavior(SyntaxBehavior::from_bits_retain(behavior))instead of the FFI setter, minimizing the unsafe surface while safely preserving the full bitmask.
Under
-P, configure Oniguruma syntax behavior and options to align with GNU grep:ONIG_SYN_ISOLATED_OPTION_CONTINUE_BRANCHso inline(?i)carries over across branches (previously stripped byenable_behavior()).ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHINDso look-behind alternatives of differing lengths (e.g.(?<=Host: |host=)) are accepted.ONIG_SYN_CAPTURE_ONLY_NAMED_GROUPso numbered backreferences (\1) work alongside named capture groups (e.g.(?<w>\w+) \1).ONIG_OPTION_DIGIT_IS_ASCIIso\dmatches ASCII[0-9]only, rather than non-ASCII Unicode digits.Fixes #182