diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2026-01-26 21:36:20 -0500 |
|---|---|---|
| committer | Kevin Newton <kddnewton@gmail.com> | 2026-01-27 15:30:45 -0500 |
| commit | af4a1ca021845837fd7bfb1e1b4b5abd7e336c34 (patch) | |
| tree | 08d5929c5c3239b9e742c8b5906f8964949a6ff2 /lib | |
| parent | ec154654a99c07d065108e9c31793eb9ccbd9ad0 (diff) | |
Use slices instead of locations
In the C API, we want to use slices instead of locations in the
AST. In this case a "slice" is effectively the same thing as the
location, expect it is represented using a 32-bit offset and a
32-bit length. This will cut down on half of the space of all of
the locations in the AST.
Note that from the Ruby/Java/JavaScript side, this is effectively
an invisible change. This only impacts the C/Rust side.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/prism/translation/parser/compiler.rb | 2 | ||||
| -rw-r--r-- | lib/prism/translation/parser/lexer.rb | 2 | ||||
| -rw-r--r-- | lib/prism/translation/ripper.rb | 13 |
3 files changed, 7 insertions, 10 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index 8805614603..bd3618b162 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -1767,7 +1767,7 @@ module Prism end else parts = - if node.value == "" + if node.value_loc.nil? [] elsif node.value.include?("\n") string_nodes_from_line_continuations(node.unescaped, node.value, node.value_loc.start_offset, node.opening) diff --git a/lib/prism/translation/parser/lexer.rb b/lib/prism/translation/parser/lexer.rb index 75c48ef667..0491e79cd2 100644 --- a/lib/prism/translation/parser/lexer.rb +++ b/lib/prism/translation/parser/lexer.rb @@ -18,8 +18,6 @@ module Prism # The direct translating of types between the two lexers. TYPES = { # These tokens should never appear in the output of the lexer. - MISSING: nil, - NOT_PROVIDED: nil, EMBDOC_END: nil, EMBDOC_LINE: nil, diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index 735217d2e0..70f72132f6 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -3152,14 +3152,13 @@ module Prism # :foo # ^^^^ def visit_symbol_node(node) - if (opening = node.opening)&.match?(/^%s|['"]:?$/) + if node.value_loc.nil? + bounds(node.location) + on_dyna_symbol(on_string_content) + elsif (opening = node.opening)&.match?(/^%s|['"]:?$/) bounds(node.value_loc) - content = on_string_content - - if !(value = node.value).empty? - content = on_string_add(content, on_tstring_content(value)) - end - + content = on_string_add(on_string_content, on_tstring_content(node.value)) + bounds(node.location) on_dyna_symbol(content) elsif (closing = node.closing) == ":" bounds(node.location) |
