Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions snapshots/heredoc_percent_q_newline_delimiter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
@ ProgramNode (location: (1,0)-(22,0))
├── flags: ∅
├── locals: []
└── statements:
@ StatementsNode (location: (1,0)-(22,0))
├── flags: ∅
└── body: (length: 7)
├── @ InterpolatedStringNode (location: (1,0)-(3,0))
│ ├── flags: newline, static_literal, mutable
│ ├── opening_loc: (1,0)-(2,0) = "%Q\n"
│ ├── parts: (length: 1)
│ │ └── @ EmbeddedStatementsNode (location: (2,0)-(2,6))
│ │ ├── flags: ∅
│ │ ├── opening_loc: (2,0)-(2,2) = "\#{"
│ │ ├── statements:
│ │ │ @ StatementsNode (location: (2,2)-(2,5))
│ │ │ ├── flags: ∅
│ │ │ └── body: (length: 1)
│ │ │ └── @ StringNode (location: (2,2)-(2,5))
│ │ │ ├── flags: static_literal, frozen
│ │ │ ├── opening_loc: (2,2)-(2,5) = "<<B"
│ │ │ ├── content_loc: (3,0)-(3,0) = ""
│ │ │ ├── closing_loc: (3,0)-(4,0) = "B\n"
│ │ │ └── unescaped: ""
│ │ └── closing_loc: (2,5)-(2,6) = "}"
│ └── closing_loc: (2,6)-(3,0) = "\n"
├── @ InterpolatedStringNode (location: (5,0)-(7,0))
│ ├── flags: newline, static_literal, mutable
│ ├── opening_loc: (5,0)-(6,0) = "%\n"
│ ├── parts: (length: 1)
│ │ └── @ EmbeddedStatementsNode (location: (6,0)-(6,6))
│ │ ├── flags: ∅
│ │ ├── opening_loc: (6,0)-(6,2) = "\#{"
│ │ ├── statements:
│ │ │ @ StatementsNode (location: (6,2)-(6,5))
│ │ │ ├── flags: ∅
│ │ │ └── body: (length: 1)
│ │ │ └── @ StringNode (location: (6,2)-(6,5))
│ │ │ ├── flags: static_literal, frozen
│ │ │ ├── opening_loc: (6,2)-(6,5) = "<<B"
│ │ │ ├── content_loc: (7,0)-(7,0) = ""
│ │ │ ├── closing_loc: (7,0)-(8,0) = "B\n"
│ │ │ └── unescaped: ""
│ │ └── closing_loc: (6,5)-(6,6) = "}"
│ └── closing_loc: (6,6)-(7,0) = "\n"
├── @ StringNode (location: (9,0)-(9,3))
│ ├── flags: newline
│ ├── opening_loc: (9,0)-(9,3) = "<<A"
│ ├── content_loc: (10,0)-(10,0) = ""
│ ├── closing_loc: (10,0)-(11,0) = "A\n"
│ └── unescaped: ""
├── @ InterpolatedStringNode (location: (9,5)-(12,0))
│ ├── flags: newline, static_literal, mutable
│ ├── opening_loc: (9,5)-(10,0) = "%Q\n"
│ ├── parts: (length: 1)
│ │ └── @ EmbeddedStatementsNode (location: (11,0)-(11,6))
│ │ ├── flags: ∅
│ │ ├── opening_loc: (11,0)-(11,2) = "\#{"
│ │ ├── statements:
│ │ │ @ StatementsNode (location: (11,2)-(11,5))
│ │ │ ├── flags: ∅
│ │ │ └── body: (length: 1)
│ │ │ └── @ StringNode (location: (11,2)-(11,5))
│ │ │ ├── flags: static_literal, frozen
│ │ │ ├── opening_loc: (11,2)-(11,5) = "<<B"
│ │ │ ├── content_loc: (12,0)-(12,0) = ""
│ │ │ ├── closing_loc: (12,0)-(13,0) = "B\n"
│ │ │ └── unescaped: ""
│ │ └── closing_loc: (11,5)-(11,6) = "}"
│ └── closing_loc: (11,6)-(12,0) = "\n"
├── @ StringNode (location: (14,0)-(14,3))
│ ├── flags: newline
│ ├── opening_loc: (14,0)-(14,3) = "<<A"
│ ├── content_loc: (15,0)-(15,0) = ""
│ ├── closing_loc: (15,0)-(16,0) = "A\n"
│ └── unescaped: ""
├── @ InterpolatedStringNode (location: (14,5)-(17,0))
│ ├── flags: newline, static_literal, mutable
│ ├── opening_loc: (14,5)-(15,0) = "%\n"
│ ├── parts: (length: 1)
│ │ └── @ EmbeddedStatementsNode (location: (16,0)-(16,6))
│ │ ├── flags: ∅
│ │ ├── opening_loc: (16,0)-(16,2) = "\#{"
│ │ ├── statements:
│ │ │ @ StatementsNode (location: (16,2)-(16,5))
│ │ │ ├── flags: ∅
│ │ │ └── body: (length: 1)
│ │ │ └── @ StringNode (location: (16,2)-(16,5))
│ │ │ ├── flags: static_literal, frozen
│ │ │ ├── opening_loc: (16,2)-(16,5) = "<<B"
│ │ │ ├── content_loc: (17,0)-(17,0) = ""
│ │ │ ├── closing_loc: (17,0)-(18,0) = "B\n"
│ │ │ └── unescaped: ""
│ │ └── closing_loc: (16,5)-(16,6) = "}"
│ └── closing_loc: (16,6)-(17,0) = "\n"
└── @ InterpolatedStringNode (location: (20,0)-(22,0))
├── flags: newline, static_literal, mutable
├── opening_loc: (20,0)-(21,0) = "%Q\r\n"
├── parts: (length: 1)
│ └── @ EmbeddedStatementsNode (location: (21,0)-(21,6))
│ ├── flags: ∅
│ ├── opening_loc: (21,0)-(21,2) = "\#{"
│ ├── statements:
│ │ @ StatementsNode (location: (21,2)-(21,5))
│ │ ├── flags: ∅
│ │ └── body: (length: 1)
│ │ └── @ StringNode (location: (21,2)-(21,5))
│ │ ├── flags: static_literal, frozen
│ │ ├── opening_loc: (21,2)-(21,5) = "<<B"
│ │ ├── content_loc: (22,0)-(22,0) = ""
│ │ ├── closing_loc: (22,0)-(23,0) = "B\n"
│ │ └── unescaped: ""
│ └── closing_loc: (21,5)-(21,6) = "}"
└── closing_loc: (21,6)-(22,0) = "\r\n"
7 changes: 7 additions & 0 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -11612,6 +11612,13 @@ parser_lex(pm_parser_t *parser) {
LEX(PM_TOKEN_LABEL_END);
}

