Class: MetaParse::SequentialMatcher
- Defined in:
- lib/meta_parse.rb
Overview
Matcher subclass matching submatches sequentially.
Instance Attribute Summary collapse
-
#matches ⇒ Object
Returns the value of attribute matches.
Attributes inherited from Matcher
Instance Method Summary collapse
-
#clear ⇒ Object
Reset result stack (@matches) to be empty.
-
#match?(scanner, context = nil) ⇒ Boolean
Match submatch patterns against scanner sequentially, accumulating results in @matches.
-
#pop ⇒ Object
Remove most recent sequential match from result stack (@matches), returning it (pop).
-
#push(value) ⇒ Object
Add (push) value to result stack (@matches).
- #show ⇒ Object
-
#stateful ⇒ Object
SequentialMatcher is stateful.
Methods inherited from Matcher
compile, #initialize, #inspect, #m, #m?, #match
Constructor Details
This class inherits a constructor from MetaParse::Matcher
Instance Attribute Details
#matches ⇒ Object
Returns the value of attribute matches.
342 343 344 |
# File 'lib/meta_parse.rb', line 342 def matches @matches end |
Instance Method Details
#clear ⇒ Object
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.
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 |
#pop ⇒ Object
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 |
#show ⇒ Object
392 393 394 |
# File 'lib/meta_parse.rb', line 392 def show "sequentially: (#{ (spec.map &:show).join ', ' })" end |
#stateful ⇒ Object
SequentialMatcher is stateful.
348 349 350 |
# File 'lib/meta_parse.rb', line 348 def stateful true end |