Class: TRuby::ParserCombinator::Satisfy
- Defined in:
- lib/t_ruby/parser_combinator.rb
Overview
Parse a single character matching predicate
Instance Method Summary collapse
-
#initialize(predicate, description = "character") ⇒ Satisfy
constructor
A new instance of Satisfy.
- #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(predicate, description = "character") ⇒ Satisfy
Returns a new instance of Satisfy.
147 148 149 150 |
# File 'lib/t_ruby/parser_combinator.rb', line 147 def initialize(predicate, description = "character") @predicate = predicate @description = description end |
Instance Method Details
#parse(input, position = 0) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/t_ruby/parser_combinator.rb', line 152 def parse(input, position = 0) if position < input.length && @predicate.call(input[position]) ParseResult.success(input[position], input, position + 1) else ParseResult.failure("Expected #{@description}", input, position) end end |