class MetaParse::SequentialMatcher

Matcher subclass matching submatches sequentially.

Attributes

matches[RW]

Public Instance Methods

clear() click to toggle source

Reset result stack (@matches) to be empty.

# File lib/meta_parse.rb, line 388
def clear
  @matches = []
end
match?(scanner, context = nil) click to toggle source

Match submatch patterns against scanner sequentially, accumulating results in @matches.

# File lib/meta_parse.rb, line 355
def match?(scanner, context = nil)
  @matches = []
  initial_position = scanner.pos
  last_match = nil

  spec.each do |element|
    last_match = element.match(scanner, self)
    unless last_match
      scanner.pos = initial_position
      return nil
    end
    @matches << last_match
  end
  return last_match
end
pop() click to toggle source

Remove most recent sequential match from result stack (@matches), returning it (pop).

# File lib/meta_parse.rb, line 374
def pop
  @matches.pop
end
push(value) click to toggle source

Add (push) value to result stack (@matches).

# File lib/meta_parse.rb, line 381
def push(value)
  @matches.push(value)
end
show() click to toggle source
# File lib/meta_parse.rb, line 392
def show
  "sequentially: (#{ (spec.map &:show).join ', ' })"
end
stateful() click to toggle source

SequentialMatcher is stateful.

# File lib/meta_parse.rb, line 348
def stateful
  true
end