atom / node-oniguruma

Oniguruma Node Module
http://atom.github.io/node-oniguruma
MIT License
121 stars 46 forks source link

Knowing if a group in the pattern is matched and group name #100

Open lieene opened 5 years ago

lieene commented 5 years ago

Summary

CaptureIndex should contain info to tell if a subgroup is matched and group name on a named group.

Motivation

group name and subgroup match state are needed in some cases.

Describe alternatives you've considered

As unmatched group always has a 0 start position and 0 lengths. So when full-match is not started at 0, comparing subgroup start with full-match start can tell if there is a match. but that does not solve the case when full-match starts at 0. And 0 length(anchor alike) subgroup will have 0 lengths, so testing length against 0 can only solve none-0-length groups.

the group name can be collected by parsing pattern sources. it would be very helpful if group name and subgroup match state can be provided by CaptureIndex.

Additional context

rsese commented 5 years ago

Thanks for the suggestion - we're not currently prioritizing new functionality but just to clarify, would this idea be useful for Atom in particular or are you using this module outside of Atom?

Aerijo commented 5 years ago

@rsese It’s for TextMate grammars; more recent oniguruma versions have a conditional regex, but that feature doesn’t appear to have been implemented when this repo was made.

lieene commented 5 years ago

@rsese, for now, I'm working on a vscode extension on injection grammar. the extension uses oniguruma to sync with TM grammars. And I need group names and anchor matcher. And it can be adapted to Atom with not much effort. I have a working pattern search for group names. but 0 pos anchor is still a problem.