Class: DParse::Parsers::Bind

Inherits:
DParse::Parser show all
Defined in:
lib/d-parse/parsers/primitives/bind.rb

Instance Method Summary collapse

Methods inherited from DParse::Parser

#apply, #bind, #capture, #compact, #expectation_message, #first, #flatten, #ignore, #map, #match?, #second, #select_even, #select_odd, #to_s

Constructor Details

#initialize(parser, &block) ⇒ Bind

Returns a new instance of Bind.



4
5
6
7
# File 'lib/d-parse/parsers/primitives/bind.rb', line 4

def initialize(parser, &block)
  @parser = parser
  @block = block
end

Instance Method Details

#inspectObject



20
21
22
# File 'lib/d-parse/parsers/primitives/bind.rb', line 20

def inspect
  "bind(#{@parser}, <proc>)"
end

#read(input, pos) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/d-parse/parsers/primitives/bind.rb', line 9

def read(input, pos)
  res = @parser.read(input, pos)
  case res
  when Success
    other_parser = @block.call(res.data)
    other_parser.read(input, res.pos)
  when Failure
    res
  end
end