Module: LIT::Parser
- Defined in:
- lib/lit/parser.rb,
lib/lit/parser/ast.rb,
lib/lit/parser/errors.rb,
lib/lit/parser/version.rb,
lib/lit/parser/ast_builder.rb
Overview
Defined Under Namespace
Modules: AST
Classes: ASTBuilder, ParseError
Constant Summary
collapse
- InvalidASTError =
Class.new(::StandardError)
- VERSION =
"0.1.1"
Class Method Summary
collapse
Class Method Details
31
32
33
|
# File 'lib/lit/parser.rb', line 31
def format_error(file_path, error)
__format_error_internal(file_path.to_s, error)
end
|
.parse_file(path) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/lit/parser.rb', line 17
def parse_file(path)
source_code = File.read(path)
result = JSON.parse(__parse_internal(source_code))
if result.fetch("type") == "parse_error"
error_data = result.fetch("data")
error_message = format_error(path, JSON.dump(error_data))
raise ParseError.new(data: error_data, message: error_message)
else
ASTBuilder.new(result.fetch("data")).build
end
end
|