Skip to content
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

sublime-syntax single quote escapes followed by quantifier chars inside sets #94

Open
keith-hall opened this issue Mar 8, 2017 · 6 comments
Assignees
Labels

Comments

@keith-hall
Copy link
Member

In a sublime-syntax file, if the regex is single quoted, and contains a set, and that set contains an escaped single quote, if a character that is normally a valid quantifier immediately follows it, that character is scoped as a quantifier when it shouldn't be - because it is inside a set.

Example: add a star after the ' here: https://github.com/sublimehq/Packages/blob/7ef80d531b752baee46f792b6bc6b26206e56012/Rust/Rust.sublime-syntax#L383

to get:

- match: '(?=>|[^ \t\n\$=<_+''*(),&:\[\][:alnum:]])'

and you will see the * is scoped as keyword.operator.quantifier.regexp when it shouldn't be.

@FichteFoll
Copy link
Member

I can also imagine problematic situations with match: '[x-'']+'.

@FichteFoll FichteFoll modified the milestone: 3.0.0 Apr 24, 2017
@FichteFoll
Copy link
Member

This issue is quite annoying. Without having to rewrite the entire syntax for a "single-quotes escape mode", I basically get to decide between not matching situations like `match: '\s*''?', where a quantifier would be valid but not recognized, or the current situation where a quantifier is seen within a set when it shouldn't. Since the latter is less obtrusive than the former, I'd prefer to keep it the way it is, if we had to choose between either.

Cases where the escape occurs in a set range not considered.

I don't think this issue occurs frequent enough to warrant rebuilding the entire Oniguruma syntax with single quotes in mind, so I'll pull this from the 3.0.0 milestone for later consideration. It's not a huge deal either way.

@FichteFoll FichteFoll removed this from the 3.0.0 milestone Sep 1, 2017
FichteFoll added a commit that referenced this issue Sep 1, 2017
@Thom1729
Copy link
Member

I took a stab at rebuilding the entire Oniguruma syntax with single quotes in mind:

%YAML 1.2
%TAG ! tag:yaml-macros:YAMLMacros.lib.extend:
---
!extend
_base: Oniguruma RegExp.sublime-syntax
name: Oniguruma Regular Expression (single-quoted)
hidden: true

variables: !merge
  char_escape: \\.|''

Is this a solution worth pursuing?

@FichteFoll
Copy link
Member

Thanks for the heads up.

I kind of dislike having to require third-party tools for building resource files for ST, since it introduces yet another dependency, and was very glad when the need for YAML-tmLanguage conversions was nullified by sublime-syntax being YAML already.
However, I do see merit in the brevity of the YAML Macros approach and I wouldn't be able to get around having to rebuild the syntax anyway in order to fix this issue.

I'll think about this more and experiment with YAML Macros a bit. You won't have to submit this as a pull request.

@FichteFoll FichteFoll added this to the 3.2.2 milestone Nov 20, 2018
@FichteFoll FichteFoll removed this from the 3.2.2 milestone Jan 15, 2019
@FichteFoll
Copy link
Member

Going to wait on the YAML Macros update that includes changes from the outfactored dependency.

@FichteFoll
Copy link
Member

Just as a heads-up, with the ability to extend syntaxes, fixing this has become a lot easier. Just waiting for someone with enough motivation to get picked up. 😉

@FichteFoll FichteFoll self-assigned this Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants