Skip to content

Commit

Permalink
Use the diagnostic types in the ripper translation layer
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Mar 6, 2024
1 parent a735c22 commit a7ab3a4
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions lib/prism/translation/ripper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,18 @@ module Translation
# 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
# * on_lbracket
# * on_lparen
# * on_nl
# * on_op
# * on_operator_ambiguous
# * on_rbrace
# * on_rbracket
# * on_rparen
Expand All @@ -45,7 +41,6 @@ module Translation
# * on_tlambeg
# * on_tstring_beg
# * on_tstring_end
# * on_ignored_sp
#
class Ripper < Compiler
# Parses the given Ruby program read from +src+.
Expand Down Expand Up @@ -502,16 +497,45 @@ def parse
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
Expand Down

0 comments on commit a7ab3a4

Please sign in to comment.