Class: Prism::Translation::RubyParser
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Inherits: | Object |
| Defined in: | lib/prism/translation/ruby_parser.rb |
Overview
This module is the entry-point for converting a prism syntax tree into the seattlerb/ruby_parser gem's syntax tree.
Class Method Summary
-
.parse(source, filepath = "(string)", scopes: nil)
Parse the given source and translate it into the seattlerb/ruby_parser gem's Sexp format.
-
.parse_file(filepath, scopes: nil)
Parse the given file and translate it into the seattlerb/ruby_parser gem's Sexp format.
-
.new(scopes: nil) ⇒ RubyParser
constructor
Internal use only
: (?scopes: Array[Array[Symbol]]?) -> void.
Instance Attribute Summary
-
#scopes
readonly
Optional scopes to pass to the parser.
Instance Method Summary
-
#parse(source, filepath = "(string)")
Parse the given source and translate it into the seattlerb/ruby_parser gem's Sexp format.
-
#parse_file(filepath)
Parse the given file and translate it into the seattlerb/ruby_parser gem's Sexp format.
-
#process(ruby, file = "(string)", timeout = nil)
Parse the give file and translate it into the seattlerb/ruby_parser gem's Sexp format.
-
#translate(result, filepath)
private
Translate the given parse result and filepath into the seattlerb/ruby_parser gem's Sexp format.
Constructor Details
.new(scopes: nil) ⇒ RubyParser
: (?scopes: Array[Array[Symbol]]?) -> void
# File 'lib/prism/translation/ruby_parser.rb', line 1632
def initialize(scopes: nil) super() @scopes = scopes end
Class Method Details
.parse(source, filepath = "(string)", scopes: nil)
Parse the given source and translate it into the seattlerb/ruby_parser gem's Sexp format.
.parse_file(filepath, scopes: nil)
Parse the given file and translate it into the seattlerb/ruby_parser gem's Sexp format.
Instance Attribute Details
#scopes (readonly)
Optional scopes to pass to the parser.
# File 'lib/prism/translation/ruby_parser.rb', line 1628
attr_reader :scopes #: Array[Array[Symbol]]?
Instance Method Details
#parse(source, filepath = "(string)")
Parse the given source and translate it into the seattlerb/ruby_parser gem's Sexp format.
#parse_file(filepath)
Parse the given file and translate it into the seattlerb/ruby_parser gem's Sexp format.
# File 'lib/prism/translation/ruby_parser.rb', line 1645
def parse_file(filepath) translate(Prism.parse_file(filepath, partial_script: true, scopes: scopes), filepath) end
#process(ruby, file = "(string)", timeout = nil)
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.
# File 'lib/prism/translation/ruby_parser.rb', line 1653
def process(ruby, file = "(string)", timeout = nil) Timeout.timeout(timeout) { parse(ruby, file) } end
#translate(result, filepath) (private)
Translate the given parse result and filepath into the seattlerb/ruby_parser gem's Sexp format.
# File 'lib/prism/translation/ruby_parser.rb', line 1675
def translate(result, filepath) if result.failure? error = result.errors.first raise ::RubyParser::SyntaxError, "#{filepath}:#{error.location.start_line} :: #{error.}" end result.attach_comments! result.value.accept(self.class::Compiler.new(filepath)) end