Class: Emfrp::Syntax

Inherits:
Hash
  • Object
show all
Defined in:
lib/emfrp/syntax.rb

Direct Known Subclasses

Pattern, SSymbol, Top

Instance Method Summary collapse

Constructor Details

#initialize(hash, hash2 = {}) ⇒ Syntax

Returns a new instance of Syntax.



3
4
5
6
7
8
# File 'lib/emfrp/syntax.rb', line 3

def initialize(hash, hash2 = {})
  self[:class] = self.class
  self.merge!(hash)
  self.merge!(hash2)
  self[:class] = self.class
end

Instance Method Details

#[](key) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/emfrp/syntax.rb', line 10

def [](key)
  if self.has_key?(key)
    self.fetch(key)
  else
    pp self
    raise "unexist key #{key}"
  end
end

#deep_copy(x = self) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/emfrp/syntax.rb', line 29

def deep_copy(x=self)
  case x
  when Syntax
    x.class.new(Hash[x.map{|k, v| [k, deep_copy(v)]}])
  when Array
    x.map{|x| deep_copy(x)}
  else
    x
  end
end

#traverse_all_syntax(target = self, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/emfrp/syntax.rb', line 19

def traverse_all_syntax(target=self, &block)
  case target
  when Syntax
    block.call(target)
    traverse_all_syntax(target.values, &block)
  when Array
    target.each{|e| traverse_all_syntax(e, &block)}
  end
end