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.3.0 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.2.1 lib/regexp_parser/expression/classes/alternation.rb
regexp_parser-0.2.0 lib/regexp_parser/expression/classes/alternation.rb