module Prism::Serialize
A module responsible for deserializing parse results.
Constants
- MAJOR_VERSION
The major version of prism that we are expecting to find in the serialized strings.
- MINOR_VERSION
The minor version of prism that we are expecting to find in the serialized strings.
- PATCH_VERSION
The patch version of prism that we are expecting to find in the serialized strings.
- TOKEN_TYPES
The token types that can be indexed by their enum values.
Public Class Methods
Source
# File lib/prism/serialize.rb, line 87defself.load_lex(input,serialized,freeze)source =Source.for(input)loader =Loader.new(source,serialized)tokens =loader.load_tokensencoding =loader.load_encodingstart_line =loader.load_varsintoffsets =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)raiseunlessloader.eof?result =LexResult.new(tokens,comments,magic_comments,data_loc,errors,warnings,source)tokens.eachdo|token|token[0].value.force_encoding(encoding)iffreezetoken[0].deep_freezetoken.freezeendendiffreezesource.deep_freezetokens.freezeresult.freezeendresultend
Deserialize the dumped output from a request to lex or lex_file.
The formatting of the source of this method is purposeful to illustrate the structure of the serialized data.
Source
# File lib/prism/serialize.rb, line 34defself.load_parse(input,serialized,freeze)input =input.dupsource =Source.for(input)loader =Loader.new(source,serialized)loader.load_headerencoding =loader.load_encodingstart_line =loader.load_varsintoffsets =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_uint32cpool_size =loader.load_varuintconstant_pool =ConstantPool.new(input,serialized,cpool_base,cpool_size)node =loader.load_node(constant_pool,encoding,freeze)loader.load_constant_pool(constant_pool)raiseunlessloader.eof?result =ParseResult.new(node,comments,magic_comments,data_loc,errors,warnings,source)result.freezeiffreezeinput.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::BINARYinput.force_encoding(Encoding::UTF_8)input.force_encoding(Encoding::BINARY)unlessinput.valid_encoding?endiffreezeinput.freezesource.deep_freezeendresultend
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.
Source
# File lib/prism/serialize.rb, line 131defself.load_parse_comments(input,serialized,freeze)source =Source.for(input)loader =Loader.new(source,serialized)loader.load_headerloader.load_encodingstart_line =loader.load_varsintsource.replace_start_line(start_line)result =loader.load_comments(freeze)raiseunlessloader.eof?source.deep_freezeiffreezeresultend
Deserialize the dumped output from a request to parse_comments or parse_file_comments.
The formatting of the source of this method is purposeful to illustrate the structure of the serialized data.
Source
# File lib/prism/serialize.rb, line 153defself.load_parse_lex(input,serialized,freeze)source =Source.for(input)loader =Loader.new(source,serialized)tokens =loader.load_tokensloader.load_headerencoding =loader.load_encodingstart_line =loader.load_varsintoffsets =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_uint32cpool_size =loader.load_varuintconstant_pool =ConstantPool.new(input,serialized,cpool_base,cpool_size)node =loader.load_node(constant_pool,encoding,freeze)loader.load_constant_pool(constant_pool)raiseunlessloader.eof?value = [node,tokens]result =ParseLexResult.new(value,comments,magic_comments,data_loc,errors,warnings,source)tokens.eachdo|token|token[0].value.force_encoding(encoding)iffreezetoken[0].deep_freezetoken.freezeendendiffreezesource.deep_freezetokens.freezevalue.freezeresult.freezeendresultend
Deserialize the dumped output from a request to parse_lex or parse_lex_file.
The formatting of the source of this method is purposeful to illustrate the structure of the serialized data.