Class: PatternMatch::PatternSequence

Inherits:
PatternElement show all
Includes:
HasOrderedSubPatterns
Defined in:
lib/pattern-match/core.rb

Defined Under Namespace

Classes: PatternRewind

Instance Attribute Summary

Attributes inherited from Pattern

#next, #parent, #prev

Instance Method Summary collapse

Methods inherited from PatternElement

#quantifier?

Methods inherited from Pattern

#!@, #&, #ancestors, #append, #initialize, #inspect, #quantified?, #quantifier?, #quasibinding, #root, #root?, #to_a, #vars, #|

Constructor Details

This class inherits a constructor from PatternMatch::Pattern

Instance Method Details

#match(vals) ⇒ Object



386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/pattern-match/core.rb', line 386

def match(vals)
  if @next and @next.quantifier?
    repeating_match(vals, @next.longest?) do |rewind|
      if rewind.ntimes < @next.min_k
        next false
      end
      rewind.match(vals)
    end
  else
    with_rewind(make_rewind(1)) do |rewind|
      rewind.match(vals)
    end
  end
end

#validateObject



401
402
403
404
405
# File 'lib/pattern-match/core.rb', line 401

def validate
  super
  raise MalformedPatternError if @subpatterns.empty?
  raise MalformedPatternError unless @parent.kind_of?(HasOrderedSubPatterns)
end