~singpolyma/dhall-ruby

ref: 7274a86b64cd761f0c0c3d0bddb790f2d5aba1fc dhall-ruby/lib/dhall.rb -rw-r--r-- 828 bytes
7274a86bStephen Paul Weber Add Dhall.load 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module Dhall
	def self.load(source, resolver: Resolvers::Default.new)
		Promise.resolve(nil).then {
			load_raw(source).resolve(resolver: resolver)
		}.then do |resolved|
			TypeChecker.for(resolved).annotate(TypeChecker::Context.new).normalize
		end
	end

	def self.load_raw(source)
		begin
			return from_binary(source) if source.encoding == Encoding::BINARY
		rescue Exception # rubocop:disable Lint/RescueException
			# Parsing CBOR failed, so guess this is source text in standard UTF-8
			return load_raw(source.force_encoding("UTF-8"))
		end

		Parser.parse(source.encode("UTF-8")).value
	end
end

require "dhall/as_dhall"
require "dhall/ast"
require "dhall/binary"
require "dhall/builtins"
require "dhall/normalize"
require "dhall/parser"
require "dhall/resolve"
require "dhall/typecheck"