class ABNF::Alternate
Remember to place the longest matches first!
Public Class Methods
new(*choices, &blk)
click to toggle source
# File lib/abnf.rb, line 78 def initialize(*choices, &blk) @choices = choices @blk = blk end
Public Instance Methods
match(strm)
click to toggle source
# 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)
click to toggle source
# File lib/abnf.rb, line 83 def set_block(&blk) @blk = blk return self end