Class: ABNF::Alternate
- Inherits:
-
Object
- Object
- ABNF::Alternate
- Defined in:
- lib/abnf.rb
Overview
Remember to place the longest matches first!
Instance Method Summary collapse
-
#initialize(*choices, &blk) ⇒ Alternate
constructor
A new instance of Alternate.
- #match(strm) ⇒ Object
- #set_block(&blk) ⇒ Object
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 |