lib/rouge/context.rb in rouge-lang-0.0.11 vs lib/rouge/context.rb in rouge-lang-0.0.12
- old
+ new
@@ -3,23 +3,30 @@
require 'rouge/namespace'
class Rouge::Context
class BindingNotFoundError < StandardError; end
class BadBindingError < StandardError; end
+
class ChangeContextException < Exception
- def initialize(context); @context = context; end
attr_reader :context
+
+ def initialize(context)
+ @context = context
+ end
end
+ attr_reader :ns
+
def initialize(parent_or_ns)
case parent_or_ns
when Rouge::Namespace
@ns = parent_or_ns
when Rouge::Context
@parent = parent_or_ns
@ns = @parent.ns
end
+
@table = {}
end
def [](key)
if @table.include? key
@@ -45,20 +52,19 @@
if @table.include? key
@table[key] = value
elsif @parent
@parent.set_lexical key, value
else
- raise BindingNotFoundError,
- "setting #{key} to #{value.inspect}"
+ raise BindingNotFoundError, "setting #{key} to #{value.inspect}"
end
end
def lexical_keys
@table.keys + (@parent ? @parent.lexical_keys : [])
end
- # This readeval post-processes the backtrace. Accordingly, it should only
+ # This readeval post-processes the backtrace. Accordingly, it should only
# be called by consumers, and never by Rouge internally itself, lest it
# catches an exception and processes the backtrace too early.
def readeval(input)
reader = Rouge::Reader.new(ns, input)
context = self
@@ -127,12 +133,10 @@
else
self[symbol.name]
end
end
- attr_reader :ns
-
private
def eval_symbol(form)
if !form.ns and form.name_s[0] == ?. and form.name_s.length > 1
lambda {|receiver, *args, &block|
@@ -195,14 +199,13 @@
args[0].fetch(fun) { default }
else
default
end
else
- raise(
- ArgumentError,
+ raise ArgumentError,
"Wrong number of args (#{num_args}) passed to " \
- "ruby/Symbol #{fun.inspect}")
+ "ruby/Symbol #{fun.inspect}"
end
when Hash
if num_args == 1 || num_args == 2
default = args[1]
fun.fetch(args[0]) { default }
@@ -242,8 +245,8 @@
# end
# }
raise e
end
end
-end
+end # class Rouge::Context
# vim: set sw=2 et cc=80: