class Yadriggy::HashLiteral

Hash table.

Attributes

pairs[R]

Returns the elements in the hash table. @return [Array<Array<ASTnode>>] the hash elements.

Each element is a key-value pair.
For example, if the source code is
`{key1 => value1, key2 => value2}`,
then `[[key1, value2], [key2, value2]]` is returned.

Public Class Methods

new(sexp) click to toggle source
# File lib/yadriggy/ast.rb, line 762
def initialize(sexp)
  if sexp[0] == :hash && sexp[1]
    list = has_tag?(sexp[1], :assoclist_from_args)[1]
  else
    list = sexp[1]
  end
  if list.nil?
    @pairs = []
  else
    @pairs = list.map do |e|
      has_tag?(e, :assoc_new)
      [to_node(e[1]), to_node(e[2])]
    end
  end
  @pairs.map do |p|
    add_child(p[0])
    add_child(p[1])
  end
end
tags() click to toggle source
# File lib/yadriggy/ast.rb, line 760
def self.tags() [:hash, :bare_assoc_hash] end

Public Instance Methods

accept(evaluator) click to toggle source

A method for Visitor pattern. @param [Eval] evaluator the visitor of Visitor pattern. @return [void]

# File lib/yadriggy/ast.rb, line 785
def accept(evaluator)
  evaluator.hash(self)
end