lib/prism/parse_result.rb in prism-0.13.0 vs lib/prism/parse_result.rb in prism-0.14.0

- old
+ new

@@ -115,11 +115,11 @@ def deconstruct_keys(keys) { start_offset: start_offset, end_offset: end_offset } end def pretty_print(q) - q.text("(#{start_line},#{start_column})-(#{end_line},#{end_column}))") + q.text("(#{start_line},#{start_column})-(#{end_line},#{end_column})") end def ==(other) other.is_a?(Location) && other.start_offset == start_offset && @@ -135,11 +135,11 @@ Location.new(source, start_offset, other.end_offset - start_offset) end def self.null - new(0, 0) + new(nil, 0, 0) end end # This represents a comment that was encountered during parsing. class Comment @@ -164,10 +164,36 @@ def inspect "#<Prism::Comment @type=#{@type.inspect} @location=#{@location.inspect}>" end end + # This represents a magic comment that was encountered during parsing. + class MagicComment + attr_reader :key_loc, :value_loc + + def initialize(key_loc, value_loc) + @key_loc = key_loc + @value_loc = value_loc + end + + def key + key_loc.slice + end + + def value + value_loc.slice + end + + def deconstruct_keys(keys) + { key_loc: key_loc, value_loc: value_loc } + end + + def inspect + "#<Prism::MagicComment @key=#{key.inspect} @value=#{value.inspect}>" + end + end + # This represents an error that was encountered during parsing. class ParseError attr_reader :message, :location def initialize(message, location) @@ -204,21 +230,22 @@ # This represents the result of a call to ::parse or ::parse_file. It contains # the AST, any comments that were encounters, and any errors that were # encountered. class ParseResult - attr_reader :value, :comments, :errors, :warnings, :source + attr_reader :value, :comments, :magic_comments, :errors, :warnings, :source - def initialize(value, comments, errors, warnings, source) + def initialize(value, comments, magic_comments, errors, warnings, source) @value = value @comments = comments + @magic_comments = magic_comments @errors = errors @warnings = warnings @source = source end def deconstruct_keys(keys) - { value: value, comments: comments, errors: errors, warnings: warnings } + { value: value, comments: comments, magic_comments: magic_comments, errors: errors, warnings: warnings } end def success? errors.empty? end