Skip to content

Commit 899af92

Browse files
committed
Use slices for more internal locations
1 parent 859b4e4 commit 899af92

10 files changed

Lines changed: 875 additions & 979 deletions

File tree

config.yml

Lines changed: 225 additions & 229 deletions
Large diffs are not rendered by default.

lib/prism/translation/parser/compiler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ def visit_symbol_node(node)
17671767
end
17681768
else
17691769
parts =
1770-
if node.value == ""
1770+
if node.value_loc.nil?
17711771
[]
17721772
elsif node.value.include?("\n")
17731773
string_nodes_from_line_continuations(node.unescaped, node.value, node.value_loc.start_offset, node.opening)

lib/prism/translation/parser/lexer.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class Lexer
1919
TYPES = {
2020
# These tokens should never appear in the output of the lexer.
2121
MISSING: nil,
22-
NOT_PROVIDED: nil,
2322
EMBDOC_END: nil,
2423
EMBDOC_LINE: nil,
2524

lib/prism/translation/ripper.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,14 +3106,13 @@ def visit_super_node(node)
31063106
# :foo
31073107
# ^^^^
31083108
def visit_symbol_node(node)
3109-
if (opening = node.opening)&.match?(/^%s|['"]:?$/)
3109+
if node.value_loc.nil?
3110+
bounds(node.location)
3111+
on_dyna_symbol(on_string_content)
3112+
elsif (opening = node.opening)&.match?(/^%s|['"]:?$/)
31103113
bounds(node.value_loc)
3111-
content = on_string_content
3112-
3113-
if !(value = node.value).empty?
3114-
content = on_string_add(content, on_tstring_content(value))
3115-
end
3116-
3114+
content = on_string_add(on_string_content, on_tstring_content(node.value))
3115+
bounds(node.location)
31173116
on_dyna_symbol(content)
31183117
elsif (closing = node.closing) == ":"
31193118
bounds(node.location)

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: (1,2)-(1,2) = ""
11+
├── value_loc:
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: (18,0)-(18,0) = ""
132+
│ │ ├── value_loc:
133133
│ │ ├── closing_loc: (19,0)-(20,0) = "\n"
134134
│ │ └── unescaped: ""
135135
│ ├── closing_loc: ∅

snapshots/unparser/corpus/literal/literal.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@
620620
├── @ SymbolNode (location: (48,0)-(48,3))
621621
│ ├── flags: newline, static_literal
622622
│ ├── opening_loc: (48,0)-(48,2) = ":\""
623-
│ ├── value_loc: (1,0)-(1,0) = ""
623+
│ ├── value_loc:
624624
│ ├── closing_loc: (48,2)-(48,3) = "\""
625625
│ └── unescaped: ""
626626
├── @ RegularExpressionNode (location: (49,0)-(49,5))

src/prism.c

Lines changed: 637 additions & 731 deletions
Large diffs are not rendered by default.

templates/src/token_type.c.erb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ pm_token_type_human(pm_token_type_t token_type) {
3131
switch (token_type) {
3232
case PM_TOKEN_EOF:
3333
return "end-of-input";
34-
case PM_TOKEN_MISSING:
35-
return "missing token";
36-
case PM_TOKEN_NOT_PROVIDED:
37-
return "not provided token";
3834
case PM_TOKEN_AMPERSAND:
3935
return "'&'";
4036
case PM_TOKEN_AMPERSAND_AMPERSAND:

test/prism/errors_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ def test_embdoc_ending
4545
def test_unterminated_string_closing
4646
statement = Prism.parse_statement("'hello")
4747
assert_equal statement.unescaped, "hello"
48-
assert_empty statement.closing
48+
assert_nil statement.closing
4949
end
5050

5151
def test_unterminated_interpolated_string_closing
5252
statement = Prism.parse_statement('"hello')
5353
assert_equal statement.unescaped, "hello"
54-
assert_empty statement.closing
54+
assert_nil statement.closing
5555
end
5656

5757
def test_unterminated_empty_string_closing
5858
statement = Prism.parse_statement('"')
5959
assert_empty statement.unescaped
60-
assert_empty statement.closing
60+
assert_nil statement.closing
6161
end
6262

6363
def test_invalid_message_name

0 commit comments

Comments
 (0)