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 28
def self.load(input, serialized)
input = input.dup
source = Source.for(input)
loader = Loader.new(source, serialized)
result = loader.load_result
input.force_encoding(loader.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
result
end Deserialize the AST represented by the given string into a parse result.
Source
# File lib/prism/serialize.rb, line 51 def self.load_tokens(source, serialized) Loader.new(source, serialized).load_tokens_result end
Deserialize the tokens represented by the given string into a parse result.
Ruby Core © 1993–2024 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.