Class: Dhall::Application
- Inherits:
-
Expression
show all
- Defined in:
- lib/dhall/ast.rb,
lib/dhall/binary.rb,
lib/dhall/normalize.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Expression
#&, #*, #+, #annotate, #as_dhall, #cache_key, #call, #concat, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fetch, #fusion, #merge, #resolve, #shift, #slice, #substitute, #to_binary, #to_cbor, #to_proc, #to_s, #|
Class Method Details
.decode(function, *args) ⇒ Object
54
55
56
57
58
59
|
# File 'lib/dhall/binary.rb', line 54
def self.decode(function, *args)
function = Dhall.decode(function)
args.map(&Dhall.method(:decode)).reduce(function) do |f, arg|
self.for(function: f, argument: arg)
end
end
|
.for(function:, argument:) ⇒ Object
126
127
128
129
130
131
132
|
# File 'lib/dhall/ast.rb', line 126
def self.for(function:, argument:)
if function == Builtins[:None]
OptionalNone.new(value_type: argument)
else
new(function: function, argument: argument)
end
end
|
Instance Method Details
#as_json ⇒ Object
147
148
149
150
|
# File 'lib/dhall/ast.rb', line 147
def as_json
function, arguments = flatten
[0, function.as_json, *arguments.map(&:as_json)]
end
|
#flatten ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/dhall/ast.rb', line 134
def flatten
f, args = if function.is_a?(Application)
function.flatten
elsif function.is_a?(BuiltinFunction) &&
(unfilled = function.unfill).is_a?(Application)
unfilled.flatten
else
[function, []]
end
[f, args + [argument]]
end
|
#fuse ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/dhall/normalize.rb', line 74
def fuse
if function.is_a?(Application)
@fuse ||= function.function.fusion(function.argument, argument)
return @fuse if @fuse
end
@fuse ||= function.fusion(argument)
end
|
#normalize ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/dhall/normalize.rb', line 59
def normalize
return fuse.normalize if fuse
normalized = super
return normalized.fuse if normalized.fuse
if normalized.function.is_a?(BuiltinFunction) ||
normalized.function.is_a?(Function) ||
normalized.function.is_a?(RecordSelection)
return normalized.function.call(normalized.argument)
end
normalized
end
|