class Prism::Translation::RubyParser
此模块是将在 prism 语法树转换为 seattlerb/ruby_parser gem 的语法树的入口点。
Public Class Methods
Source
# File lib/prism/translation/ruby_parser.rb, line 1938 def parse(source, filepath = "(string)") new.parse(source, filepath) end
解析给定的源代码,并将其翻译为 seattlerb/ruby_parser gem 的 Sexp 格式。
Source
# File lib/prism/translation/ruby_parser.rb, line 1944 def parse_file(filepath) new.parse_file(filepath) end
解析给定的文件,并将其翻译为 seattlerb/ruby_parser gem 的 Sexp 格式。
Public Instance Methods
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
解析给定的源代码,并将其翻译为 seattlerb/ruby_parser gem 的 Sexp 格式。
Source
# File lib/prism/translation/ruby_parser.rb, line 1923 def parse_file(filepath) translate(Prism.parse_file(filepath, partial_script: true), filepath) end
解析给定的文件,并将其翻译为 seattlerb/ruby_parser gem 的 Sexp 格式。
Source
# File lib/prism/translation/ruby_parser.rb, line 1931 def process(ruby, file = "(string)", timeout = nil) Timeout.timeout(timeout) { parse(ruby, file) } end
解析给定的文件,并将其翻译为 seattlerb/ruby_parser gem 的 Sexp 格式。此方法为与 RubyParser 的 API 兼容性而提供,并接受一个可选的 timeout 参数。
私有实例方法
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
将给定的解析结果和文件路径翻译为 seattlerb/ruby_parser gem 的 Sexp 格式。