vendored parslet, deemed stable enough and better without dependency

This commit is contained in:
Torsten Ruger
2014-04-27 15:34:35 +03:00
parent 6fafeda66d
commit b1203363d4
42 changed files with 3415 additions and 2 deletions

42
lib/parslet/scope.rb Normal file
View File

@@ -0,0 +1,42 @@
class Parslet::Scope
# Raised when the accessed slot has never been assigned a value.
#
class NotFound < StandardError
end
class Binding
attr_reader :parent
def initialize(parent=nil)
@parent = parent
@hash = Hash.new
end
def [](k)
@hash.has_key?(k) && @hash[k] ||
parent && parent[k] or
raise NotFound
end
def []=(k,v)
@hash.store(k,v)
end
end
def [](k)
@current[k]
end
def []=(k,v)
@current[k] = v
end
def initialize
@current = Binding.new
end
def push
@current = Binding.new(@current)
end
def pop
@current = @current.parent
end
end