mirror of
https://github.com/ruby/ruby.git
synced 2025-08-28 07:26:00 +02:00
parent
58f93eec18
commit
cd516ebd20
3 changed files with 20 additions and 2 deletions
|
@ -73,6 +73,8 @@ module Prism
|
||||||
|
|
||||||
# Desugar `x += y` to `x = x + y`
|
# Desugar `x += y` to `x = x + y`
|
||||||
def compile
|
def compile
|
||||||
|
operator_loc = node.operator_loc.chop
|
||||||
|
|
||||||
write_class.new(
|
write_class.new(
|
||||||
source,
|
source,
|
||||||
*arguments,
|
*arguments,
|
||||||
|
@ -82,8 +84,8 @@ module Prism
|
||||||
0,
|
0,
|
||||||
read_class.new(source, *arguments, node.name_loc),
|
read_class.new(source, *arguments, node.name_loc),
|
||||||
nil,
|
nil,
|
||||||
node.operator_loc.slice.chomp("=").to_sym,
|
operator_loc.slice.to_sym,
|
||||||
node.operator_loc.copy(length: node.operator_loc.length - 1),
|
operator_loc,
|
||||||
nil,
|
nil,
|
||||||
ArgumentsNode.new(source, 0, [node.value], node.value.location),
|
ArgumentsNode.new(source, 0, [node.value], node.value.location),
|
||||||
nil,
|
nil,
|
||||||
|
|
|
@ -161,6 +161,11 @@ module Prism
|
||||||
Location.new(source, start_offset, length)
|
Location.new(source, start_offset, length)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a new location that is the result of chopping off the last byte.
|
||||||
|
def chop
|
||||||
|
copy(length: length == 0 ? length : length - 1)
|
||||||
|
end
|
||||||
|
|
||||||
# Returns a string representation of this location.
|
# Returns a string representation of this location.
|
||||||
def inspect
|
def inspect
|
||||||
"#<Prism::Location @start_offset=#{@start_offset} @length=#{@length} start_line=#{start_line}>"
|
"#<Prism::Location @start_offset=#{@start_offset} @length=#{@length} start_line=#{start_line}>"
|
||||||
|
|
|
@ -198,6 +198,17 @@ module Prism
|
||||||
assert_equal 7, location.end_code_units_column(Encoding::UTF_32LE)
|
assert_equal 7, location.end_code_units_column(Encoding::UTF_32LE)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_location_chop
|
||||||
|
location = Prism.parse("foo").value.location
|
||||||
|
|
||||||
|
assert_equal "fo", location.chop.slice
|
||||||
|
assert_equal "", location.chop.chop.chop.slice
|
||||||
|
|
||||||
|
# Check that we don't go negative.
|
||||||
|
10.times { location = location.chop }
|
||||||
|
assert_equal "", location.slice
|
||||||
|
end
|
||||||
|
|
||||||
def test_heredoc?
|
def test_heredoc?
|
||||||
refute parse_expression("\"foo\"").heredoc?
|
refute parse_expression("\"foo\"").heredoc?
|
||||||
refute parse_expression("\"foo \#{1}\"").heredoc?
|
refute parse_expression("\"foo \#{1}\"").heredoc?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue