diff options
Diffstat (limited to 'prism/templates')
-rw-r--r-- | prism/templates/lib/prism/serialize.rb.erb | 15 | ||||
-rw-r--r-- | prism/templates/src/serialize.c.erb | 14 |
2 files changed, 21 insertions, 8 deletions
diff --git a/prism/templates/lib/prism/serialize.rb.erb b/prism/templates/lib/prism/serialize.rb.erb index 058142682e..681b6117b4 100644 --- a/prism/templates/lib/prism/serialize.rb.erb +++ b/prism/templates/lib/prism/serialize.rb.erb @@ -95,9 +95,10 @@ module Prism def load_metadata comments = load_comments magic_comments = load_varint.times.map { MagicComment.new(load_location, load_location) } + data_loc = load_optional_location errors = load_varint.times.map { ParseError.new(load_embedded_string, load_location) } warnings = load_varint.times.map { ParseWarning.new(load_embedded_string, load_location) } - [comments, magic_comments, errors, warnings] + [comments, magic_comments, data_loc, errors, warnings] end def load_tokens @@ -117,11 +118,11 @@ module Prism tokens = load_tokens encoding = load_encoding load_start_line - comments, magic_comments, errors, warnings = load_metadata + comments, magic_comments, data_loc, errors, warnings = load_metadata 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, errors, warnings, @source) + Prism::ParseResult.new(tokens, comments, magic_comments, data_loc, errors, warnings, @source) end def load_nodes @@ -129,17 +130,17 @@ module Prism load_encoding load_start_line - comments, magic_comments, errors, warnings = load_metadata + comments, magic_comments, data_loc, errors, warnings = load_metadata @constant_pool_offset = io.read(4).unpack1("L") @constant_pool = Array.new(load_varint, nil) - [load_node, comments, magic_comments, errors, warnings] + [load_node, comments, magic_comments, data_loc, errors, warnings] end def load_result - node, comments, magic_comments, errors, warnings = load_nodes - Prism::ParseResult.new(node, comments, magic_comments, errors, warnings, @source) + node, comments, magic_comments, data_loc, errors, warnings = load_nodes + Prism::ParseResult.new(node, comments, magic_comments, data_loc, errors, warnings, @source) end private diff --git a/prism/templates/src/serialize.c.erb b/prism/templates/src/serialize.c.erb index db4c91e0cd..0ea70a3976 100644 --- a/prism/templates/src/serialize.c.erb +++ b/prism/templates/src/serialize.c.erb @@ -15,7 +15,7 @@ pm_sizet_to_u32(size_t value) { } static void -pm_serialize_location(pm_parser_t *parser, pm_location_t *location, pm_buffer_t *buffer) { +pm_serialize_location(const pm_parser_t *parser, const pm_location_t *location, pm_buffer_t *buffer) { assert(location->start); assert(location->end); assert(location->start <= location->end); @@ -171,6 +171,16 @@ pm_serialize_magic_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_ } static void +pm_serialize_data_loc(const pm_parser_t *parser, pm_buffer_t *buffer) { + if (parser->data_loc.end == NULL) { + pm_buffer_append_byte(buffer, 0); + } else { + pm_buffer_append_byte(buffer, 1); + pm_serialize_location(parser, &parser->data_loc, buffer); + } +} + +static void pm_serialize_diagnostic(pm_parser_t *parser, pm_diagnostic_t *diagnostic, pm_buffer_t *buffer) { // serialize message size_t message_length = strlen(diagnostic->message); @@ -214,6 +224,7 @@ pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) pm_serialize_comment_list(parser, &parser->comment_list, buffer); <%- end -%> pm_serialize_magic_comment_list(parser, &parser->magic_comment_list, buffer); + pm_serialize_data_loc(parser, buffer); pm_serialize_diagnostic_list(parser, &parser->error_list, buffer); pm_serialize_diagnostic_list(parser, &parser->warning_list, buffer); @@ -310,6 +321,7 @@ pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const pm_buffer_append_varint(buffer, parser.start_line); pm_serialize_comment_list(&parser, &parser.comment_list, buffer); pm_serialize_magic_comment_list(&parser, &parser.magic_comment_list, buffer); + pm_serialize_data_loc(&parser, buffer); pm_serialize_diagnostic_list(&parser, &parser.error_list, buffer); pm_serialize_diagnostic_list(&parser, &parser.warning_list, buffer); |