class KPeg::LiteralRegexp

Attributes

regexp[R]

Public Class Methods

new(reg, opts=nil) click to toggle source
Calls superclass method KPeg::Operator::new
# File lib/kpeg/grammar.rb, line 104
def initialize(reg, opts=nil)
  super()

  if reg.kind_of? String
    flags = 0

    if opts
      opts.split("").each do |o|
        case o
        when "m"
          flags |= Regexp::MULTILINE
        when "x"
          flags |= Regexp::EXTENDED
        when "i"
          flags |= Regexp::IGNORECASE
        end
      end
    end

    @regexp = Regexp.new(reg, flags)
  else
    @regexp = reg
  end
end

Public Instance Methods

==(obj) click to toggle source
Calls superclass method
# File lib/kpeg/grammar.rb, line 143
def ==(obj)
  case obj
  when LiteralRegexp
    @regexp == obj.regexp
  else
    super
  end
end
inspect() click to toggle source
# File lib/kpeg/grammar.rb, line 152
def inspect
  inspect_type 'reg', @regexp.inspect
end
match(x) click to toggle source
# File lib/kpeg/grammar.rb, line 135
def match(x)
  if str = x.scan(@regexp)
    MatchString.new(self, str)
  else
    x.fail(self)
  end
end
string() click to toggle source
# File lib/kpeg/grammar.rb, line 131
def string
  @regexp.source
end