Class: Yaparc::NoFail
- Inherits:
-
Object
- Object
- Yaparc::NoFail
- Includes:
- Parsable
- Defined in:
- lib/yaparc/no_fail.rb
Overview
hutton92:_higher_order_funct_parsin,p.19 www.cambridge.org/core/journals/journal-of-functional-programming/article/higherorder-functions-for-parsing/0490F2C8511F7625F9FC15BFFEDBB0AA
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(parser) ⇒ NoFail
constructor
A new instance of NoFail.
Methods included from Parsable
Constructor Details
#initialize(parser) ⇒ NoFail
Returns a new instance of NoFail.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/yaparc/no_fail.rb', line 9 def initialize(parser) @parser = lambda do |input| result = parser.parse(input) if result.instance_of?(Fail) Error.new(value: result.value, input: result.input) else Succeed.new(result.value) end end end |