Sha256: b09e7f00a42813f10b709fb5aff659b16b2130b54b3429abbf4c6bd024341223

Contents?: true

Size: 703 Bytes

Versions: 12

Compression:

Stored size: 703 Bytes

Contents

# Names a match to influence tree construction. 
#
# Example: 
#
#   str('foo')            # will return 'foo', 
#   str('foo').as(:foo)   # will return :foo => 'foo'
#
class Parslet::Atoms::Named < Parslet::Atoms::Base
  attr_reader :parslet, :name
  def initialize(parslet, name)
    super()

    @parslet, @name = parslet, name
  end
  
  def apply(source, context, consume_all)
    success, value = result = parslet.apply(source, context, consume_all)

    return result unless success
    succ(
      produce_return_value(
        value))
  end
  
  def to_s_inner(prec)
    "#{name}:#{parslet.to_s(prec)}"
  end
private
  def produce_return_value(val)
    { name => flatten(val, true) }
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
parslet-2.0.0 lib/parslet/atoms/named.rb
parslet-1.8.2 lib/parslet/atoms/named.rb
parslet-1.8.1 lib/parslet/atoms/named.rb
parslet-1.8.0 lib/parslet/atoms/named.rb
swift-pyrite-0.1.1 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/lib/parslet/atoms/named.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/lib/parslet/atoms/named.rb
parslet-1.7.1 lib/parslet/atoms/named.rb
parslet-1.7.0 lib/parslet/atoms/named.rb
parslet-1.6.2 lib/parslet/atoms/named.rb
parslet-1.6.1 lib/parslet/atoms/named.rb
parslet-1.6.0 lib/parslet/atoms/named.rb
parslet-1.5.0 lib/parslet/atoms/named.rb