Class: PatternMatch::MatchingStateStack

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pat, tgt) ⇒ MatchingStateStack

Returns a new instance of MatchingStateStack.



23
24
25
26
# File 'lib/egison/core.rb', line 23

def initialize(pat, tgt)
  @states = [MatchingState.new(pat, tgt)]
  @results = []
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



21
22
23
# File 'lib/egison/core.rb', line 21

def results
  @results
end

#statesObject

Returns the value of attribute states.



20
21
22
# File 'lib/egison/core.rb', line 20

def states
  @states
end

Instance Method Details

#matchObject



28
29
30
31
32
33
# File 'lib/egison/core.rb', line 28

def match
  until @states.empty? do
    process
  end
  @results
end

#processObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/egison/core.rb', line 35

def process
  state = @states.shift
  rets = state.process
  new_states = []
  rets.each do |ret|
    if ret.atoms.empty?
      @results += [ret.bindings]
    else
      new_states += [ret]
    end
  end
  @states = new_states + @states
end