Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a8b239c

Browse files
committed
Make sure StringLiteral and StringEmbExpr know that they can be extended by heredocs.
1 parent c05de43 commit a8b239c

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
5757
- Properly handle trailing comments after a `then` operator on a `When` or `In` clause.
5858
- Ensure nested `HshPtn` nodes use braces.
5959
- Force using braces if the block is within a `Binary` within the predicate of a loop or conditional.
60+
- Make sure `StringLiteral` and `StringEmbExpr` know that they can be extended by heredocs.
6061

6162
### Removed
6263

lib/syntax_tree.rb

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10522,21 +10522,6 @@ def on_sclass(target, bodystmt)
1052210522
# value
1052310523
# end
1052410524

10525-
# stmts_add is a parser event that represents a single statement inside a
10526-
# list of statements within any lexical block. It accepts as arguments the
10527-
# parent stmts node as well as an stmt which can be any expression in
10528-
# Ruby.
10529-
def on_stmts_add(statements, statement)
10530-
location =
10531-
if statements.body.empty?
10532-
statement.location
10533-
else
10534-
statements.location.to(statement.location)
10535-
end
10536-
10537-
Statements.new(self, body: statements.body << statement, location: location)
10538-
end
10539-
1054010525
# Everything that has a block of code inside of it has a list of statements.
1054110526
# Normally we would just track those as a node that has an array body, but we
1054210527
# have some special handling in order to handle empty statement lists. They
@@ -10711,6 +10696,21 @@ def attach_comments(start_char, end_char)
1071110696
end
1071210697
end
1071310698

10699+
# stmts_add is a parser event that represents a single statement inside a
10700+
# list of statements within any lexical block. It accepts as arguments the
10701+
# parent stmts node as well as an stmt which can be any expression in
10702+
# Ruby.
10703+
def on_stmts_add(statements, statement)
10704+
location =
10705+
if statements.body.empty?
10706+
statement.location
10707+
else
10708+
statements.location.to(statement.location)
10709+
end
10710+
10711+
Statements.new(self, body: statements.body << statement, location: location)
10712+
end
10713+
1071410714
# :call-seq:
1071510715
# on_stmts_new: () -> Statements
1071610716
def on_stmts_new
@@ -10982,10 +10982,15 @@ def on_string_embexpr(statements)
1098210982
embexpr_end.location.start_char
1098310983
)
1098410984

10985-
StringEmbExpr.new(
10986-
statements: statements,
10987-
location: embexpr_beg.location.to(embexpr_end.location)
10988-
)
10985+
location =
10986+
Location.new(
10987+
start_line: embexpr_beg.location.start_line,
10988+
start_char: embexpr_beg.location.start_char,
10989+
end_line: [embexpr_end.location.end_line, statements.location.end_line].max,
10990+
end_char: embexpr_end.location.end_char
10991+
)
10992+
10993+
StringEmbExpr.new(statements: statements, location: location)
1098910994
end
1099010995

1099110996
# StringLiteral represents a string literal.
@@ -11087,10 +11092,18 @@ def on_string_literal(string)
1108711092
tstring_beg = find_token(TStringBeg)
1108811093
tstring_end = find_token(TStringEnd)
1108911094

11095+
location =
11096+
Location.new(
11097+
start_line: tstring_beg.location.start_line,
11098+
start_char: tstring_beg.location.start_char,
11099+
end_line: [tstring_end.location.end_line, string.location.end_line].max,
11100+
end_char: tstring_end.location.end_char
11101+
)
11102+
1109011103
StringLiteral.new(
1109111104
parts: string.parts,
1109211105
quote: tstring_beg.value,
11093-
location: tstring_beg.location.to(tstring_end.location)
11106+
location: location
1109411107
)
1109511108
end
1109611109
end

0 commit comments

Comments
 (0)