class ABNF::Parser::Rules::Terminal

Attributes

abnf[R]
pattern[R]

Public Class Methods

character_range(*arguments) click to toggle source
# File lib/abnf/parser/rules/terminal.rb, line 57
def self.character_range *arguments
  CharacterRange.new *arguments
end
new(pattern, abnf) click to toggle source
# File lib/abnf/parser/rules/terminal.rb, line 8
def initialize pattern, abnf
  @abnf = abnf
  @pattern = pattern
  fail if self.class == Terminal
end
string(*arguments) click to toggle source
# File lib/abnf/parser/rules/terminal.rb, line 43
def self.string *arguments
  String.new *arguments
end

Public Instance Methods

==(other_rule) click to toggle source
# File lib/abnf/parser/rules/terminal.rb, line 14
def == other_rule
  return false unless other_rule.is_a? self.class
  pattern == other_rule.pattern
end
call(io, _=nil) click to toggle source
# File lib/abnf/parser/rules/terminal.rb, line 19
def call io, _=nil
  potential_match = io.read octets
  return unless potential_match

  matches = match? potential_match

  if matches
    Node.terminal potential_match, abnf
  else
    io.seek -potential_match.bytesize, IO::SEEK_CUR
    nil
  end
end