Sha256: 8448ffcc6b41cd7d30c025fdc97bcea8709320ae05867e009a93c581d0296092

Contents?: true

Size: 525 Bytes

Versions: 4

Compression:

Stored size: 525 Bytes

Contents

# Ignores the result of a match.
#
# Example:
#
#   str('foo')            # will return 'foo',
#   str('foo').ignore     # will return nil
#
class Parslet::Atoms::Ignored < Parslet::Atoms::Base
  attr_reader :parslet
  def initialize(parslet)
    super()

    @parslet = parslet
  end

  def apply(source, context, consume_all)
    success, _ = result = parslet.apply(source, context, consume_all)

    return result unless success
    succ(nil)
  end
  
  def to_s_inner(prec)
    "ignored(#{parslet.to_s(prec)})"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
parslet-2.0.0 lib/parslet/atoms/ignored.rb
parslet-1.8.2 lib/parslet/atoms/ignored.rb
parslet-1.8.1 lib/parslet/atoms/ignored.rb
parslet-1.8.0 lib/parslet/atoms/ignored.rb