Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Prism::Translation::Parser::Compiler#srange_find
srange_find(start_offset, end_offset, character)
lib/prism/translation/parser/compiler.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/prism/translation/parser/compiler.rb, line 2006
def srange_find(start_offset, end_offset, character)
if (match = source_buffer.source.byteslice(start_offset...end_offset)[/\A\s*#{character}/])
final_offset = start_offset + match.bytesize
[character, Range.new(source_buffer, offset_cache[final_offset - character.bytesize], offset_cache[final_offset])]
end
end
Constructs a new source range by finding the given character between the given start offset and end offset. If the needle is not found, it returns nil. Importantly it does not search past newlines or comments.
Note that end_offset is allowed to be nil, in which case this will search until the end of the string.