diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-11-27 14:17:02 -0500 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-11-28 13:25:48 +0000 |
commit | c798943a4a272f213d21295a837da06ed5fa9a51 (patch) | |
tree | 618a074700e2d501beec4db66320e2e1f5a6f085 /lib/prism/parse_result.rb | |
parent | 43dc8e9012dd7c390f1299d1b653656c81ae2aa7 (diff) | |
download | ruby-c798943a4a272f213d21295a837da06ed5fa9a51.tar.gz |
[ruby/prism] Move DATA parsing into its own parse result field
https://github.com/ruby/prism/commit/42b60b6e95
Diffstat (limited to 'lib/prism/parse_result.rb')
-rw-r--r-- | lib/prism/parse_result.rb | 27 |
1 files changed, 12 insertions, 15 deletions
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 |