Sha256: a7dc5f7c2ed02f3840045b61f90681b589d71ffa71ae7e207ee63bb9cb098ead

Contents?: true

Size: 677 Bytes

Versions: 3

Compression:

Stored size: 677 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)
    success, value = result = parslet.apply(source, context)

    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

3 entries across 3 versions & 2 rubygems

Version Path
ghazel-parslet-1.4.0.2 lib/parslet/atoms/named.rb
ghazel-parslet-1.4.0.1 lib/parslet/atoms/named.rb
parslet-1.4.0 lib/parslet/atoms/named.rb