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)")
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.
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.
Class Method Details
.parse(source, filepath = "(string)")
Parse the given source and translate it into the seattlerb/ruby_parser gem’s Sexp format.
# File 'lib/prism/translation/ruby_parser.rb', line 1933
def parse(source, filepath = "(string)") new.parse(source, filepath) end
.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 1939
def parse_file(filepath) new.parse_file(filepath) end
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 1918
def parse_file(filepath) translate(Prism.parse_file(filepath, partial_script: true), 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 1926
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 1948
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(Compiler.new(filepath)) end