Class: TRuby::ParserCombinator::FlatMap
- Defined in:
- lib/t_ruby/parser_combinator.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
276 277 278 279 |
# File 'lib/t_ruby/parser_combinator.rb', line 276 def initialize(parser, func) @parser = parser @func = func end |
Instance Method Details
#parse(input, position = 0) ⇒ Object
281 282 283 284 285 286 287 |
# File 'lib/t_ruby/parser_combinator.rb', line 281 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 |