class method
Prism::Serialize.load_parse
load_parse(input, serialized, freeze)
lib/prism/serialize.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/prism/serialize.rb, line 34
def self.load_parse(input, serialized, freeze)
input = input.dup
source = Source.for(input)
loader = Loader.new(source, serialized)
loader.load_header
encoding = loader.load_encoding
start_line = loader.load_varsint
offsets = loader.load_line_offsets(freeze)
source.replace_start_line(start_line)
source.replace_offsets(offsets)
comments = loader.load_comments(freeze)
magic_comments = loader.load_magic_comments(freeze)
data_loc = loader.load_optional_location_object(freeze)
errors = loader.load_errors(encoding, freeze)
warnings = loader.load_warnings(encoding, freeze)
cpool_base = loader.load_uint32
cpool_size = loader.load_varuint
constant_pool = ConstantPool.new(input, serialized, cpool_base, cpool_size)
node = loader.load_node(constant_pool, encoding, freeze)
loader.load_constant_pool(constant_pool)
raise unless loader.eof?
result = ParseResult.new(node, comments, magic_comments, data_loc, errors, warnings, source)
result.freeze if freeze
input.force_encoding(encoding)
# This is an extremely niche use-case where the file was marked as binary
# but it contained UTF-8-encoded characters. In that case we will actually
# put it back to UTF-8 to give the location APIs the best chance of being
# correct.
if !input.ascii_only? && input.encoding == Encoding::BINARY
input.force_encoding(Encoding::UTF_8)
input.force_encoding(Encoding::BINARY) unless input.valid_encoding?
end
if freeze
input.freeze
source.deep_freeze
end
result
end
Deserialize the dumped output from a request to parse or parse_file.
The formatting of the source of this method is purposeful to illustrate the structure of the serialized data.