Class: Yaparc::Satisfy
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 Attribute Summary
Attributes included from Parsable
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.
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/yaparc.rb', line 103 def initialize(predicate) raise unless predicate.instance_of?(Proc) @parser = lambda do |input| result = Item.new.parse(input) if result.instance_of?(Result::OK) and predicate.call(result.value) Succeed.new(result.value, result.input) else Fail.new end end end |