summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2024-01-24 21:12:31 +0100
committergit <svn-admin@ruby-lang.org>2024-01-26 21:34:34 +0000
commitde135bc247408712a0f630010778af0b405bae1f (patch)
tree185a573d5dcc1a16df3fd60e7978480dbe7d5dcc /lib
parentbcafd28a3e2ec6c35d80c55a5d11c2f8aab6fc8b (diff)
[ruby/prism] Add level to warnings and errors to categorize them
* Fixes https://github.com/ruby/prism/issues/2082 https://github.com/ruby/prism/commit/7a74576357
Diffstat (limited to 'lib')
-rw-r--r--lib/prism/parse_result.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/prism/parse_result.rb b/lib/prism/parse_result.rb
index 556c664019..27e03fe23b 100644
--- a/lib/prism/parse_result.rb
+++ b/lib/prism/parse_result.rb
@@ -312,10 +312,14 @@ module Prism
# A Location object representing the location of this error in the source.
attr_reader :location
+ # The level of this error
+ attr_reader :level
+
# Create a new error object with the given message and location.
- def initialize(message, location)
+ def initialize(message, location, level)
@message = message
@location = location
+ @level = level
end
# Implement the hash pattern matching interface for ParseError.
@@ -325,7 +329,7 @@ module Prism
# Returns a string representation of this error.
def inspect
- "#<Prism::ParseError @message=#{@message.inspect} @location=#{@location.inspect}>"
+ "#<Prism::ParseError @message=#{@message.inspect} @location=#{@location.inspect} @level=#{@level}>"
end
end
@@ -337,20 +341,24 @@ module Prism
# A Location object representing the location of this warning in the source.
attr_reader :location
+ # The level of this warning
+ attr_reader :level
+
# Create a new warning object with the given message and location.
- def initialize(message, location)
+ def initialize(message, location, level)
@message = message
@location = location
+ @level = level
end
# Implement the hash pattern matching interface for ParseWarning.
def deconstruct_keys(keys)
- { message: message, location: location }
+ { message: message, location: location, verbose_only: verbose_only }
end
# Returns a string representation of this warning.
def inspect
- "#<Prism::ParseWarning @message=#{@message.inspect} @location=#{@location.inspect}>"
+ "#<Prism::ParseWarning @message=#{@message.inspect} @location=#{@location.inspect} @level=#{@level}>"
end
end