module Prism

def self.dump(code, filepath = nil)

Mirror the Prism.dump API by using the serialization API.
def self.dump(code, filepath = nil)
  LibRubyParser.dump_internal(code, code.bytesize, filepath)
end

def self.dump_file(filepath)

Mirror the Prism.dump_file API by using the serialization API.
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)

Mirror the Prism.lex API by using the serialization API.
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 = "")

same way, it's going to always return the NONE state.
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)

Mirror the Prism.lex_file API by using the serialization API.
def self.lex_file(filepath)
  LibRubyParser::PrismString.with(filepath) do |string|
    lex(string.read, filepath)
  end
end

def self.lex_ripper(source)

invalid.
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)

Load the serialized AST using the source as a reference into a tree.
def self.load(source, serialized)
  Serialize.load(source, serialized)
end

def self.parse(code, filepath = nil)

Mirror the Prism.parse API by using the serialization API.
def self.parse(code, filepath = nil)
  Prism.load(code, dump(code, filepath))
end

def self.parse_file(filepath)

it is available.
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)

Mirror the Prism.parse_lex API by using the serialization API.
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)

Mirror the Prism.parse_lex_file API by using the serialization API.
def self.parse_lex_file(filepath)
  LibRubyParser::PrismString.with(filepath) do |string|
    parse_lex(string.read, filepath)
  end
end