Diff
Modified: trunk/jparsetree/lib/parse_tree.rb (716 => 717)
--- trunk/jparsetree/lib/parse_tree.rb 2007-08-25 20:38:08 UTC (rev 716)
+++ trunk/jparsetree/lib/parse_tree.rb 2007-08-25 20:39:23 UTC (rev 717)
@@ -42,7 +42,7 @@
def initialize(arg=false)
end
-VERSION = '1.0.0.697'
+VERSION = '1.0.0.717'
##
# Main driver for ParseTree. Returns an array of arrays containing
Modified: trunk/jparsetree/lib/sexp.rb (716 => 717)
--- trunk/jparsetree/lib/sexp.rb 2007-08-25 20:38:08 UTC (rev 716)
+++ trunk/jparsetree/lib/sexp.rb 2007-08-25 20:39:23 UTC (rev 717)
@@ -199,7 +199,7 @@
if Array === self.first then
result = self.first.structure
else
- result << self.shift
+ result << self.first
self.grep(Array).each do |subexp|
result << subexp.structure
end
Modified: trunk/jparsetree/lib/sexp_processor.rb (716 => 717)
--- trunk/jparsetree/lib/sexp_processor.rb 2007-08-25 20:38:08 UTC (rev 716)
+++ trunk/jparsetree/lib/sexp_processor.rb 2007-08-25 20:39:23 UTC (rev 717)
@@ -75,35 +75,17 @@
class SexpProcessor
##
- # A default method to call if a process_<type> method is not found
- # for the Sexp type.
-
- attr_accessor :default_method
-
- ##
- # Emit a warning when the method in #default_method is called.
-
- attr_accessor :warn_on_default
-
- ##
# Automatically shifts off the Sexp type before handing the
# Sexp to process_<type>
attr_accessor :auto_shift_type
##
- # An array that specifies node types that are unsupported by this
- # processor. SexpProcessor will raise UnsupportedNodeError if you try
- # to process one of those node types.
+ # Return a stack of contexts. Most recent node is first.
- attr_accessor :unsupported
+ attr_reader :context
##
- # Raise an exception if no process_<type> method is found for a Sexp.
-
- attr_accessor :strict
-
- ##
# A Hash of Sexp types and Regexp.
#
# Print a debug message if the Sexp type matches the Hash key
@@ -112,6 +94,12 @@
attr_accessor :debug
##
+ # A default method to call if a process_<type> method is not found
+ # for the Sexp type.
+
+ attr_accessor :default_method
+
+ ##
# Expected result class
attr_accessor :expected
@@ -122,6 +110,23 @@
attr_accessor :require_empty
##
+ # Raise an exception if no process_<type> method is found for a Sexp.
+
+ attr_accessor :strict
+
+ ##
+ # An array that specifies node types that are unsupported by this
+ # processor. SexpProcessor will raise UnsupportedNodeError if you try
+ # to process one of those node types.
+
+ attr_accessor :unsupported
+
+ ##
+ # Emit a warning when the method in #default_method is called.
+
+ attr_accessor :warn_on_default
+
+ ##
# Creates a new SexpProcessor. Use super to invoke this
# initializer from SexpProcessor subclasses, then use the
# attributes above to customize the functionality of the
@@ -144,6 +149,7 @@
# different processors.
@processors = {}
@rewriters = {}
+ @context = []
public_methods.each do |name|
case name
@@ -198,7 +204,11 @@
result = self.expected.new
type = exp.first
+ raise "type should be a Symbol, not: #{exp.first.inspect}" unless
+ Symbol === type
+ @context.unshift type
+
if @debug.has_key? type then
str = exp.inspect
puts "// DEBUG: #{str}" if str =~ @debug[type]
@@ -268,6 +278,7 @@
@process_level -= 1
+ @context.shift
result
end
Modified: trunk/jparsetree/lib/unified_ruby.rb (716 => 717)
--- trunk/jparsetree/lib/unified_ruby.rb 2007-08-25 20:38:08 UTC (rev 716)
+++ trunk/jparsetree/lib/unified_ruby.rb 2007-08-25 20:39:23 UTC (rev 717)
@@ -1,5 +1,13 @@
+$TESTING ||= false
+
module UnifiedRuby
+ def rewrite_argscat(exp)
+ raise "unknown type #{exp.inspect}" unless exp[1][0] == :array
+ exp[1][0] = :arglist
+ exp
+ end
+
def rewrite_bmethod(exp)
exp[0] = :scope
@@ -25,6 +33,28 @@
exp
end
+ def rewrite_call(exp)
+ args = exp.last
+ case args
+ when nil
+ exp.pop
+ when Array
+ case args.first
+ when :array, :arglist then
+ args[0] = :arglist
+ when :argscat, :splat then
+ # do nothing
+ else
+ raise "unknown type in call #{args.first.inspect}"
+ end
+ return exp
+ end
+
+ exp << s(:arglist)
+
+ exp
+ end
+
##
# :defn is one of the most complex of all the ASTs in ruby. We do
# one of 3 different translations:
@@ -74,6 +104,14 @@
exp
end
+ def rewrite_defs(exp)
+ # move args up
+ args = exp.scope.block.args(true) rescue nil
+ exp.insert 3, args if args
+
+ exp
+ end
+
def rewrite_dmethod(exp)
exp.shift # type
exp.shift # dmethod name
@@ -89,16 +127,7 @@
exp.insert 1, nil
exp.push nil if exp.size <= 3
- args = exp[-1]
- if Array === args and args.first == :array then
- args[0] = :arglist
- elsif args.nil? then
- exp[-1] = s(:arglist)
- else
- exp[-1] = s(:arglist, args) unless args.nil?
- end
-
- exp
+ rewrite_call(exp)
end
def rewrite_resbody(exp) # TODO: clean up and move to unified
@@ -108,8 +137,8 @@
while exp and exp.first == :resbody do
code << exp.shift
list = exp.shift || s(:array)
- body = exp.shift rescue nil
- exp = exp.shift rescue nil
+ body = exp.empty? ? nil : exp.shift
+ exp = exp.empty? ? nil : exp.shift
# code may be nil, :lasgn, or :block
case body.first
@@ -133,9 +162,15 @@
end
end
- raise unless result.first == :resbody
- raise unless Sexp === result[1] and result[1].first == :array
- raise unless result[2].nil? or (Sexp === result[2] and ! result[2].empty?)
+ if $DEBUG or $TESTING then
+ structure = result.structure
+ raise "result structure wrong: #{structure[0..1].inspect}" unless
+ structure.flatten[0] == :resbody
+ raise "result structure wrong: #{structure[0..1].inspect}" unless
+ s(:array, :splat, :argscat).include? structure.flatten[1]
+ raise "result body wrong: #{structure[2].inspect}" unless
+ structure[2].nil? or not structure[2].empty?
+ end
result
end
Modified: trunk/jparsetree/lib/version.rb (716 => 717)
--- trunk/jparsetree/lib/version.rb 2007-08-25 20:38:08 UTC (rev 716)
+++ trunk/jparsetree/lib/version.rb 2007-08-25 20:39:23 UTC (rev 717)
@@ -1,3 +1,3 @@
module JParseTree
-VERSION = '0.9.9.402'
+VERSION = '1.0.0.697'
end