class Prism::Translation::RubyParser
此模块是将 prism 语法树转换为 seattlerb/ruby_parser gem 的语法树的入口点。
公共类方法
源代码
# File lib/prism/translation/ruby_parser.rb, line 1620 def parse(source, filepath = "(string)") new.parse(source, filepath) end
解析给定的源代码,并将其转换为 seattlerb/ruby_parser gem 的 Sexp 格式。
源代码
# File lib/prism/translation/ruby_parser.rb, line 1626 def parse_file(filepath) new.parse_file(filepath) end
解析给定的文件,并将其转换为 seattlerb/ruby_parser gem 的 Sexp 格式。
公共实例方法
源代码
# File lib/prism/translation/ruby_parser.rb, line 1607 def parse(source, filepath = "(string)") translate(Prism.parse(source, filepath: filepath, partial_script: true), filepath) end
解析给定的源代码,并将其转换为 seattlerb/ruby_parser gem 的 Sexp 格式。
源代码
# File lib/prism/translation/ruby_parser.rb, line 1613 def parse_file(filepath) translate(Prism.parse_file(filepath, partial_script: true), filepath) end
解析给定的文件,并将其转换为 seattlerb/ruby_parser gem 的 Sexp 格式。
私有实例方法
源代码
# File lib/prism/translation/ruby_parser.rb, line 1635 def translate(result, filepath) if result.failure? error = result.errors.first raise ::RubyParser::SyntaxError, "#{filepath}:#{error.location.start_line} :: #{error.message}" end result.value.accept(Compiler.new(filepath)) end
将给定的解析结果和文件路径转换为 seattlerb/ruby_parser gem 的 Sexp 格式。