8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/evilution/ast/parser.rb', line 8
def call(file_path)
raise 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 ParseError.new("cannot read #{file_path}: #{e.message}", file: file_path)
end
result = Prism.parse(source)
raise ParseError.new("failed to parse #{file_path}: #{result.errors.map(&:message).join(", ")}", file: file_path) if result.failure?
(result.value, source, file_path)
end
|