Skip to content

Commit

Permalink
[ruby/prism] Ensure symbol nodes not in interpolated symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed Feb 27, 2024
1 parent 2396b7a commit fc36882
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 11 additions & 4 deletions prism/prism.c
Expand Up @@ -16523,15 +16523,22 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b

pm_interpolated_symbol_node_append((pm_interpolated_symbol_node_t *) current, string);
} else if (PM_NODE_TYPE_P(current, PM_SYMBOL_NODE)) {
// If we hit string content and the current node is a string node,
// If we hit string content and the current node is a symbol node,
// then we need to convert the current node into an interpolated
// string and add the string content to the list of child nodes.
pm_node_t *string = (pm_node_t *) pm_string_node_create_current_string(parser, &opening, &parser->previous, &closing);
pm_symbol_node_t *cast = (pm_symbol_node_t *) current;
pm_token_t bounds = not_provided(parser);

pm_token_t content = { .type = PM_TOKEN_STRING_CONTENT, .start = cast->value_loc.start, .end = cast->value_loc.end };
pm_node_t *first_string = (pm_node_t *) pm_string_node_create_unescaped(parser, &bounds, &content, &bounds, &cast->unescaped);
pm_node_t *second_string = (pm_node_t *) pm_string_node_create_current_string(parser, &opening, &parser->previous, &closing);
parser_lex(parser);

pm_interpolated_symbol_node_t *interpolated = pm_interpolated_symbol_node_create(parser, &opening, NULL, &closing);
pm_interpolated_symbol_node_append(interpolated, current);
pm_interpolated_symbol_node_append(interpolated, string);
pm_interpolated_symbol_node_append(interpolated, first_string);
pm_interpolated_symbol_node_append(interpolated, second_string);

free(current);
current = (pm_node_t *) interpolated;
} else {
assert(false && "unreachable");
Expand Down
6 changes: 3 additions & 3 deletions test/prism/snapshots/spanning_heredoc.txt
Expand Up @@ -298,10 +298,10 @@
│ │ │ └── @ InterpolatedSymbolNode (location: (48,12)-(48,14))
│ │ │ ├── opening_loc: ∅
│ │ │ ├── parts: (length: 2)
│ │ │ │ ├── @ SymbolNode (location: (48,12)-(48,14))
│ │ │ │ │ ├── flags: forced_us_ascii_encoding
│ │ │ │ ├── @ StringNode (location: (48,12)-(48,14))
│ │ │ │ │ ├── flags:
│ │ │ │ │ ├── opening_loc: ∅
│ │ │ │ │ ├── value_loc: (48,12)-(48,14) = "p\\"
│ │ │ │ │ ├── content_loc: (48,12)-(48,14) = "p\\"
│ │ │ │ │ ├── closing_loc: ∅
│ │ │ │ │ └── unescaped: "p\n"
│ │ │ │ └── @ StringNode (location: (48,12)-(48,14))
Expand Down

0 comments on commit fc36882

Please sign in to comment.