Sha256: 607871cda82a31d3a29a546248a4b041b8eba854bb4e9e0edd80255675abe9b6

Contents?: true

Size: 889 Bytes

Versions: 23

Compression:

Stored size: 889 Bytes

Contents

module Regexp::Expression

  # This is not a subexpression really, but considering it one simplifies
  # the API when it comes to handling the alternatives.
  class Alternation < Regexp::Expression::Subexpression
    def starts_at
      @expressions.first.starts_at
    end

    def <<(exp)
      @expressions.last << exp
    end

    def alternative(exp = nil)
      @expressions << (exp ? exp : Alternative.new(level, set_level, conditional_level))
    end

    def alternatives
      @expressions
    end

    def quantify(token, text, min = nil, max = nil, mode = :greedy)
      alternatives.last.last.quantify(token, text, min, max, mode)
    end

    def to_s(format = :full)
      alternatives.map{|e| e.to_s(format)}.join('|')
    end
  end

  # A sequence of expressions, used by Alternation as one of its alternative.
  class Alternative < Regexp::Expression::Sequence; end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
regexp_parser-0.4.13 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.12 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.11 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.10 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.9 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.8 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.7 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.6 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.5 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.4 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.3 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.2 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.1 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.4.0 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.3.6 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.3.5 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.3.4 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.3.3 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.3.2 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.3.1 lib/regexp_parser/expression/classes/alternation.rb