class RBI::Parser

Public Class Methods

parse_file(path) click to toggle source
# File lib/rbi/parser.rb, line 36
def self.parse_file(path)
  Parser.new.parse_file(path)
end
parse_string(string) click to toggle source
# File lib/rbi/parser.rb, line 31
def self.parse_string(string)
  Parser.new.parse_string(string)
end

Public Instance Methods

parse_file(path) click to toggle source
# File lib/rbi/parser.rb, line 46
def parse_file(path)
  parse(::File.read(path), file: path)
end
parse_string(string) click to toggle source
# File lib/rbi/parser.rb, line 41
def parse_string(string)
  parse(string, file: "-")
end

Private Instance Methods

parse(content, file:) click to toggle source
# File lib/rbi/parser.rb, line 53
def parse(content, file:)
  node, comments = Unparser.parse_with_comments(content)
  assoc = ::Parser::Source::Comment.associate_locations(node, comments)
  builder = TreeBuilder.new(file: file, comments: assoc)
  builder.separate_header_comments
  builder.visit(node)
  builder.assoc_dangling_comments(comments)
  builder.tree
rescue ::Parser::SyntaxError => e
  raise ParseError.new(e.message, Loc.from_ast_loc(file, e.diagnostic.location))
end