class Analyst::Parser
Attributes
root[R]
Public Class Methods
for_files(*path_to_files)
click to toggle source
# File lib/analyst/parser.rb, line 10 def self.for_files(*path_to_files) file_paths = path_to_files.flatten.map do |path| if File.directory?(path) Dir.glob(File.join(path, "**", "*.rb")) else path end end.flatten asts = file_paths.map do |path| File.open(path) do |file| parse_source(file.read, path) end end.compact new(asts) end
for_source(source)
click to toggle source
# File lib/analyst/parser.rb, line 28 def self.for_source(source) ast = parse_source(source) new([ast].compact) end
new(asts)
click to toggle source
# File lib/analyst/parser.rb, line 52 def initialize(asts) root_node = ::Parser::AST::Node.new(:analyst_root, asts) @root = Processor.process_node(root_node, nil) end
Private Class Methods
format_diagnostic_msg(diagnostic)
click to toggle source
# File lib/analyst/parser.rb, line 47 def self.format_diagnostic_msg(diagnostic) diagnostic.render.map { |line| " #{line}" }.join("\n") end
parse_source(source, filename='(string)')
click to toggle source
# File lib/analyst/parser.rb, line 33 def self.parse_source(source, filename='(string)') parser = ::Parser::CurrentRuby.new parser.diagnostics.all_errors_are_fatal = true parser.diagnostics.ignore_warnings = true buffer = ::Parser::Source::Buffer.new(filename) buffer.source = source parser.parse(buffer) rescue ::Parser::SyntaxError => e $stderr.puts "Error during parsing; #{filename == '(string)' ? 'string' : 'file'} will be skipped:" $stderr.puts format_diagnostic_msg(e.diagnostic) end
Public Instance Methods
inspect()
click to toggle source
# File lib/analyst/parser.rb, line 57 def inspect "\#<#{self.class}:#{object_id}>" end
top_level_entities()
click to toggle source
# File lib/analyst/parser.rb, line 61 def top_level_entities root.contents end