Class: MetaParse::SequentialMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/meta_parse.rb

Overview

Matcher subclass matching submatches sequentially.

Instance Attribute Summary collapse

Attributes inherited from Matcher

#spec

Instance Method Summary collapse

Methods inherited from Matcher

compile, #initialize, #inspect, #m, #m?, #match

Constructor Details

This class inherits a constructor from MetaParse::Matcher

Instance Attribute Details

#matchesObject

Returns the value of attribute matches.



342
343
344
# File 'lib/meta_parse.rb', line 342

def matches
  @matches
end

Instance Method Details

#clearObject

Reset result stack (@matches) to be empty.



388
389
390
# File 'lib/meta_parse.rb', line 388

def clear
  @matches = []
end

#match?(scanner, context = nil) ⇒ Boolean

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

Returns:

  • (Boolean)


355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# 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

#popObject

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



374
375
376
# File 'lib/meta_parse.rb', line 374

def pop
  @matches.pop
end

#push(value) ⇒ Object

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



381
382
383
# File 'lib/meta_parse.rb', line 381

def push(value)
  @matches.push(value)
end

#showObject



392
393
394
# File 'lib/meta_parse.rb', line 392

def show
  "sequentially: (#{ (spec.map &:show).join ', ' })"
end

#statefulObject

SequentialMatcher is stateful.



348
349
350
# File 'lib/meta_parse.rb', line 348

def stateful
  true
end