Class: Prism::Translation::RubyParser

Inherits:
Object
  • Object
show all
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 collapse

Instance Method Summary collapse

Class Method Details

.parse(source, filepath = "(string)") ⇒ Object

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



1938
1939
1940
# File 'lib/prism/translation/ruby_parser.rb', line 1938

def parse(source, filepath = "(string)")
  new.parse(source, filepath)
end

.parse_file(filepath) ⇒ Object

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



1944
1945
1946
# File 'lib/prism/translation/ruby_parser.rb', line 1944

def parse_file(filepath)
  new.parse_file(filepath)
end

Instance Method Details

#parse(source, filepath = "(string)") ⇒ Object

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



1917
1918
1919
# 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_file(filepath) ⇒ Object

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



1923
1924
1925
# File 'lib/prism/translation/ruby_parser.rb', line 1923

def parse_file(filepath)
  translate(Prism.parse_file(filepath, partial_script: true), filepath)
end

#process(ruby, file = "(string)", timeout = nil) ⇒ Object

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.



1931
1932
1933
# File 'lib/prism/translation/ruby_parser.rb', line 1931

def process(ruby, file = "(string)", timeout = nil)
  Timeout.timeout(timeout) { parse(ruby, file) }
end