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
Decouple option values of regex literal modifiers #13252
Comments
@bcardiff mentioned in #13152 (comment)
|
I think it should also be possible for the compile to compose an option value from named members. ::Regex.new("cat", ::Regex::Options::IGNORE_CASE | ::Regex::Options::MULTILINE) That means the compiler expects the constants However, there is some value for the regex implementation to know that a pattern comes from a literal. For example to skip UTF validation (ref #13237). @bcardiff's API proposal should work for that. But we can go a step further to a single method: Regex.literal("cat", i: true) The |
Why not use an array instead? Regex.literal("cat", [:i]) |
I think it's good that the implementation can declare which flags it supports in the method signature and the compiler just ticks them. This could allow adding support for new modifiers without any changes to the compiler (except recognizing the syntax). It keeps backwards compatibility and produces a compile time error if the implementation does not support a given modifier. |
👍 on |
The compiler currently passes the integer value of the compiler's version of
Regex::Options
when expanding aRegexLiteral
.For example
/cat/i
expands toRegex.new("cat", Regex::Options.new(1))
(withRegex::Options::CASELESS = 0x00000001
).This constitutes a strong dependency between the compiler and
Regex
implementation because they need to agree on what value represents what. With such a tight coupling it's impossible to change the stdlib implementation (as discussed in #13152).The compiler should use logical names to represent the modifier options instead of integer values.
I expect this can be done in a backwards-compatible way so that the compiler would also be able to build an older stdlib.
Extracted from #13152 (comment)
The text was updated successfully, but these errors were encountered: