Sha256: 4def64e796ae865efc1461758cbbe8799006e2c05869dffc1d71da5347a74051

Contents?: true

Size: 1.23 KB

Versions: 17

Compression:

Stored size: 1.23 KB

Contents

# Used internally for representing a bind placeholder in a Parslet::Transform
# pattern. This is the superclass for all bindings. 
#
# It defines the most permissive kind of bind, the one that matches any subtree
# whatever it looks like. 
#
class Parslet::Pattern::SubtreeBind < Struct.new(:symbol)
  def variable_name
    symbol
  end
  
  def inspect
    "#{bind_type_name}(#{symbol.inspect})"
  end
  
  def can_bind?(subtree)
    true
  end

private 
  def bind_type_name 
    if md=self.class.name.match(/(\w+)Bind/)
      md.captures.first.downcase
    else
      # This path should never be used, but since this is for inspection only, 
      # let's not raise.
      'unknown_bind'
    end
  end
end

# Binds a symbol to a simple subtree, one that is not either a sequence of
# elements or a collection of attributes. 
#
class Parslet::Pattern::SimpleBind < Parslet::Pattern::SubtreeBind
  def can_bind?(subtree)
    not [Hash, Array].include?(subtree.class)
  end
end

# Binds a symbol to a sequence of simple leafs ([element1, element2, ...])
#
class Parslet::Pattern::SequenceBind < Parslet::Pattern::SubtreeBind
  def can_bind?(subtree)
    subtree.kind_of?(Array) &&
      (not subtree.any? { |el| [Hash, Array].include?(el.class) })
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
parslet-2.0.0 lib/parslet/pattern/binding.rb
parslet-1.8.2 lib/parslet/pattern/binding.rb
parslet-1.8.1 lib/parslet/pattern/binding.rb
parslet-1.8.0 lib/parslet/pattern/binding.rb
swift-pyrite-0.1.1 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/lib/parslet/pattern/binding.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/lib/parslet/pattern/binding.rb
parslet-1.7.1 lib/parslet/pattern/binding.rb
parslet-1.7.0 lib/parslet/pattern/binding.rb
parslet-1.6.2 lib/parslet/pattern/binding.rb
parslet-1.6.1 lib/parslet/pattern/binding.rb
parslet-1.6.0 lib/parslet/pattern/binding.rb
parslet-1.5.0 lib/parslet/pattern/binding.rb
ghazel-parslet-1.4.0.2 lib/parslet/pattern/binding.rb
ghazel-parslet-1.4.0.1 lib/parslet/pattern/binding.rb
parslet-1.4.0 lib/parslet/pattern/binding.rb
parslet-0.11.0 lib/parslet/pattern/binding.rb
parslet-0.10.1 lib/parslet/pattern/binding.rb