[ruby/prism] Use the diagnostic types in the ripper translation layer

https://github.com/ruby/prism/commit/a7ab3a41c8
This commit is contained in:
Kevin Newton 2024-03-06 13:50:28 -05:00
parent 38c2774420
commit 56026edaba

View File

@ -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