Class: ABNF::Alternate

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

Overview

Remember to place the longest matches first!

Direct Known Subclasses

Alpha, AlternateChars, Bit, Ctl, HexDigit, WSP

Instance Method Summary collapse

Constructor Details

#initialize(*choices, &blk) ⇒ Alternate

Returns a new instance of Alternate.



78
79
80
81
# File 'lib/abnf.rb', line 78

def initialize(*choices, &blk)
  @choices = choices
  @blk = blk
end

Instance Method Details

#match(strm) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/abnf.rb', line 88

def match(strm)
  start = strm.pos

  @choices.each {
    |c|

    n_strm = c.match(strm);

    if n_strm
      @blk.call(n_strm.clip(start)) unless @blk.nil?

      return n_strm
    end
  }

  return nil
end

#set_block(&blk) ⇒ Object



83
84
85
86
# File 'lib/abnf.rb', line 83

def set_block(&blk)
  @blk = blk
  return self
end