Class: Evilution::AST::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/ast/parser.rb

Instance Method Summary collapse

Instance Method Details

#call(file_path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/evilution/ast/parser.rb', line 7

def call(file_path)
  raise Evilution::ParseError.new("file not found: #{file_path}", file: file_path) unless File.exist?(file_path)

  begin
    source = File.read(file_path)
  rescue SystemCallError => e
    raise Evilution::ParseError.new("cannot read #{file_path}: #{e.message}", file: file_path)
  end
  result = Prism.parse(source)

  if result.failure?
    raise Evilution::ParseError.new("failed to parse #{file_path}: #{result.errors.map(&:message).join(", ")}",
                                    file: file_path)
  end

  extract_subjects(result.value, source, file_path)
end