Skip to content

Commit 5c06479

Browse files
committed
Make SymbolNode#value_loc non-optional
Sort of a followup for 929aec1 It changed the value for `:''` into nil/null, which is a bit inconvenient. For syntax-valid code I expect it to always be present. It's also inconsistent with `StringNode`. In effect, this reverts the snapshots changes and the two changes in ruby for the ripper/parser compiler.
1 parent c72817c commit 5c06479

11 files changed

Lines changed: 39 additions & 37 deletions

File tree

config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4553,7 +4553,7 @@ nodes:
45534553
- name: opening_loc
45544554
type: location?
45554555
- name: value_loc
4556-
type: location?
4556+
type: location
45574557
- name: closing_loc
45584558
type: location?
45594559
- name: unescaped

lib/prism/translation/parser/compiler.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ def visit_assoc_node(node)
165165
else
166166
parts =
167167
if key.is_a?(SymbolNode)
168-
value_loc = key.value_loc
169-
if value_loc.nil?
168+
value = key.value
169+
if value == ""
170170
[]
171-
elsif value_loc.slice.include?("\n")
172-
string_nodes_from_line_continuations(key.unescaped, value_loc.slice, value_loc.start_offset, key.opening)
171+
elsif value.include?("\n")
172+
string_nodes_from_line_continuations(key.unescaped, value, key.value_loc.start_offset, key.opening)
173173
else
174-
[builder.string_internal([key.unescaped, srange(value_loc)])]
174+
[builder.string_internal([key.unescaped, srange(key.value_loc)])]
175175
end
176176
else
177177
visit_all(key.parts)
@@ -1775,7 +1775,7 @@ def visit_symbol_node(node)
17751775
end
17761776
else
17771777
parts =
1778-
if node.value_loc.nil?
1778+
if node.value == ""
17791779
[]
17801780
elsif node.value.include?("\n")
17811781
string_nodes_from_line_continuations(node.unescaped, node.value, node.value_loc.start_offset, node.opening)

lib/prism/translation/ripper.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3840,12 +3840,14 @@ def visit_super_node(node)
38403840
# ^^^^
38413841
def visit_symbol_node(node)
38423842
with_string_bounds(node) do
3843-
if node.value_loc.nil?
3844-
bounds(node.location)
3845-
on_dyna_symbol(on_string_content)
3846-
elsif (opening = node.opening)&.match?(/^%s|['"]:?$/)
3843+
if (opening = node.opening)&.match?(/^%s|['"]:?$/)
38473844
bounds(node.value_loc)
3848-
content = on_string_add(on_string_content, on_tstring_content(node.value))
3845+
content = on_string_content
3846+
3847+
if !(value = node.value).empty?
3848+
content = on_string_add(content, on_tstring_content(value))
3849+
end
3850+
38493851
bounds(node.location)
38503852
on_dyna_symbol(content)
38513853
elsif (closing = node.closing) == ":"

rbi/generated/prism/dsl.rbi

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rbi/generated/prism/node.rbi

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

sig/generated/prism/dsl.rbs

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

sig/generated/prism/node.rbs

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

snapshots/hashes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@
447447
│ │ │ @ SymbolNode (location: (30,2)-(30,5))
448448
│ │ │ ├── flags: static_literal
449449
│ │ │ ├── opening_loc: (30,2)-(30,3) = "\""
450-
│ │ │ ├── value_loc:
450+
│ │ │ ├── value_loc: (1,0)-(1,0) = ""
451451
│ │ │ ├── closing_loc: (30,3)-(30,5) = "\":"
452452
│ │ │ └── unescaped: ""
453453
│ │ ├── value:

snapshots/seattlerb/symbol_empty.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
└── @ SymbolNode (location: (1,0)-(1,3))
99
├── flags: newline, static_literal, forced_us_ascii_encoding
1010
├── opening_loc: (1,0)-(1,2) = ":'"
11-
├── value_loc:
11+
├── value_loc: (1,2)-(1,2) = ""
1212
├── closing_loc: (1,2)-(1,3) = "'"
1313
└── unescaped: ""

snapshots/spanning_heredoc_newlines.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
│ │ └── @ SymbolNode (location: (17,4)-(20,0))
130130
│ │ ├── flags: static_literal, forced_us_ascii_encoding
131131
│ │ ├── opening_loc: (17,4)-(18,0) = "%s\n"
132-
│ │ ├── value_loc:
132+
│ │ ├── value_loc: (18,0)-(18,0) = ""
133133
│ │ ├── closing_loc: (19,0)-(20,0) = "\n"
134134
│ │ └── unescaped: ""
135135
│ ├── closing_loc: ∅

0 commit comments

Comments
 (0)