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
Custom regexp engine parses isolated options differently from Oniguruma #2354
Comments
Is it certain that Oniguruma didn't mean |
By observation, it's grouped like |
I rather meant it in the way whether we know it's not a bug. Because it really does seem weird to parse it like that. |
I've opened an issue to verify. It would be better for Sublime to replicate the bug than to differ from Oniguruma. However, if it is a bug, and it is fixed in Oniguruma, than that might be a good reason for Sublime to update its Oniguruma version. |
I always felt like So it is not a bug of Oniguruma. |
Since I just went through the referenced issue, the intended solution for Oniguruma is to interpret See also this test case: kkos/oniguruma@0b7a1b9#diff-f1faa5ae6ee6c139773f8424cadf6112R398 |
Expected behavior
When Sublime's custom regexp engine handles a regexp, it should behave identically to Oniguruma.
Actual behavior
Oniguruma has a quirk when parsing isolated options (e.g.
(?i)
) that Sublime does not replicate. When Oniguruma encounters isolated options, the remainder of the enclosing group (or of the expression, if there is no enclosing group) is implicitly grouped. For instance, the following expressions are equivalent:The documentation is less than clear, and this behavior is unintuitive, but it is consistent. I suppose that option groups are parsed with the same precedence as the
|
operator.Sublime's custom regexp engine, however, will interpret that expression differently, so that the following are equivalent:
As a result, the same construct may be interpreted differently depending on whether the expression triggers the Oniguruma engine or uses the native Sublime engine. This is confusing. In addition, this is an obstacle to third-party implementations and other tools.
Sample syntax
Sample input
Notes
The core HTML syntax inadvertently relies upon this bug. I will submit a PR to correct that.
A suggested best practice to avoid this issue is to avoid isolated options, except at the very beginning of an expression (and never in
variables
). Instead, use noncapturing groups with flags. For example, instead ofa(?i)b
, usea(?i:b)
.The text was updated successfully, but these errors were encountered: