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

Since:

  • 0.1.0

Defined Under Namespace

Modules: AST Classes: ASTBuilder, ParseError

Constant Summary collapse

InvalidASTError =

Since:

  • 0.1.0

Class.new(::StandardError)
VERSION =

Returns:

  • (String)

Since:

  • 0.1.0

"0.1.1"

Class Method Summary collapse

Class Method Details

.format_error(file_path, error) ⇒ Object

Since:

  • 0.1.0



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

Since:

  • 0.1.0



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