Sha256: d4993667f13fcefea89070b43ecd610676d95cb541ed2eaf104cd9b9085f40a6

Contents?: true

Size: 725 Bytes

Versions: 5

Compression:

Stored size: 725 Bytes

Contents

require_relative '../exceptions'

module Dentaku
  module AST
    class Identifier < Node
      attr_reader :identifier

      def initialize(token)
        @identifier = token.value.downcase
      end

      def value(context={})
        v = context.fetch(identifier) do
          raise UnboundVariableError.new([identifier])
        end

        case v
        when Node
          v.value(context)
        else
          v
        end
      end

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

      private

      def dependencies_of(node)
        node.respond_to?(:dependencies) ? node.dependencies : []
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dentaku-2.0.11 lib/dentaku/ast/identifier.rb
dentaku-2.0.10 lib/dentaku/ast/identifier.rb
dentaku-2.0.9 lib/dentaku/ast/identifier.rb
dentaku-2.0.8 lib/dentaku/ast/identifier.rb
dentaku-2.0.7 lib/dentaku/ast/identifier.rb