Class: Yaparc::Satisfy
Overview
class SatisfyParser
Constant Summary
Constants included from Parsable
Parsable::IS_ALPHANUM, 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
Methods included from Parsable
Constructor Details
#initialize(predicate) ⇒ Satisfy
Returns a new instance of Satisfy.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/yaparc.rb', line 134 def initialize(predicate) raise unless predicate.instance_of?(Proc) @parser = lambda do |input| case result = Item.new.parse(input) when Result::OK parser = if predicate.call(result.value) Succeed.new(result.value, result.input) else Fail.new end else # Result::Fail or Result::Error Fail.new end end end |