class Prism::Translation::RubyParser - Documentation for Ruby 4.0
Description: class Prism::Translation::RubyParser: ruby_parser gem's syntax tree.
Keywords: ruby,class,Prism::Translation::RubyParser

🔍

No recent searches

# 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)")
Source

    # File lib/prism/translation/ruby_parser.rb, line 1938
    def parse(source, filepath = "(string)")
      new.parse(source, filepath)
    end

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

parse_file (filepath)
Source

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

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

### Public Instance Methods

parse (source, filepath = "(string)")
Source

    # File lib/prism/translation/ruby_parser.rb, line 1917
    def parse(source, filepath = "(string)")
      translate(Prism.parse(source, filepath: filepath, partial_script: true), filepath)
    end

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

parse_file (filepath)
Source

    # File lib/prism/translation/ruby_parser.rb, line 1923
    def parse_file(filepath)
      translate(Prism.parse_file(filepath, partial_script: true), filepath)
    end

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

process (ruby, file = "(string)", timeout = nil)
Source

    # File lib/prism/translation/ruby_parser.rb, line 1931
    def process(ruby, file = "(string)", timeout = nil)
      Timeout.timeout(timeout) { parse(ruby, file) }
    end

Parse the give file and translate it into the seattlerb/ruby_parser gem’s Sexp format. This method is provided for API compatibility to `RubyParser` and takes an optional `timeout` argument.

### Private Instance Methods

translate (result, filepath)
Source

    # File lib/prism/translation/ruby_parser.rb, line 1953
    def translate(result, filepath)
      if result.failure?
        error = result.errors.first
        raise ::RubyParser::SyntaxError, "#{filepath}:#{error.location.start_line} :: #{error.message}"
      end

      result.attach_comments!
      result.value.accept(Compiler.new(filepath))
    end

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