Class: PatternMatch::MatchingState
Instance Attribute Summary collapse
-
#atoms ⇒ Object
Returns the value of attribute atoms.
-
#bindings ⇒ Object
Returns the value of attribute bindings.
Instance Method Summary collapse
-
#initialize(pat, tgt) ⇒ MatchingState
constructor
A new instance of MatchingState.
- #process ⇒ Object
- #process_stream(&block) ⇒ Object
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
#atoms ⇒ Object
Returns the value of attribute atoms.
77 78 79 |
# File 'lib/egison/core.rb', line 77 def atoms @atoms end |
#bindings ⇒ Object
Returns the value of attribute bindings.
77 78 79 |
# File 'lib/egison/core.rb', line 77 def bindings @bindings end |
Instance Method Details
#process ⇒ Object
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 |