Class: Yaparc::Satisfy
- Inherits:
-
Object
- Object
- Yaparc::Satisfy
- Includes:
- Parsable
- Defined in:
- lib/yaparc/satisfy.rb
Constant Summary
Constants included from Parsable
Parsable::IS_ALPHANUM, Parsable::IS_CR, Parsable::IS_DIGIT, Parsable::IS_LOWER, Parsable::IS_SPACE, Parsable::IS_WHITESPACE
Instance Method Summary collapse
-
#initialize(predicate) ⇒ Satisfy
constructor
A new instance of Satisfy.
- #parse(input) ⇒ Object
Constructor Details
#initialize(predicate) ⇒ Satisfy
Returns a new instance of Satisfy.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/yaparc/satisfy.rb', line 7 def initialize(predicate) @parser = lambda do |input| result = Item.new.parse(input) if result.instance_of?(OK) && predicate.call(result.value) Succeed.new(result.value, result.input) else FailParser.new end end end |
Instance Method Details
#parse(input) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/yaparc/satisfy.rb', line 19 def parse(input) case parser = @parser.call(input) in Succeed parser.parse(parser.remaining) in FailParser parser.parse(input) end end |