Skip to content

feat(core): capture range for SequenceExpr#2994

Open
86xsk wants to merge 3 commits intoAutomattic:masterfrom
86xsk:SeqExpr-start-end
Open

feat(core): capture range for SequenceExpr#2994
86xsk wants to merge 3 commits intoAutomattic:masterfrom
86xsk:SeqExpr-start-end

Conversation

@86xsk
Copy link
Copy Markdown
Contributor

@86xsk 86xsk commented Mar 21, 2026

Description

Adds the start_capture and end_capture functions to SequenceExpr. These functions allow limiting the range of tokens captured by a SequenceExpr. They're inspired by and intended to function similarly to vim regex's \zs and \ze atoms.

One implementation detail I'm not too sure about is the RangeEnum type. It's functionality feels fairly distant from a grammar checker, and it feels like something that might better be delegated to a dependency. I'm not sure if there is a dependency we can/should use for this, or if there's a simpler way to implement it entirely.

All the added types/functions are currently pub(crate), with the intention of allowing otherwise breaking changes until this can become more refined through use/experience.

How Has This Been Tested?

  • cargo test

Checklist

  • I have performed a self-review of my own code
  • I have added tests to cover my changes

86xsk added 3 commits March 21, 2026 11:51
Allows the storing of a generic range in structs and similar.
Add tests for capture-range feature.
@hippietrail
Copy link
Copy Markdown
Collaborator

Interesting approach! I consider myself fairly decent at regexes but I've never known about \zs and \ze before you mentioned them the other day. I only ever did capturing with ( and ) (or \( and \) in vim) around subexpressions.

When I played with adding capturing I was going to "enable" capturing for any selected Pattern or Expr, or maybe just SequenceExpr and internally it would create an array so implicitly 0, 1, 2, etc. That would either get passed to match_to_lint as an extra arg that would just be None if there were no capture groups.

Or try to "walk the tree" of Patterns/Exprs - I got even less far with that idea than with the previous idea.

Since then I've also considered having a new kind of Pattern or Expr that would only capture its inner Pattern or Expr. I didn't even try to implement that idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants