summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-10-10 14:28:15 -0400
committerKevin Newton <kddnewton@gmail.com>2023-10-13 15:31:30 -0400
commit5fc34f1cde041e72597c873d3ada8f3b039b991f (patch)
tree6099ab662d1a5b5063e1801743979bfbee03ecda
parent41ac8ddca34445076aba16504e1eeacae3cefed5 (diff)
[ruby/prism] Use current_string for handling %W lists
https://github.com/ruby/prism/commit/edb1674725
-rw-r--r--prism/prism.c25
-rw-r--r--test/prism/snapshots/seattlerb/pctW_lineno.txt2
-rw-r--r--test/prism/snapshots/spanning_heredoc.txt2
-rw-r--r--test/prism/snapshots/whitequark/parser_slash_slash_n_escaping_in_literals.txt2
-rw-r--r--test/prism/unescape_test.rb2
5 files changed, 21 insertions, 12 deletions
diff --git a/prism/prism.c b/prism/prism.c
index bf1c696be2..36d83db191 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -6064,7 +6064,7 @@ lex_interpolation(pm_parser_t *parser, const uint8_t *pound) {
}
}
-// static const uint8_t PM_ESCAPE_FLAG_NONE = 0x0;
+static const uint8_t PM_ESCAPE_FLAG_NONE = 0x0;
static const uint8_t PM_ESCAPE_FLAG_CONTROL = 0x1;
static const uint8_t PM_ESCAPE_FLAG_META = 0x2;
static const uint8_t PM_ESCAPE_FLAG_SINGLE = 0x4;
@@ -7915,12 +7915,13 @@ parser_lex(pm_parser_t *parser) {
case '\v':
case '\\':
pm_buffer_append_u8(&buffer, peeked);
+ parser->current.end++;
break;
case '\r':
pm_buffer_append_u8(&buffer, '\r');
- if (peek_offset(parser, 1) != '\n') break;
-
parser->current.end++;
+
+ if (peek(parser) != '\n') break;
/* fallthrough */
case '\n':
pm_buffer_append_u8(&buffer, '\n');
@@ -7936,18 +7937,24 @@ parser_lex(pm_parser_t *parser) {
pm_newline_list_append(&parser->newline_list, parser->current.end);
}
+ parser->current.end++;
break;
default:
- if (peeked != lex_mode->as.list.incrementor && peeked != lex_mode->as.list.terminator) {
+ if (peeked == lex_mode->as.list.incrementor || peeked == lex_mode->as.list.terminator) {
+ pm_buffer_append_u8(&buffer, peeked);
+ parser->current.end++;
+ } else if (lex_mode->as.list.interpolation) {
+ escape_read(parser, &buffer, PM_ESCAPE_FLAG_NONE);
+ } else {
pm_buffer_append_u8(&buffer, '\\');
+ pm_buffer_append_u8(&buffer, peeked);
+ parser->current.end++;
}
- pm_buffer_append_u8(&buffer, peeked);
+
break;
}
- parser->current.end++;
buffer_cursor = parser->current.end;
-
breakpoint = pm_strpbrk(parser, parser->current.end, breakpoints, parser->end - parser->current.end);
continue;
}
@@ -13600,7 +13607,9 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
parser_lex(parser);
pm_token_t opening = not_provided(parser);
pm_token_t closing = not_provided(parser);
- pm_string_node_t *string = (pm_string_node_t *) pm_string_node_create_and_unescape(parser, &opening, &parser->previous, &closing, PM_UNESCAPE_ALL);
+
+ pm_string_node_t *string = (pm_string_node_t *) pm_string_node_create(parser, &opening, &parser->previous, &closing);
+ string->unescaped = parser->current_string;
if (current == NULL) {
// If we hit content and the current node is NULL, then this is
diff --git a/test/prism/snapshots/seattlerb/pctW_lineno.txt b/test/prism/snapshots/seattlerb/pctW_lineno.txt
index 468150529d..20196fe2f9 100644
--- a/test/prism/snapshots/seattlerb/pctW_lineno.txt
+++ b/test/prism/snapshots/seattlerb/pctW_lineno.txt
@@ -28,7 +28,7 @@
│ │ ├── opening_loc: ∅
│ │ ├── content_loc: (3,0)-(4,1) = "e\\\nf"
│ │ ├── closing_loc: ∅
- │ │ └── unescaped: "ef"
+ │ │ └── unescaped: "e\nf"
│ ├── @ StringNode (location: (5,0)-(5,2))
│ │ ├── flags: ∅
│ │ ├── opening_loc: ∅
diff --git a/test/prism/snapshots/spanning_heredoc.txt b/test/prism/snapshots/spanning_heredoc.txt
index 4c6598b62b..cb99a343ab 100644
--- a/test/prism/snapshots/spanning_heredoc.txt
+++ b/test/prism/snapshots/spanning_heredoc.txt
@@ -216,7 +216,7 @@
│ │ │ │ │ ├── opening_loc: ∅
│ │ │ │ │ ├── content_loc: (35,12)-(35,14) = "l\\"
│ │ │ │ │ ├── closing_loc: ∅
- │ │ │ │ │ └── unescaped: "l\\"
+ │ │ │ │ │ └── unescaped: "l"
│ │ │ │ └── @ StringNode (location: (38,0)-(38,1))
│ │ │ │ ├── flags: ∅
│ │ │ │ ├── opening_loc: ∅
diff --git a/test/prism/snapshots/whitequark/parser_slash_slash_n_escaping_in_literals.txt b/test/prism/snapshots/whitequark/parser_slash_slash_n_escaping_in_literals.txt
index b9c6da2367..2de7dd439c 100644
--- a/test/prism/snapshots/whitequark/parser_slash_slash_n_escaping_in_literals.txt
+++ b/test/prism/snapshots/whitequark/parser_slash_slash_n_escaping_in_literals.txt
@@ -31,7 +31,7 @@
│ │ ├── opening_loc: ∅
│ │ ├── content_loc: (10,3)-(11,1) = "a\\\nb"
│ │ ├── closing_loc: ∅
- │ │ └── unescaped: "ab"
+ │ │ └── unescaped: "a\nb"
│ ├── opening_loc: (10,0)-(10,3) = "%W{"
│ └── closing_loc: (11,1)-(11,2) = "}"
├── @ ArrayNode (location: (13,0)-(14,2))
diff --git a/test/prism/unescape_test.rb b/test/prism/unescape_test.rb
index 92b7869d0c..4104b051dd 100644
--- a/test/prism/unescape_test.rb
+++ b/test/prism/unescape_test.rb
@@ -104,7 +104,7 @@ module Prism
# [Context::String.new("<<~\"H\"\n", "\nH"), escapes],
# [Context::String.new("<<~`H`\n", "\nH"), escapes],
[Context::List.new("%w[", "]"), escapes],
- # [Context::List.new("%W[", "]"), escapes],
+ [Context::List.new("%W[", "]"), escapes],
[Context::List.new("%i[", "]"), escapes],
# [Context::List.new("%I[", "]"), escapes],
# [Context::Symbol.new("%s[", "]"), escapes],