-
Notifications
You must be signed in to change notification settings - Fork 702
templates: support string patterns in template language #6899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
8ffafc9
to
cc7eb2f
Compare
cc @yuja |
3ebcc42
to
4cae57d
Compare
just a reminder to adhere to commit guidelines here: https://github.com/jj-vcs/jj/blob/main/docs/contributing.md#commit-guidelines since. a |
3ea5b1a
to
7c68277
Compare
The full completion of this feature to be able to pull out the matching text in question probably involves introducing a new type that represents a match result (and match groups in regex), but doing so requires some rework and semantics design of the string pattern system itself. I think that would probably be |
For this use case, I think we can add
( Implementation-wise, we'll need https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace |
The issue I have is that it seems nontrivial to make a to_regex translator for globs, and that IME it is most ideal to have the ability to match groups with a regex. But that's probably going to require creating a language type to be able to extract groups and matches; a regex feature that only does full matches is quite a bit harder to use. So I'm partially trying to figure out how to incrementally deliver something useful without simply . inventing good regex support in my first code PR to the project heh. I think the path forward on that is calling the function introduced in this PR |
I think we'll need to switch to the globset crate at some point. The current |
52da308
to
a6dbfd7
Compare
I've rebased and rewritten this based on #6967. It should be ready to go from my end minus one code question I couldn't figure out and need help with :) |
a6dbfd7
to
c5b798d
Compare
7775609
to
d971626
Compare
Should be sufficiently rebased and feedback addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last minor thing from me.
d971626
to
49c2521
Compare
49c2521
to
3cf51ed
Compare
rebased, I'm going to fix up the feedback now edit: done! |
7a7bea5
to
1a1e6ed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG
1a1e6ed
to
c417a3c
Compare
c417a3c
to
583edf9
Compare
okay, i think that's good to go now |
This is a basic implementation of the same string pattern system as in the revset language. It's currently only used for `string.matches`, so you can now do: ``` "foo".matches(regex:'[a-f]o+') ``` In the future this could be added to more string functions (and e.g. the ability to parse things out of strings could be added). CC: jj-vcs#6893
This allows for any matcher type and allows extracting a capture group by number.
583edf9
to
a4f1704
Compare
Feedback should be fully addressed, PTAL. |
This is a basic implementation of the same string pattern system as in
the revset language. It's currently only used for
string.matches
, soyou can now do:
In the future this could be added to more string functions (and e.g.
the ability to parse things out of strings could be added).
CC: #6893
Checklist
If applicable:
CHANGELOG.md
README.md
,docs/
,demos/
)cli/src/config-schema.json
)