summaryrefslogtreecommitdiff
path: root/prism/templates/lib/prism/serialize.rb.erb
diff options
context:
space:
mode:
Diffstat (limited to 'prism/templates/lib/prism/serialize.rb.erb')
-rw-r--r--prism/templates/lib/prism/serialize.rb.erb36
1 files changed, 18 insertions, 18 deletions
diff --git a/prism/templates/lib/prism/serialize.rb.erb b/prism/templates/lib/prism/serialize.rb.erb
index 5920eaa952..62108ec28a 100644
--- a/prism/templates/lib/prism/serialize.rb.erb
+++ b/prism/templates/lib/prism/serialize.rb.erb
@@ -1,16 +1,16 @@
require "stringio"
-require_relative "polyfill/string"
+require_relative "polyfill/unpack1"
module Prism
# A module responsible for deserializing parse results.
module Serialize
# The major version of prism that we are expecting to find in the serialized
# strings.
- MAJOR_VERSION = 0
+ MAJOR_VERSION = 1
# The minor version of prism that we are expecting to find in the serialized
# strings.
- MINOR_VERSION = 26
+ MINOR_VERSION = 0
# The patch version of prism that we are expecting to find in the serialized
# strings.
@@ -19,7 +19,7 @@ module Prism
# Deserialize the AST represented by the given string into a parse result.
def self.load(input, serialized)
input = input.dup
- source = Source.new(input)
+ source = Source.for(input)
loader = Loader.new(source, serialized)
result = loader.load_result
@@ -131,8 +131,8 @@ module Prism
comments = load_comments
magic_comments = Array.new(load_varuint) { MagicComment.new(load_location_object, load_location_object) }
data_loc = load_optional_location_object
- errors = Array.new(load_varuint) { ParseError.new(DIAGNOSTIC_TYPES[load_varuint], load_embedded_string, load_location_object, load_error_level) }
- warnings = Array.new(load_varuint) { ParseWarning.new(DIAGNOSTIC_TYPES[load_varuint], load_embedded_string, load_location_object, load_warning_level) }
+ errors = Array.new(load_varuint) { ParseError.new(DIAGNOSTIC_TYPES.fetch(load_varuint), load_embedded_string, load_location_object, load_error_level) }
+ warnings = Array.new(load_varuint) { ParseWarning.new(DIAGNOSTIC_TYPES.fetch(load_varuint), load_embedded_string, load_location_object, load_warning_level) }
[comments, magic_comments, data_loc, errors, warnings]
end
@@ -143,7 +143,7 @@ module Prism
length = load_varuint
lex_state = load_varuint
location = Location.new(@source, start, length)
- tokens << [Prism::Token.new(source, type, location.slice, location), lex_state]
+ tokens << [Token.new(source, type, location.slice, location), lex_state]
end
tokens
@@ -158,7 +158,7 @@ module Prism
tokens.each { |token,| token.value.force_encoding(encoding) }
raise "Expected to consume all bytes while deserializing" unless @io.eof?
- Prism::ParseResult.new(tokens, comments, magic_comments, data_loc, errors, warnings, @source)
+ LexResult.new(tokens, comments, magic_comments, data_loc, errors, warnings, @source)
end
def load_nodes
@@ -177,7 +177,7 @@ module Prism
def load_result
node, comments, magic_comments, data_loc, errors, warnings = load_nodes
- Prism::ParseResult.new(node, comments, magic_comments, data_loc, errors, warnings, @source)
+ ParseResult.new(node, comments, magic_comments, data_loc, errors, warnings, @source)
end
private
@@ -319,9 +319,10 @@ module Prism
end
end
- if RUBY_ENGINE == 'ruby'
+ if RUBY_ENGINE == "ruby"
def load_node
type = io.getbyte
+ node_id = load_varuint
location = load_location
case type
@@ -330,8 +331,7 @@ module Prism
<%- if node.needs_serialized_length? -%>
load_uint32
<%- end -%>
- <%= node.name %>.new(
- source, <%= (node.fields.map { |field|
+ <%= node.name %>.new(<%= ["source", "node_id", "location", "load_varuint", *node.fields.map { |field|
case field
when Prism::Template::NodeField then "load_node"
when Prism::Template::OptionalNodeField then "load_optional_node"
@@ -343,12 +343,12 @@ module Prism
when Prism::Template::LocationField then "load_location"
when Prism::Template::OptionalLocationField then "load_optional_location"
when Prism::Template::UInt8Field then "io.getbyte"
- when Prism::Template::UInt32Field, Prism::Template::FlagsField then "load_varuint"
+ when Prism::Template::UInt32Field then "load_varuint"
when Prism::Template::IntegerField then "load_integer"
when Prism::Template::DoubleField then "load_double"
else raise
end
- } + ["location"]).join(", ") -%>)
+ }].join(", ") -%>)
<%- end -%>
end
end
@@ -363,12 +363,12 @@ module Prism
nil,
<%- nodes.each do |node| -%>
-> {
+ node_id = load_varuint
location = load_location
<%- if node.needs_serialized_length? -%>
load_uint32
<%- end -%>
- <%= node.name %>.new(
- source, <%= (node.fields.map { |field|
+ <%= node.name %>.new(<%= ["source", "node_id", "location", "load_varuint", *node.fields.map { |field|
case field
when Prism::Template::NodeField then "load_node"
when Prism::Template::OptionalNodeField then "load_optional_node"
@@ -380,12 +380,12 @@ module Prism
when Prism::Template::LocationField then "load_location"
when Prism::Template::OptionalLocationField then "load_optional_location"
when Prism::Template::UInt8Field then "io.getbyte"
- when Prism::Template::UInt32Field, Prism::Template::FlagsField then "load_varuint"
+ when Prism::Template::UInt32Field then "load_varuint"
when Prism::Template::IntegerField then "load_integer"
when Prism::Template::DoubleField then "load_double"
else raise
end
- } + ["location"]).join(", ") -%>)
+ }].join(", ") -%>)
},
<%- end -%>
]