Class: Dentaku::AST::Identifier

Inherits:
Node
  • Object
show all
Includes:
StringCasing
Defined in:
lib/dentaku/ast/identifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StringCasing

#standardize_case

Methods inherited from Node

arity, #name, precedence, resolve_class, #type

Constructor Details

#initialize(token, options = {}) ⇒ Identifier

Returns a new instance of Identifier.



10
11
12
13
# File 'lib/dentaku/ast/identifier.rb', line 10

def initialize(token, options = {})
  @case_sensitive = options.fetch(:case_sensitive, false)
  @identifier = standardize_case(token.value)
end

Instance Attribute Details

#case_sensitiveObject (readonly)

Returns the value of attribute case_sensitive.



8
9
10
# File 'lib/dentaku/ast/identifier.rb', line 8

def case_sensitive
  @case_sensitive
end

#identifierObject (readonly)

Returns the value of attribute identifier.



8
9
10
# File 'lib/dentaku/ast/identifier.rb', line 8

def identifier
  @identifier
end

Instance Method Details

#accept(visitor) ⇒ Object



37
38
39
# File 'lib/dentaku/ast/identifier.rb', line 37

def accept(visitor)
  visitor.visit_identifier(self)
end

#dependencies(context = {}) ⇒ Object



33
34
35
# File 'lib/dentaku/ast/identifier.rb', line 33

def dependencies(context = {})
  context.key?(identifier) ? dependencies_of(context[identifier], context) : [identifier]
end

#to_sObject



41
42
43
# File 'lib/dentaku/ast/identifier.rb', line 41

def to_s
  identifier.to_s
end

#value(context = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dentaku/ast/identifier.rb', line 15

def value(context = {})
  v = context.fetch(identifier) do
    raise UnboundVariableError.new([identifier]),
          "no value provided for variables: #{identifier}"
  end

  case v
  when Node
    value = v.value(context)
    context[identifier] = value if Dentaku.cache_identifier?
    value
  when Proc
    v.call
  else
    v
  end
end