~singpolyma/dhall-ruby

ref: df3138fd2e83f0ba079b91fe923cdeab2c319281 dhall-ruby/lib/dhall.rb -rw-r--r-- 764 bytes
df3138fdStephen Paul Weber Update text-or-binary heuristic 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
32
33
34
35
36
37
# frozen_string_literal: true

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

module Dhall
	using Dhall::AsDhall

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

	def self.load_raw(source)
		source = Util.text_or_binary(source)

		if source.encoding == Encoding::BINARY
			from_binary(source)
		else
			Parser.parse(source).value
		end
	end

	def self.dump(o)
		CBOR.encode(o.as_dhall)
	end
end