module Prism
def self.dump(code, filepath = nil)
def self.dump(code, filepath = nil) LibRubyParser.dump_internal(code, code.bytesize, filepath) end
def self.dump_file(filepath)
def self.dump_file(filepath) LibRubyParser::PrismString.with(filepath) do |string| LibRubyParser.dump_internal(string.source, string.length, filepath) end end
def self.lex(code, filepath = nil)
def self.lex(code, filepath = nil) LibRubyParser::PrismBuffer.with do |buffer| LibRubyParser.pm_lex_serialize(code, code.bytesize, filepath, buffer.pointer) Serialize.load_tokens(Source.new(code), buffer.read) end end
def self.lex_compat(source, filepath = "")
The only difference is that since we don't keep track of lexer state in the
Returns an array of tokens that closely resembles that of the Ripper lexer.
def self.lex_compat(source, filepath = "") LexCompat.new(source, filepath).result end
def self.lex_file(filepath)
def self.lex_file(filepath) LibRubyParser::PrismString.with(filepath) do |string| lex(string.read, filepath) end end
def self.lex_ripper(source)
returns the same tokens. Raises SyntaxError if the syntax in source is
This lexes with the Ripper lex. It drops any space events but otherwise
def self.lex_ripper(source) LexRipper.new(source).result end
def self.load(source, serialized)
def self.load(source, serialized) Serialize.load(source, serialized) end
def self.parse(code, filepath = nil)
def self.parse(code, filepath = nil) Prism.load(code, dump(code, filepath)) end
def self.parse_file(filepath)
native strings instead of Ruby strings because it allows us to use mmap when
Mirror the Prism.parse_file API by using the serialization API. This uses
def self.parse_file(filepath) LibRubyParser::PrismString.with(filepath) do |string| parse(string.read, filepath) end end
def self.parse_lex(code, filepath = nil)
def self.parse_lex(code, filepath = nil) LibRubyParser::PrismBuffer.with do |buffer| metadata = [filepath.bytesize, filepath.b, 0].pack("LA*L") if filepath LibRubyParser.pm_parse_lex_serialize(code, code.bytesize, buffer.pointer, metadata) source = Source.new(code) loader = Serialize::Loader.new(source, buffer.read) tokens = loader.load_tokens node, comments, errors, warnings = loader.load_nodes tokens.each { |token,| token.value.force_encoding(loader.encoding) } ParseResult.new([node, tokens], comments, errors, warnings, source) end end
def self.parse_lex_file(filepath)
def self.parse_lex_file(filepath) LibRubyParser::PrismString.with(filepath) do |string| parse_lex(string.read, filepath) end end