Skip to content

Conversation

@deathaxe
Copy link
Collaborator

This commit prepares named backreferences for correctly handling interpolation.

Primary use case are raw f-strings, but it applies to all other sorts of template languages as well.

Notes:

  1. to align with Regular Expressions package, keyword.other.backref-and-recursion covers all, leading ? and group names.
  2. adds ?&backref to support patterns from "regexp" package.

This commit prepares named backreferences for correctly handling interpolation.
@michaelblyons
Copy link
Collaborator

Looks good.

Would interpolations still work if you added an invalid.illegal for [^:[alnum]:_] in backref-name? (Or are there other concerns for annoyance while typing? I would expect any nonconforming characters to be inside the interpolations and not really a problem if interpolations are working.)

@deathaxe
Copy link
Collaborator Author

deathaxe commented Oct 21, 2025

With regards to related Discord discussion, it may require additional messures to ensure place holders like %s to not be highlighted illegal. Those are currently not included into with_prototype in Python.

A point of concern is [^:[alnum]:_] pattern creating individual tokens for each character and [^:[alnum]:_]+ potentially preventing interpolation from being highlighted, when preceeded by an non-word character. But maybe individual tokens being created may be unlikely and expected ammount small enough to be acceptable.

It doesn't currently produce good results, as normal patterns don't handle placeholders as those cause ambiguities with {1} quantifiers. Adding illegals results in ...

grafik

With current PR, they at least don't look too broken.

grafik

@deathaxe deathaxe merged commit 8b02fe0 into sublimehq:master Oct 22, 2025
2 checks passed
@deathaxe deathaxe deleted the pr/python/improve-regexp-interpolation branch October 22, 2025 17:06
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.

3 participants