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, Bool, Builtin, Double, EmptyRecord, EmptyRecordProjection, Function, If, Import, Integer, Let, LetBlock, 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
|
#as_dhall ⇒ Object
111
112
113
|
# File 'lib/dhall/ast.rb', line 111
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
44
|
# File 'lib/dhall/normalize.rb', line 44
def fusion(*); end
|
#normalize ⇒ Object
28
29
30
|
# File 'lib/dhall/normalize.rb', line 28
def normalize
with(ExpressionVisitor.new(&:normalize).visit(self))
end
|
#resolve(resolver: Resolvers::Default.new, relative_to: Import::Path.from_string(Pathname.pwd + "file")) ⇒ Object
521
522
523
524
525
526
527
528
529
530
531
|
# File 'lib/dhall/resolve.rb', line 521
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
32
33
34
35
36
|
# File 'lib/dhall/normalize.rb', line 32
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
38
39
40
41
42
|
# File 'lib/dhall/normalize.rb', line 38
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
107
108
109
|
# File 'lib/dhall/ast.rb', line 107
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
|