diff options
Diffstat (limited to 'lib/prism')
-rw-r--r-- | lib/prism/ffi.rb | 4 | ||||
-rw-r--r-- | lib/prism/lex_compat.rb | 2 | ||||
-rw-r--r-- | lib/prism/parse_result.rb | 27 |
3 files changed, 15 insertions, 18 deletions
diff --git a/lib/prism/ffi.rb b/lib/prism/ffi.rb index 847990ed9a..36f1c398de 100644 --- a/lib/prism/ffi.rb +++ b/lib/prism/ffi.rb @@ -254,10 +254,10 @@ module Prism loader = Serialize::Loader.new(source, buffer.read) tokens = loader.load_tokens - node, comments, magic_comments, errors, warnings = loader.load_nodes + node, comments, magic_comments, data_loc, errors, warnings = loader.load_nodes tokens.each { |token,| token.value.force_encoding(loader.encoding) } - ParseResult.new([node, tokens], comments, magic_comments, errors, warnings, source) + ParseResult.new([node, tokens], comments, magic_comments, data_loc, errors, warnings, source) end end diff --git a/lib/prism/lex_compat.rb b/lib/prism/lex_compat.rb index b6d12053a0..66be275bcd 100644 --- a/lib/prism/lex_compat.rb +++ b/lib/prism/lex_compat.rb @@ -831,7 +831,7 @@ module Prism # We sort by location to compare against Ripper's output tokens.sort_by!(&:location) - ParseResult.new(tokens, result.comments, result.magic_comments, result.errors, result.warnings, []) + ParseResult.new(tokens, result.comments, result.magic_comments, result.data_loc, result.errors, result.warnings, []) end end diff --git a/lib/prism/parse_result.rb b/lib/prism/parse_result.rb index 50c23bce65..753d72f10b 100644 --- a/lib/prism/parse_result.rb +++ b/lib/prism/parse_result.rb @@ -238,11 +238,6 @@ module Prism def deconstruct_keys(keys) { location: location } end - - # This can only be true for inline comments. - def trailing? - false - end end # InlineComment objects are the most common. They correspond to comments in @@ -263,18 +258,14 @@ module Prism # EmbDocComment objects correspond to comments that are surrounded by =begin # and =end. class EmbDocComment < Comment - # Returns a string representation of this comment. - def inspect - "#<Prism::EmbDocComment @location=#{location.inspect}>" + # This can only be true for inline comments. + def trailing? + false end - end - # DATAComment objects correspond to comments that are after the __END__ - # keyword in a source file. - class DATAComment < Comment # Returns a string representation of this comment. def inspect - "#<Prism::DATAComment @location=#{location.inspect}>" + "#<Prism::EmbDocComment @location=#{location.inspect}>" end end @@ -378,6 +369,11 @@ module Prism # The list of magic comments that were encountered during parsing. attr_reader :magic_comments + # An optional location that represents the location of the content after the + # __END__ marker. This content is loaded into the DATA constant when the + # file being parsed is the main file being executed. + attr_reader :data_loc + # The list of errors that were generated during parsing. attr_reader :errors @@ -388,10 +384,11 @@ module Prism attr_reader :source # Create a new parse result object with the given values. - def initialize(value, comments, magic_comments, errors, warnings, source) + def initialize(value, comments, magic_comments, data_loc, errors, warnings, source) @value = value @comments = comments @magic_comments = magic_comments + @data_loc = data_loc @errors = errors @warnings = warnings @source = source @@ -399,7 +396,7 @@ module Prism # Implement the hash pattern matching interface for ParseResult. def deconstruct_keys(keys) - { value: value, comments: comments, magic_comments: magic_comments, errors: errors, warnings: warnings } + { value: value, comments: comments, magic_comments: magic_comments, data_loc: data_loc, errors: errors, warnings: warnings } end # Returns true if there were no errors during parsing and false if there |