Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Prism.parse_stream
parse_stream(stream, **options)
lib/prism/ffi.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/prism/ffi.rb, line 264
def parse_stream(stream, **options)
LibRubyParser::PrismBuffer.with do |buffer|
source = +""
callback = -> (string, size, _) {
raise "Expected size to be >= 0, got: #{size}" if size <= 0
if !(line = stream.gets(size - 1)).nil?
source << line
string.write_string("#{line}\x00", line.bytesize + 1)
end
}
# In the pm_serialize_parse_stream function it accepts a pointer to the
# IO object as a void* and then passes it through to the callback as the
# third argument, but it never touches it itself. As such, since we have
# access to the IO object already through the closure of the lambda, we
# can pass a null pointer here and not worry.
LibRubyParser.pm_serialize_parse_stream(buffer.pointer, nil, callback, dump_options(options))
Prism.load(source, buffer.read)
end
end
Mirror the Prism.parse_stream API by using the serialization API.