Class: ABNF::Parser::Rules::RegexpPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/abnf/parser/rules/regexp_pattern.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regexp, abnf, max_octets) ⇒ RegexpPattern

Returns a new instance of RegexpPattern.



9
10
11
12
13
# 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

Instance Attribute Details

#abnfObject (readonly)

Returns the value of attribute abnf.



5
6
7
# File 'lib/abnf/parser/rules/regexp_pattern.rb', line 5

def abnf
  @abnf
end

#max_octetsObject (readonly)

Returns the value of attribute max_octets.



6
7
8
# File 'lib/abnf/parser/rules/regexp_pattern.rb', line 6

def max_octets
  @max_octets
end

#regexpObject (readonly)

Returns the value of attribute regexp.



7
8
9
# File 'lib/abnf/parser/rules/regexp_pattern.rb', line 7

def regexp
  @regexp
end

Instance Method Details

#bounded_regexpObject



15
16
17
# File 'lib/abnf/parser/rules/regexp_pattern.rb', line 15

def bounded_regexp
  @bounded_regexp ||= %r{\A#{regexp}}
end

#call(io, _ = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# 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