// When the delimiter itself is a newline, we won't
// get a chance to flush heredocs in the usual places since
// the newline is already consumed.
if (term == '\n' && parser->heredoc_end) {
parser_flush_heredoc_end(parser);
}

lex_state_set(parser, PM_LEX_STATE_END);
lex_mode_pop(parser);
LEX(PM_TOKEN_STRING_END);
Expand Down
11 changes: 11 additions & 0 deletions test/prism/errors/heredoc_percent_q_newline_delimiter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%q
#{<<B}
B
^ unexpected constant, expecting end-of-input

<<A; %q
A
#{<<B}
B
^ unexpected constant, expecting end-of-input

22 changes: 22 additions & 0 deletions test/prism/fixtures/heredoc_percent_q_newline_delimiter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
%Q
#{<<B}
B

%
#{<<B}
B

<<A; %Q
A
#{<<B}
B

<<A; %
A
#{<<B}
B

# \r\n
%Q
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to just work without special handling, see snapshot for confirmation

#{<<B}
B
3 changes: 3 additions & 0 deletions test/prism/ruby/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class ParserTest < TestCase
"alias.txt",
"seattlerb/bug_215.txt",

# %Q with newline delimiter and heredoc interpolation
"heredoc_percent_q_newline_delimiter.txt",

# 1.. && 2
"ranges.txt",

Expand Down
1 change: 1 addition & 0 deletions test/prism/ruby/ruby_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class RubyParserTest < TestCase
"alias.txt",
"dsym_str.txt",
"dos_endings.txt",
"heredoc_percent_q_newline_delimiter.txt",
"heredocs_with_fake_newlines.txt",
"heredocs_with_ignored_newlines.txt",
"method_calls.txt",
Expand Down
Loading