Sha256: 9678cc233187f53940a4767021e064800c997f4033507089bfa1459b1cb30e0c

Contents?: true

Size: 526 Bytes

Versions: 2

Compression:

Stored size: 526 Bytes

Contents

require 'blankslate'

# Provides a context for tree transformations to run in. The context allows
# accessing each of the bindings in the bindings hash as local method.
#
# Example: 
#
#   ctx = Context.new(:a => :b)
#   ctx.instance_eval do 
#     a # => :b
#   end
#
class Parslet::Pattern::Context < BlankSlate
  def initialize(bindings)
    @bindings = bindings
  end
  
  def method_missing(sym, *args, &block)
    super unless args.empty?
    super unless @bindings.has_key?(sym.to_sym)
    
    @bindings[sym]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
parslet-0.11.0 lib/parslet/pattern/context.rb
parslet-0.10.1 lib/parslet/pattern/context.rb