[ruby/prism] Fix up linting in ripper translation
https://github.com/ruby/prism/commit/5cf5f15ee7
This commit is contained in:
parent
1966b5c8c6
commit
532ddc1745
@ -2943,6 +2943,7 @@ module Prism
|
||||
end
|
||||
end
|
||||
|
||||
# Visit a heredoc node that is representing a string.
|
||||
private def visit_heredoc_string_node(node)
|
||||
bounds(node.opening_loc)
|
||||
on_heredoc_beg(node.opening)
|
||||
@ -2959,6 +2960,7 @@ module Prism
|
||||
result
|
||||
end
|
||||
|
||||
# Visit a heredoc node that is representing an xstring.
|
||||
private def visit_heredoc_x_string_node(node)
|
||||
bounds(node.opening_loc)
|
||||
on_heredoc_beg(node.opening)
|
||||
|
@ -8,6 +8,8 @@ module Prism
|
||||
# This class mirrors the ::Ripper::SexpBuilder subclass of ::Ripper that
|
||||
# returns the arrays of [type, *children].
|
||||
class SexpBuilder < Ripper
|
||||
# :stopdoc:
|
||||
|
||||
attr_reader :error
|
||||
|
||||
private
|
||||
@ -62,12 +64,16 @@ module Prism
|
||||
remove_method :on_parse_error
|
||||
alias on_parse_error on_error
|
||||
alias compile_error on_error
|
||||
|
||||
# :startdoc:
|
||||
end
|
||||
|
||||
# This class mirrors the ::Ripper::SexpBuilderPP subclass of ::Ripper that
|
||||
# returns the same values as ::Ripper::SexpBuilder except with a couple of
|
||||
# niceties that flatten linked lists into arrays.
|
||||
class SexpBuilderPP < SexpBuilder
|
||||
# :stopdoc:
|
||||
|
||||
private
|
||||
|
||||
def on_heredoc_dedent(val, width)
|
||||
@ -111,6 +117,8 @@ module Prism
|
||||
alias_method "on_#{event}", :_dispatch_event_push
|
||||
end
|
||||
end
|
||||
|
||||
# :startdoc:
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# This writes the prism ripper translation into the Ripper constant so that
|
||||
# users can transparently use Ripper without any changes.
|
||||
Ripper = Prism::Translation::Ripper
|
||||
|
@ -6,7 +6,7 @@ module Prism
|
||||
module Translation
|
||||
# This module is the entry-point for converting a prism syntax tree into the
|
||||
# seattlerb/ruby_parser gem's syntax tree.
|
||||
module RubyParser
|
||||
class RubyParser
|
||||
# A prism visitor that builds Sexp objects.
|
||||
class Compiler < ::Prism::Compiler
|
||||
# This is the name of the file that we are compiling. We set it on every
|
||||
@ -1490,31 +1490,43 @@ module Prism
|
||||
|
||||
private_constant :Compiler
|
||||
|
||||
# Parse the given source and translate it into the seattlerb/ruby_parser
|
||||
# gem's Sexp format.
|
||||
def parse(source, filepath = "(string)")
|
||||
translate(Prism.parse(source), filepath)
|
||||
end
|
||||
|
||||
# Parse the given file and translate it into the seattlerb/ruby_parser
|
||||
# gem's Sexp format.
|
||||
def parse_file(filepath)
|
||||
translate(Prism.parse_file(filepath), filepath)
|
||||
end
|
||||
|
||||
class << self
|
||||
# Parse the given source and translate it into the seattlerb/ruby_parser
|
||||
# gem's Sexp format.
|
||||
def parse(source, filepath = "(string)")
|
||||
translate(Prism.parse(source), filepath)
|
||||
new.parse(source, filepath)
|
||||
end
|
||||
|
||||
# Parse the given file and translate it into the seattlerb/ruby_parser
|
||||
# gem's Sexp format.
|
||||
def parse_file(filepath)
|
||||
translate(Prism.parse_file(filepath), filepath)
|
||||
new.parse_file(filepath)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Translate the given parse result and filepath into the
|
||||
# seattlerb/ruby_parser gem's Sexp format.
|
||||
def translate(result, filepath)
|
||||
if result.failure?
|
||||
error = result.errors.first
|
||||
raise ::RubyParser::SyntaxError, "#{filepath}:#{error.location.start_line} :: #{error.message}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Translate the given parse result and filepath into the
|
||||
# seattlerb/ruby_parser gem's Sexp format.
|
||||
def translate(result, filepath)
|
||||
if result.failure?
|
||||
error = result.errors.first
|
||||
raise ::RubyParser::SyntaxError, "#{filepath}:#{error.location.start_line} :: #{error.message}"
|
||||
end
|
||||
|
||||
result.value.accept(Compiler.new(filepath))
|
||||
end
|
||||
result.value.accept(Compiler.new(filepath))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user