Class: Dhall::Variable

Inherits:
Expression show all
Defined in:
lib/dhall/ast.rb,
lib/dhall/normalize.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#&, #*, #+, #annotate, #as_dhall, #cache_key, #call, #concat, decode, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fetch, #fusion, #merge, #normalize, #resolve, #slice, #to_binary, #to_cbor, #to_proc, #|

Class Method Details

.[](name, index = 0) ⇒ Object



327
328
329
# File 'lib/dhall/ast.rb', line 327

def self.[](name, index=0)
	new(name: name, index: index)
end

Instance Method Details

#as_jsonObject



335
336
337
338
339
340
341
# File 'lib/dhall/ast.rb', line 335

def as_json
	if name == "_"
		index
	else
		[name, index]
	end
end

#shift(amount, name, min_index) ⇒ Object

Raises:

  • (TypeError)


149
150
151
152
153
154
155
# File 'lib/dhall/normalize.rb', line 149

def shift(amount, name, min_index)
	return self if self.name != name || min_index > index

	raise TypeError, "free variable" if (index + amount).negative?

	with(index: index + amount)
end

#substitute(var, with_expr) ⇒ Object



157
158
159
# File 'lib/dhall/normalize.rb', line 157

def substitute(var, with_expr)
	self == var ? with_expr : self
end

#to_sObject



331
332
333
# File 'lib/dhall/ast.rb', line 331

def to_s
	"#{name}@#{index}"
end