From 56026edabaec6002069084bc41fa89fa1b0b1d96 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 6 Mar 2024 13:50:28 -0500 Subject: [PATCH] [ruby/prism] Use the diagnostic types in the ripper translation layer https://github.com/ruby/prism/commit/a7ab3a41c8 --- lib/prism/translation/ripper.rb | 42 ++++++++++++++++++++++++++------- 1 file 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