Class: PatternMatch::MatchingState

Inherits:
Object
  • Object
show all
Defined in:
lib/egison/core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pat, tgt) ⇒ MatchingState

Returns a new instance of MatchingState.



79
80
81
82
# File 'lib/egison/core.rb', line 79

def initialize(pat, tgt)
  @atoms = [[pat, tgt]]
  @bindings = []
end

Instance Attribute Details

#atomsObject

Returns the value of attribute atoms.



77
78
79
# File 'lib/egison/core.rb', line 77

def atoms
  @atoms
end

#bindingsObject

Returns the value of attribute bindings.



77
78
79
# File 'lib/egison/core.rb', line 77

def bindings
  @bindings
end

Instance Method Details

#processObject



84
85
86
87
88
89
90
91
92
93
# File 'lib/egison/core.rb', line 84

def process
  atom = @atoms.shift
  rets = atom.first.match(atom.last, @bindings)
  rets.map do |new_atoms, new_bindings|
    new_state = clone
    new_state.atoms = new_atoms + new_state.atoms
    new_state.bindings += new_bindings
    new_state
  end
end

#process_stream(&block) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/egison/core.rb', line 95

def process_stream(&block)
  return to_enum :process_stream unless block_given?
  atom = @atoms.shift
  atom.first.match_stream(atom.last, @bindings) do |new_atoms, new_bindings|
    new_state = clone
    new_state.atoms = new_atoms + new_state.atoms
    new_state.bindings += new_bindings
    block.(new_state)
  end
end