Class: DParse::Parsers::Map
- Inherits:
-
DParse::Parser
- Object
- DParse::Parser
- DParse::Parsers::Map
- Defined in:
- lib/d-parse/parsers/modifiers/map.rb
Instance Method Summary collapse
-
#initialize(parser, &block) ⇒ Map
constructor
A new instance of Map.
- #inspect ⇒ Object
- #read(input, pos) ⇒ Object
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) ⇒ Map
Returns a new instance of Map.
4 5 6 7 |
# File 'lib/d-parse/parsers/modifiers/map.rb', line 4 def initialize(parser, &block) @parser = parser @block = block end |
Instance Method Details
#inspect ⇒ Object
19 20 21 |
# File 'lib/d-parse/parsers/modifiers/map.rb', line 19 def inspect "map(#{@parser}, <proc>)" end |
#read(input, pos) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/d-parse/parsers/modifiers/map.rb', line 9 def read(input, pos) res = @parser.read(input, pos) case res when Success Success.new(input, res.pos, data: @block.call(res.data, res, pos), best_failure: res.best_failure) when Failure res end end |