aboutsummaryrefslogtreecommitdiffstats
path: root/prism
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2023-09-27 16:53:37 -0400
committerKevin Newton <kddnewton@gmail.com>2023-09-27 18:36:23 -0400
commit54bbf9a6e92acd0b1581e2a7bb31aab1ecbdb176 (patch)
tree8af651770da747f875ccb397ea5dbf03b4c009de /prism
parent175ac32c62101c601ab701f08e3a781b3b088e62 (diff)
downloadruby-54bbf9a6e92acd0b1581e2a7bb31aab1ecbdb176.tar.gz
[PRISM] Implement MatchLastLineNode
This PR implements `MatchLastLineNode` for Prism. Related: ruby/prism#1335
Diffstat (limited to 'prism')
-rw-r--r--prism/prism_compiler.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/prism/prism_compiler.c b/prism/prism_compiler.c
index 56f0907f6f..7247d701bd 100644
--- a/prism/prism_compiler.c
+++ b/prism/prism_compiler.c
@@ -1594,6 +1594,32 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
ADD_SETLOCAL(ret, &dummy_line_node, (int)index, local_write_node->depth);
return;
}
+ case PM_MATCH_LAST_LINE_NODE: {
+ if (!popped) {
+ pm_match_last_line_node_t *regular_expression_node = (pm_match_last_line_node_t *) node;
+ VALUE regex_str = parse_string(&regular_expression_node->unescaped);
+ int flags = 0;
+
+ if (regular_expression_node->base.flags & PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE) {
+ flags |= ONIG_OPTION_IGNORECASE;
+ }
+
+ if (regular_expression_node->base.flags & PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE) {
+ flags |= ONIG_OPTION_MULTILINE;
+ }
+
+ if (regular_expression_node->base.flags & PM_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);
+ ADD_INSN2(ret, &dummy_line_node, getspecial, INT2FIX(0), INT2FIX(0));
+ ADD_SEND(ret, &dummy_line_node, idEqTilde, INT2NUM(1));
+ }
+
+ return;
+ }
case PM_MISSING_NODE: {
rb_bug("A pm_missing_node_t should not exist in prism's AST.");
return;