class Dentaku::AST::Identifier

Attributes

case_sensitive[R]
identifier[R]

Public Class Methods

new(token, options = {}) click to toggle source
# 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

Public Instance Methods

accept(visitor) click to toggle source
# File lib/dentaku/ast/identifier.rb, line 37
def accept(visitor)
  visitor.visit_identifier(self)
end
dependencies(context = {}) click to toggle source
# File lib/dentaku/ast/identifier.rb, line 33
def dependencies(context = {})
  context.key?(identifier) ? dependencies_of(context[identifier], context) : [identifier]
end
to_s() click to toggle source
# File lib/dentaku/ast/identifier.rb, line 41
def to_s
  identifier.to_s
end
value(context = {}) click to toggle source
# 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

Private Instance Methods

dependencies_of(node, context) click to toggle source
# File lib/dentaku/ast/identifier.rb, line 47
def dependencies_of(node, context)
  node.respond_to?(:dependencies) ? node.dependencies(context) : []
end