Class: TRuby::ParserCombinator::FlatMap
- Defined in:
- lib/t_ruby/parser_combinator/combinators/flat_map.rb
Overview
FlatMap (bind)
Instance Method Summary collapse
-
#initialize(parser, func) ⇒ FlatMap
constructor
A new instance of FlatMap.
- #parse(input, position = 0) ⇒ Object
Methods inherited from Parser
#<<, #>>, #between, #flat_map, #label, #lookahead, #many, #many1, #map, #not_followed_by, #optional, #sep_by, #sep_by1, #|
Constructor Details
#initialize(parser, func) ⇒ FlatMap
Returns a new instance of FlatMap.
7 8 9 10 |
# File 'lib/t_ruby/parser_combinator/combinators/flat_map.rb', line 7 def initialize(parser, func) @parser = parser @func = func end |
Instance Method Details
#parse(input, position = 0) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/t_ruby/parser_combinator/combinators/flat_map.rb', line 12 def parse(input, position = 0) result = @parser.parse(input, position) return result if result.failure? next_parser = @func.call(result.value) next_parser.parse(input, result.position) end |