class Prism::Translation::RubyParser

This module is the entry-point for converting a prism syntax tree into the seattlerb/ruby_parser gem’s syntax tree.

Public Class Methods

parse(source, filepath = "(string)") click to toggle source

Parse the given source and translate it into the seattlerb/ruby_parser gem’s Sexp format.

# File lib/prism/translation/ruby_parser.rb, line 1551
def parse(source, filepath = "(string)")
  new.parse(source, filepath)
end
parse_file(filepath) click to toggle source

Parse the given file and translate it into the seattlerb/ruby_parser gem’s Sexp format.

# File lib/prism/translation/ruby_parser.rb, line 1557
def parse_file(filepath)
  new.parse_file(filepath)
end

Public Instance Methods

parse(source, filepath = "(string)") click to toggle source

Parse the given source and translate it into the seattlerb/ruby_parser gem’s Sexp format.

# File lib/prism/translation/ruby_parser.rb, line 1538
def parse(source, filepath = "(string)")
  translate(Prism.parse(source, filepath: filepath), filepath)
end
parse_file(filepath) click to toggle source

Parse the given file and translate it into the seattlerb/ruby_parser gem’s Sexp format.

# File lib/prism/translation/ruby_parser.rb, line 1544
def parse_file(filepath)
  translate(Prism.parse_file(filepath), filepath)
end

Private Instance Methods

translate(result, filepath) click to toggle source

Translate the given parse result and filepath into the seattlerb/ruby_parser gem’s Sexp format.

# File lib/prism/translation/ruby_parser.rb, line 1566
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