summaryrefslogtreecommitdiff
path: root/lib/prism/translation/ripper.rb
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-03-06 13:50:28 -0500
committerKevin Newton <kddnewton@gmail.com>2024-03-06 21:42:54 -0500
commit56026edabaec6002069084bc41fa89fa1b0b1d96 (patch)
tree62652f1614f305426b6465eb0fbc3c4e786cd347 /lib/prism/translation/ripper.rb
parent38c2774420674fd1c6ef1f12dc641f5cfc6140aa (diff)
[ruby/prism] Use the diagnostic types in the ripper translation layer
https://github.com/ruby/prism/commit/a7ab3a41c8
Diffstat (limited to 'lib/prism/translation/ripper.rb')
-rw-r--r--lib/prism/translation/ripper.rb42
1 files changed, 33 insertions, 9 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb
index b56ca40ea1..75feafc1ff 100644
--- a/lib/prism/translation/ripper.rb
+++ b/lib/prism/translation/ripper.rb
@@ -19,15 +19,10 @@ module Prism
# The main known difference is that we may omit dispatching some events in
# some cases. This impacts the following events:
#
- # * on_alias_error
- # * on_arg_ambiguous
# * on_assign_error
- # * on_class_name_error
- # * on_operator_ambiguous
- # * on_param_error
- #
# * on_comma
# * on_ignored_nl
+ # * on_ignored_sp
# * on_kw
# * on_label_end
# * on_lbrace
@@ -35,6 +30,7 @@ module Prism
# * on_lparen
# * on_nl
# * on_op
+ # * on_operator_ambiguous
# * on_rbrace
# * on_rbracket
# * on_rparen
@@ -45,7 +41,6 @@ module Prism
# * on_tlambeg
# * on_tstring_beg
# * on_tstring_end
- # * on_ignored_sp
#
class Ripper < Compiler
# Parses the given Ruby program read from +src+.
@@ -502,16 +497,45 @@ module Prism
end
result.warnings.each do |warning|
+ bounds(warning.location)
+
if warning.level == :default
warning(warning.message)
else
- warn(warning.message)
+ case warning.type
+ when :ambiguous_first_argument_plus
+ on_arg_ambiguous("+")
+ when :ambiguous_first_argument_minus
+ on_arg_ambiguous("-")
+ when :ambiguous_slash
+ on_arg_ambiguous("/")
+ else
+ warn(warning.message)
+ end
end
end
if error?
result.errors.each do |error|
- on_parse_error(error.message)
+ location = error.location
+ bounds(location)
+
+ case error.type
+ when :alias_argument
+ on_alias_error("can't make alias for the number variables", location.slice)
+ when :argument_formal_class
+ on_param_error("formal argument cannot be a class variable", location.slice)
+ when :argument_format_constant
+ on_param_error("formal argument cannot be a constant", location.slice)
+ when :argument_formal_global
+ on_param_error("formal argument cannot be a global variable", location.slice)
+ when :argument_formal_ivar
+ on_param_error("formal argument cannot be an instance variable", location.slice)
+ when :class_name, :module_name
+ on_class_name_error("class/module name must be CONSTANT", location.slice)
+ else
+ on_parse_error(error.message)
+ end
end
nil