class ABNF::Parser::Rules::RegexpPattern

Attributes

abnf[R]
max_octets[R]
regexp[R]

Public Class Methods

new(regexp, abnf, max_octets) click to toggle source
# File lib/abnf/parser/rules/regexp_pattern.rb, line 9
def initialize regexp, abnf, max_octets
  @abnf = abnf
  @max_octets = max_octets
  @regexp = regexp
end

Public Instance Methods

bounded_regexp() click to toggle source
# File lib/abnf/parser/rules/regexp_pattern.rb, line 15
def bounded_regexp
  @bounded_regexp ||= %r{\A#{regexp}}
end
call(io, _=nil) click to toggle source
# File lib/abnf/parser/rules/regexp_pattern.rb, line 19
def call io, _=nil
  string = io.read max_octets
  return unless string
  io.seek -string.bytesize, IO::SEEK_CUR

  match_data = bounded_regexp.match string

  if match_data
    node = Node.pattern_match match_data, abnf
    io.seek node.octets, IO::SEEK_CUR
    node
  end
end