зеркало из https://github.com/github/ruby.git
[YARP] Implement regex flags
This fixes the TODO in the code that was passing 0 instead of the regex flags.
This commit is contained in:
Родитель
2000cf9183
Коммит
2bc243b3dc
|
@ -252,6 +252,13 @@ module YARP
|
|||
|
||||
def test_RegularExpressionNode
|
||||
test_yarp_eval('/yct/')
|
||||
test_yarp_eval('/yct/i')
|
||||
test_yarp_eval('/yct/x')
|
||||
test_yarp_eval('/yct/m')
|
||||
test_yarp_eval('/yct/im')
|
||||
test_yarp_eval('/yct/mx')
|
||||
test_yarp_eval('/yct/xi')
|
||||
test_yarp_eval('/yct/ixm')
|
||||
end
|
||||
|
||||
def test_StringConcatNode
|
||||
|
|
|
@ -1795,8 +1795,21 @@ yp_compile_node(rb_iseq_t *iseq, const yp_node_t *node, LINK_ANCHOR *const ret,
|
|||
if (!popped) {
|
||||
yp_regular_expression_node_t *regular_expression_node = (yp_regular_expression_node_t *) node;
|
||||
VALUE regex_str = parse_string(®ular_expression_node->unescaped);
|
||||
// TODO: Replace 0 with regex options
|
||||
VALUE regex = rb_reg_new(RSTRING_PTR(regex_str), RSTRING_LEN(regex_str), 0);
|
||||
int flags = 0;
|
||||
|
||||
if (regular_expression_node->base.flags & YP_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE) {
|
||||
flags |= ONIG_OPTION_IGNORECASE;
|
||||
}
|
||||
|
||||
if (regular_expression_node->base.flags & YP_REGULAR_EXPRESSION_FLAGS_MULTI_LINE) {
|
||||
flags |= ONIG_OPTION_MULTILINE;
|
||||
}
|
||||
|
||||
if (regular_expression_node->base.flags & YP_REGULAR_EXPRESSION_FLAGS_EXTENDED) {
|
||||
flags |= ONIG_OPTION_EXTEND;
|
||||
}
|
||||
|
||||
VALUE regex = rb_reg_new(RSTRING_PTR(regex_str), RSTRING_LEN(regex_str), flags);
|
||||
ADD_INSN1(ret, &dummy_line_node, putobject, regex);
|
||||
}
|
||||
return;
|
||||
|
|
Загрузка…
Ссылка в новой задаче