diff options
author | eileencodes <[email protected]> | 2023-09-19 15:25:13 -0400 |
---|---|---|
committer | Kevin Newton <[email protected]> | 2023-09-27 11:25:53 -0400 |
commit | 2bc243b3dcd10d6de3efd80c3e91413d83b476fe (patch) | |
tree | b8d79c3654c77e9d3e152a5058932eb67c9c64f1 | |
parent | 2000cf918358460f9d7da86fb253318fcdbe8e57 (diff) |
[YARP] Implement regex flags
This fixes the TODO in the code that was passing 0 instead of the regex
flags.
-rw-r--r-- | test/yarp/compiler_test.rb | 7 | ||||
-rw-r--r-- | yarp/yarp_compiler.c | 17 |
2 files changed, 22 insertions, 2 deletions
diff --git a/test/yarp/compiler_test.rb b/test/yarp/compiler_test.rb index 9af208f625..876e952640 100644 --- a/test/yarp/compiler_test.rb +++ b/test/yarp/compiler_test.rb @@ -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 diff --git a/yarp/yarp_compiler.c b/yarp/yarp_compiler.c index a3994e387e..4b3e6ec11b 100644 --- a/yarp/yarp_compiler.c +++ b/yarp/yarp_compiler.c @@ -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; |