Class: Yaparc::String

Inherits:
Object
  • Object
show all
Includes:
Parsable
Defined in:
lib/yaparc.rb

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

#tree

Instance Method Summary collapse

Methods included from Parsable

#eval, included, #parse

Constructor Details

#initialize(string) ⇒ String

Returns a new instance of String.



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/yaparc.rb', line 264

def initialize(string)
  @parser = lambda do |input|
    case result = Item.new.parse(string)
    when Result::OK
      Seq.new(
              Char.new(result.value),
              Yaparc::String.new(result.input),
              Succeed.new(result.value + result.input)
              ) do |char_result, string_result, succeed_result|
        succeed_result
      end
    else
      Succeed.new(result) # Is it OK?
    end
  end
end