Class: Metrocot::OneOrMorePattern
Overview
matches one or more occurences of some other pattern
Instance Attribute Summary
Attributes inherited from BasePattern
#matched, #metrocot, #name, #node_scraper, #pattern_no, #pred, #source, #succ
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BasePattern
#default_scanner, #dump_match_map, #log, #log_match_data, #optional, #with_scanned_match_data
Constructor Details
Returns a new instance of OneOrMorePattern.
431
432
433
434
|
# File 'lib/metrocot.rb', line 431
def initialize(repeatee)
super( nil )
@repeatee = repeatee
end
|
Class Method Details
.parse(s) ⇒ Object
437
438
439
|
# File 'lib/metrocot.rb', line 437
def self.parse(s)
raise "not implemented"
end
|
Instance Method Details
#consume_remaining_matches(match_range, match_map, matches) ⇒ Object
463
464
465
466
467
468
469
470
471
472
473
|
# File 'lib/metrocot.rb', line 463
def consume_remaining_matches( match_range, match_map, matches )
log("consuming remaining matches in #{match_range}")
@repeatee.each_match( match_range, match_map ) { |r_match_range, r_match_map|
matches << r_match_range.hnodes[r_match_range.start_index ... r_match_range.end_index]
last_match_range = consume_remaining_matches( match_range.tail( r_match_range.end_index, r_match_range.end_offset ), match_map, matches )
return last_match_range || r_match_range
}
return nil
end
|
#description ⇒ Object
447
448
449
|
# File 'lib/metrocot.rb', line 447
def description
"one+ ##{pattern_no}"
end
|
#dump(level, out) ⇒ Object
452
453
454
455
|
# File 'lib/metrocot.rb', line 452
def dump( level, out )
out << " " * level + "one or more p=#{priority}\n"
@repeatee.dump( level + 1, out )
end
|
#each_match(match_range, match_map) ⇒ Object
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
|
# File 'lib/metrocot.rb', line 476
def each_match( match_range, match_map )
super(match_range, match_map)
log("looking for first match in #{match_range}")
@repeatee.each_match( match_range, match_map ) { |first_match_range, first_match_map|
results = []
last_match_range = consume_remaining_matches( match_range.tail( first_match_range.end_index, first_match_range.end_offset ), match_map, results )
combined_match_range = if last_match_range
match_range.crop(
first_match_range.start_index, first_match_range.start_offset,
last_match_range.end_index, last_match_range.end_offset
)
else
first_match_range
end
log("combined match in #{combined_match_range}")
result = with_scanned_match_data( match_map, results ) { |match_map|
yield( combined_match_range, results )
}
if result
log("one+ match done with #{result}")
return result
else
log("one+ match not done")
end
}
return nil
end
|
#priority ⇒ Object
458
459
460
|
# File 'lib/metrocot.rb', line 458
def priority
@repeatee.priority
end
|
#repeatee ⇒ Object
442
443
444
|
# File 'lib/metrocot.rb', line 442
def repeatee
@repeatee
end
|