# frozen_string_literal: true # @api public # @since 0.1.0 module LIT # @api public # @since 0.1.0 module Parser require_relative "parser/version" require_relative "parser/errors" require_relative "parser/ast" require_relative "parser/ast_builder" require_relative "../../ext/lit/parser/lit_parser" require "json" class << self 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 def format_error(file_path, error) __format_error_internal(file_path.to_s, error) end end end end