Skip to content

Commit b23136e

Browse files
committed
Handle a non-interpolated dsym spanning a heredoc
1 parent 9a343b9 commit b23136e

File tree

3 files changed

+124
-44
lines changed

3 files changed

+124
-44
lines changed

src/prism.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12494,6 +12494,34 @@ parse_symbol(pm_parser_t *parser, pm_lex_mode_t *lex_mode, pm_lex_state_t next_s
1249412494
content = parser->current;
1249512495
unescaped = parser->current_string;
1249612496
parser_lex(parser);
12497+
12498+
// If we have two string contents in a row, then the content of this
12499+
// symbol is split because of heredoc contents. This looks like:
12500+
//
12501+
// <<A; :'a
12502+
// A
12503+
// b'
12504+
//
12505+
// In this case, the best way we have to represent this is as an
12506+
// interpolated string node, so that's what we'll do here.
12507+
if (match1(parser, PM_TOKEN_STRING_CONTENT)) {
12508+
pm_node_list_t parts = { 0 };
12509+
pm_token_t bounds = not_provided(parser);
12510+
12511+
pm_node_t *part = (pm_node_t *) pm_string_node_create_unescaped(parser, &bounds, &content, &bounds, &unescaped);
12512+
pm_node_list_append(&parts, part);
12513+
12514+
part = (pm_node_t *) pm_string_node_create_unescaped(parser, &bounds, &parser->current, &bounds, &parser->current_string);
12515+
pm_node_list_append(&parts, part);
12516+
12517+
if (next_state != PM_LEX_STATE_NONE) {
12518+
lex_state_set(parser, next_state);
12519+
}
12520+
12521+
parser_lex(parser);
12522+
expect1(parser, PM_TOKEN_STRING_END, PM_ERR_SYMBOL_TERM_DYNAMIC);
12523+
return (pm_node_t *) pm_interpolated_symbol_node_create(parser, &opening, &parts, &parser->previous);
12524+
}
1249712525
} else {
1249812526
content = (pm_token_t) { .type = PM_TOKEN_STRING_CONTENT, .start = parser->previous.end, .end = parser->previous.end };
1249912527
pm_string_shared_init(&unescaped, content.start, content.end);

test/prism/fixtures/spanning_heredoc.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ p]
5353
<<A; /\
5454
A
5555
(?<a>)/ =~ ''
56+
57+
<<A; :'a
58+
A
59+
b'
60+
61+
<<A; :"a
62+
A
63+
b"

test/prism/snapshots/spanning_heredoc.txt

Lines changed: 88 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)