Class: Dhall::Expression
- Inherits:
-
Object
show all
- Defined in:
- lib/dhall/ast.rb,
lib/dhall/binary.rb,
lib/dhall/resolve.rb,
lib/dhall/normalize.rb
Direct Known Subclasses
Application, Assertion, Bool, Builtin, Double, EmptyRecord, EmptyRecordProjection, Function, If, Import, Integer, Let, LetIn, List, Merge, Natural, Operator, Optional, Record, RecordProjection, RecordProjectionByExpression, RecordSelection, RecordType, RubyObjectRaw, Text, TextLiteral, ToMap, TypeAnnotation, Union, UnionType, Variable
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.decode(*args) ⇒ Object
25
26
27
28
29
|
# File 'lib/dhall/binary.rb', line 25
def self.decode(*args)
return new(value: args.first) if args.length == 1
new(*args)
end
|
Instance Method Details
#&(other) ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/dhall/ast.rb', line 50
def &(other)
if self == other
self
elsif other.is_a?(Bool)
other & self
else
Operator::And.new(lhs: self, rhs: other)
end
end
|
#*(other) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/dhall/ast.rb', line 38
def *(other)
if other.is_a?(Natural) && other.zero?
other * self
else
Operator::Times.new(lhs: self, rhs: other)
end
end
|
#+(other) ⇒ Object
34
35
36
|
# File 'lib/dhall/ast.rb', line 34
def +(other)
Operator::Plus.new(lhs: self, rhs: other)
end
|
#annotate(type) ⇒ Object
107
108
109
|
# File 'lib/dhall/ast.rb', line 107
def annotate(type)
TypeAnnotation.new(value: self, type: type)
end
|
#as_dhall ⇒ Object
115
116
117
|
# File 'lib/dhall/ast.rb', line 115
def as_dhall
self
end
|
#cache_key ⇒ Object
48
49
50
|
# File 'lib/dhall/binary.rb', line 48
def cache_key
"sha256:#{digest.hexdigest}"
end
|
#call(*args) ⇒ Object
16
17
18
19
20
|
# File 'lib/dhall/ast.rb', line 16
def call(*args)
args.reduce(self) { |f, arg|
Application.new(function: f, argument: arg)
}.normalize
end
|
#concat(other) ⇒ Object
46
47
48
|
# File 'lib/dhall/ast.rb', line 46
def concat(other)
Operator::ListConcatenate.new(lhs: self, rhs: other)
end
|
#deep_merge(other) ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'lib/dhall/ast.rb', line 80
def deep_merge(other)
case other
when EmptyRecord
other.deep_merge(self)
else
Operator::RecursiveRecordMerge.new(lhs: self, rhs: other)
end
end
|
#deep_merge_type(other) ⇒ Object
#dhall_eq(other) ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/dhall/ast.rb', line 70
def dhall_eq(other)
if self == other
Bool.new(value: true)
elsif other == Bool.new(value: true)
other.dhall_eq(self)
else
Operator::Equal.new(lhs: self, rhs: other)
end
end
|
#digest(digest: Digest::SHA2.new(256)) ⇒ Object
44
45
46
|
# File 'lib/dhall/binary.rb', line 44
def digest(digest: Digest::SHA2.new(256))
(digest << normalize.to_cbor).freeze
end
|
#fetch(k) ⇒ Object
26
27
28
|
# File 'lib/dhall/ast.rb', line 26
def fetch(k)
RecordSelection.new(record: self, selector: k)
end
|
#fusion ⇒ Object
55
|
# File 'lib/dhall/normalize.rb', line 55
def fusion(*); end
|
#resolve(resolver: Resolvers::Default.new, relative_to: Import::Path.from_string(Pathname.pwd + "file")) ⇒ Object
524
525
526
527
528
529
530
531
532
533
534
|
# File 'lib/dhall/resolve.rb', line 524
def resolve(
resolver: Resolvers::Default.new,
relative_to: Import::Path.from_string(Pathname.pwd + "file")
)
p = ExpressionResolver.for(self).resolve(
resolver: resolver,
relative_to: relative_to
)
resolver.finish!
p
end
|
#shift(amount, name, min_index) ⇒ Object
43
44
45
46
47
|
# File 'lib/dhall/normalize.rb', line 43
def shift(amount, name, min_index)
with(ExpressionVisitor.new { |expr|
expr.shift(amount, name, min_index)
}.visit(self))
end
|
#slice(*keys) ⇒ Object
30
31
32
|
# File 'lib/dhall/ast.rb', line 30
def slice(*keys)
RecordProjection.new(record: self, selectors: keys)
end
|
#substitute(var, with_expr) ⇒ Object
49
50
51
52
53
|
# File 'lib/dhall/normalize.rb', line 49
def substitute(var, with_expr)
with(ExpressionVisitor.new { |expr|
expr.substitute(var, with_expr)
}.visit(self))
end
|
#to_binary ⇒ Object
40
41
42
|
# File 'lib/dhall/binary.rb', line 40
def to_binary
CBOR.encode(::CBOR::Tagged.new(55799, self))
end
|
#to_cbor(packer = nil) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/dhall/binary.rb', line 31
def to_cbor(packer=nil)
if packer
packer.write(as_json)
packer
else
CBOR.encode(as_json)
end
end
|
#to_proc ⇒ Object
22
23
24
|
# File 'lib/dhall/ast.rb', line 22
def to_proc
method(:call).to_proc
end
|
#to_s ⇒ Object
111
112
113
|
# File 'lib/dhall/ast.rb', line 111
def to_s
inspect
end
|
#|(other) ⇒ Object
60
61
62
63
64
65
66
67
68
|
# File 'lib/dhall/ast.rb', line 60
def |(other)
if self == other
self
elsif other.is_a?(Bool)
other | self
else
Operator::Or.new(lhs: self, rhs: other)
end
end
|