dhall 0.1.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +31 -4
- data/bin/dhall-compile +111 -0
- data/bin/json-to-dhall +1 -1
- data/bin/yaml-to-dhall +1 -1
- data/dhall.gemspec +5 -1
- data/lib/dhall.rb +25 -11
- data/lib/dhall/as_dhall.rb +132 -33
- data/lib/dhall/ast.rb +512 -210
- data/lib/dhall/binary.rb +102 -24
- data/lib/dhall/builtins.rb +227 -247
- data/lib/dhall/coder.rb +199 -0
- data/lib/dhall/normalize.rb +93 -48
- data/lib/dhall/parser.citrus +177 -83
- data/lib/dhall/parser.rb +199 -118
- data/lib/dhall/resolve.rb +200 -48
- data/lib/dhall/typecheck.rb +292 -129
- data/lib/dhall/types.rb +19 -0
- data/lib/dhall/util.rb +142 -38
- metadata +63 -4
- data/lib/dhall/visitor.rb +0 -23
data/lib/dhall/types.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dhall/builtins"
|
4
|
+
|
5
|
+
module Dhall
|
6
|
+
module Types
|
7
|
+
def self.MAP_ENTRY(k: Builtins[:Text], v: Builtins[:Text])
|
8
|
+
RecordType.new(
|
9
|
+
record: {
|
10
|
+
"mapKey" => k, "mapValue" => v
|
11
|
+
}
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.MAP(k: Builtins[:Text], v: Builtins[:Text])
|
16
|
+
Builtins[:List].call(MAP_ENTRY(k: k, v: v))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/dhall/util.rb
CHANGED
@@ -1,7 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "promise"
|
4
|
+
require "timeout"
|
5
|
+
|
3
6
|
module Dhall
|
4
7
|
module Util
|
8
|
+
class LazyPromise < Promise
|
9
|
+
def initialize(&block)
|
10
|
+
super
|
11
|
+
@block = block
|
12
|
+
end
|
13
|
+
|
14
|
+
def subscribe(*args)
|
15
|
+
super
|
16
|
+
|
17
|
+
begin
|
18
|
+
fulfill(@block.call)
|
19
|
+
rescue => e
|
20
|
+
reject(e)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
5
25
|
class AllOf
|
6
26
|
def initialize(*validators)
|
7
27
|
@validators = validators
|
@@ -61,45 +81,43 @@ module Dhall
|
|
61
81
|
end
|
62
82
|
end
|
63
83
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
"Natural/show",
|
73
|
-
"Integer/toDouble",
|
74
|
-
"Integer/show",
|
75
|
-
"Double/show",
|
76
|
-
"List/build",
|
77
|
-
"List/fold",
|
78
|
-
"List/length",
|
79
|
-
"List/head",
|
80
|
-
"List/last",
|
81
|
-
"List/indexed",
|
82
|
-
"List/reverse",
|
83
|
-
"Optional/fold",
|
84
|
-
"Optional/build",
|
85
|
-
"Text/show",
|
86
|
-
"Bool",
|
87
|
-
"Optional",
|
88
|
-
"Natural",
|
89
|
-
"Integer",
|
90
|
-
"Double",
|
91
|
-
"Text",
|
92
|
-
"List",
|
93
|
-
"True",
|
94
|
-
"False",
|
95
|
-
"None",
|
96
|
-
"Type",
|
97
|
-
"Kind",
|
98
|
-
"Sort"
|
99
|
-
].freeze
|
84
|
+
class Deadline
|
85
|
+
def self.for_timeout(timeout)
|
86
|
+
if timeout.nil? || timeout.to_f.infinite?
|
87
|
+
NoDeadline.new
|
88
|
+
else
|
89
|
+
new(Time.now + timeout)
|
90
|
+
end
|
91
|
+
end
|
100
92
|
|
101
|
-
def
|
102
|
-
|
93
|
+
def initialize(deadline)
|
94
|
+
@deadline = deadline
|
95
|
+
end
|
96
|
+
|
97
|
+
def exceeded?
|
98
|
+
@deadline < Time.now
|
99
|
+
end
|
100
|
+
|
101
|
+
def timeout
|
102
|
+
[0.000000000000001, @deadline - Time.now].max
|
103
|
+
end
|
104
|
+
|
105
|
+
def timeout_block(&block)
|
106
|
+
Timeout.timeout(timeout, TimeoutException, &block)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class NoDeadline
|
111
|
+
def exceeded?
|
112
|
+
false
|
113
|
+
end
|
114
|
+
|
115
|
+
def timeout
|
116
|
+
nil
|
117
|
+
end
|
118
|
+
|
119
|
+
def timeout_block
|
120
|
+
yield
|
103
121
|
end
|
104
122
|
end
|
105
123
|
|
@@ -126,5 +144,91 @@ module Dhall
|
|
126
144
|
end]
|
127
145
|
end
|
128
146
|
end
|
147
|
+
|
148
|
+
def self.psych_coder_for(tag, v)
|
149
|
+
c = Psych::Coder.new(tag)
|
150
|
+
case v
|
151
|
+
when Hash
|
152
|
+
c.map = v
|
153
|
+
when Array
|
154
|
+
c.seq = v
|
155
|
+
else
|
156
|
+
c.scalar = v
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def self.psych_coder_from(tag, o)
|
161
|
+
coder = Psych::Coder.new(tag)
|
162
|
+
|
163
|
+
if o.respond_to?(:encode_with)
|
164
|
+
o.encode_with(coder)
|
165
|
+
else
|
166
|
+
o.instance_variables.each do |ivar|
|
167
|
+
coder[ivar.to_s[1..-1]] = o.instance_variable_get(ivar)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
coder
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.transform_keys(hash_or_not)
|
175
|
+
return hash_or_not unless hash_or_not.is_a?(Hash)
|
176
|
+
|
177
|
+
Hash[hash_or_not.map { |k, v| [(yield k), v] }]
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.utf8_if_possible(str)
|
181
|
+
utf8 = str.dup.force_encoding(Encoding::UTF_8)
|
182
|
+
utf8.valid_encoding? ? utf8 : str
|
183
|
+
end
|
184
|
+
|
185
|
+
def self.text_or_binary(str)
|
186
|
+
unless str.valid_encoding?
|
187
|
+
raise ArgumentError, "invalid byte sequence in #{str.encoding}"
|
188
|
+
end
|
189
|
+
|
190
|
+
if str.encoding == Encoding::BINARY
|
191
|
+
return str if str =~ /(?!\s)[[:cntrl:]]/
|
192
|
+
|
193
|
+
utf8_if_possible(str)
|
194
|
+
else
|
195
|
+
str.encode(Encoding::UTF_8)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def self.longest_common_prefix(a, b)
|
200
|
+
a.zip(b).take_while { |(x, y)| x == y }.map(&:first)
|
201
|
+
end
|
202
|
+
|
203
|
+
def self.indent_size(str)
|
204
|
+
if str.end_with?("\n")
|
205
|
+
0
|
206
|
+
else
|
207
|
+
str
|
208
|
+
.scan(/^[ \t]*(?=[^ \t\n]|\Z)/)
|
209
|
+
.map(&:chars)
|
210
|
+
.reduce(&method(:longest_common_prefix))&.length.to_i
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def self.path_components_to_uri(*components)
|
215
|
+
URI("/#{components.map(&method(:uri_escape)).join("/")}")
|
216
|
+
end
|
217
|
+
|
218
|
+
def self.uri_escape(s)
|
219
|
+
::URI.encode_www_form_component(s).gsub("+", "%20")
|
220
|
+
end
|
221
|
+
|
222
|
+
def self.net_http_req_with_timeout(uri, req, timeout:)
|
223
|
+
Net::HTTP.start(
|
224
|
+
uri.hostname,
|
225
|
+
uri.port,
|
226
|
+
use_ssl: uri.scheme == "https",
|
227
|
+
open_timeout: timeout,
|
228
|
+
ssl_timeout: timeout,
|
229
|
+
read_timeout: timeout,
|
230
|
+
write_timeout: timeout
|
231
|
+
) { |http| http.request(req) }
|
232
|
+
end
|
129
233
|
end
|
130
234
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dhall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Paul Weber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: base32
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.2
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: cbor
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,34 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: lazy_object
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: multihashes
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.3
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.1.3
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: promise.rb
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +122,20 @@ dependencies:
|
|
80
122
|
- - "~>"
|
81
123
|
- !ruby/object:Gem::Version
|
82
124
|
version: 0.0.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: minitest-fail-fast
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.1.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.1.0
|
83
139
|
- !ruby/object:Gem::Dependency
|
84
140
|
name: simplecov
|
85
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,6 +170,7 @@ description: 'This is a Ruby implementation of the Dhall configuration language.
|
|
114
170
|
email:
|
115
171
|
- dev@singpolyma.net
|
116
172
|
executables:
|
173
|
+
- dhall-compile
|
117
174
|
- json-to-dhall
|
118
175
|
- yaml-to-dhall
|
119
176
|
extensions: []
|
@@ -121,6 +178,7 @@ extra_rdoc_files: []
|
|
121
178
|
files:
|
122
179
|
- COPYING
|
123
180
|
- README.md
|
181
|
+
- bin/dhall-compile
|
124
182
|
- bin/json-to-dhall
|
125
183
|
- bin/yaml-to-dhall
|
126
184
|
- dhall.gemspec
|
@@ -129,13 +187,14 @@ files:
|
|
129
187
|
- lib/dhall/ast.rb
|
130
188
|
- lib/dhall/binary.rb
|
131
189
|
- lib/dhall/builtins.rb
|
190
|
+
- lib/dhall/coder.rb
|
132
191
|
- lib/dhall/normalize.rb
|
133
192
|
- lib/dhall/parser.citrus
|
134
193
|
- lib/dhall/parser.rb
|
135
194
|
- lib/dhall/resolve.rb
|
136
195
|
- lib/dhall/typecheck.rb
|
196
|
+
- lib/dhall/types.rb
|
137
197
|
- lib/dhall/util.rb
|
138
|
-
- lib/dhall/visitor.rb
|
139
198
|
homepage: https://git.sr.ht/~singpolyma/dhall-ruby
|
140
199
|
licenses:
|
141
200
|
- GPL-3.0
|
@@ -156,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
215
|
version: '0'
|
157
216
|
requirements: []
|
158
217
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.
|
218
|
+
rubygems_version: 2.7.6.2
|
160
219
|
signing_key:
|
161
220
|
specification_version: 4
|
162
221
|
summary: The non-repetitive alternative to YAML, in Ruby
|
data/lib/dhall/visitor.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dhall
|
4
|
-
class Visitor
|
5
|
-
def initialize(callbacks)
|
6
|
-
@callbacks = callbacks
|
7
|
-
end
|
8
|
-
|
9
|
-
def visit(expr)
|
10
|
-
expr.to_h.each_with_object({}) do |(attr, value), h|
|
11
|
-
if (callback = callback_for(value))
|
12
|
-
h[attr] = callback.call(value)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
protected
|
18
|
-
|
19
|
-
def callback_for(x)
|
20
|
-
@callbacks.find { |k, _| k === x }&.last
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|