mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rexml/**/*.rb: removed commented-out code.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
091cdca65e
commit
be1206c0ac
8 changed files with 4 additions and 178 deletions
|
@ -1,3 +1,7 @@
|
|||
Sun Sep 21 12:10:18 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||
|
||||
* lib/rexml/**/*.rb: removed commented-out code.
|
||||
|
||||
Sat Sep 20 03:46:58 2014 Masaki Matsushita <glass.saga@gmail.com>
|
||||
|
||||
* array.c: use rb_equal_opt() for performance improvement.
|
||||
|
|
|
@ -21,7 +21,6 @@ module REXML
|
|||
# should be nil, not supplied, or a Parent to be set as the parent
|
||||
# of this object
|
||||
def initialize( first, second = nil )
|
||||
#puts "IN COMMENT CONSTRUCTOR; SECOND IS #{second.type}"
|
||||
super(second)
|
||||
if first.kind_of? String
|
||||
@string = first
|
||||
|
|
|
@ -15,10 +15,8 @@ module REXML
|
|||
end
|
||||
|
||||
def add( object )
|
||||
#puts "PARENT GOTS #{size} CHILDREN"
|
||||
object.parent = self
|
||||
@children << object
|
||||
#puts "PARENT NOW GOTS #{size} CHILDREN"
|
||||
object
|
||||
end
|
||||
|
||||
|
|
|
@ -229,7 +229,6 @@ module REXML
|
|||
def get_procs( symbol, name )
|
||||
return nil if @procs.size == 0
|
||||
@procs.find_all do |sym, match, block|
|
||||
#puts sym.inspect+"=="+symbol.inspect+ "\t"+match.inspect+"=="+name.inspect+ "\t"+( (sym.nil? or symbol == sym) and ((name.nil? and match.nil?) or match.nil? or ( (name == match) or (match.kind_of? Regexp and name =~ match)))).to_s
|
||||
(
|
||||
(sym.nil? or symbol == sym) and
|
||||
((name.nil? and match.nil?) or match.nil? or (
|
||||
|
|
|
@ -184,7 +184,6 @@ module REXML
|
|||
# | '/' RelativeLocationPath?
|
||||
# | '//' RelativeLocationPath
|
||||
def LocationPath path, parsed
|
||||
#puts "LocationPath '#{path}'"
|
||||
path = path.strip
|
||||
if path[0] == ?/
|
||||
parsed << :document
|
||||
|
@ -196,7 +195,6 @@ module REXML
|
|||
path = path[1..-1]
|
||||
end
|
||||
end
|
||||
#puts parsed.inspect
|
||||
return RelativeLocationPath( path, parsed ) if path.size > 0
|
||||
end
|
||||
|
||||
|
@ -210,7 +208,6 @@ module REXML
|
|||
# | RelativeLocationPath '//' Step
|
||||
AXIS = /^(ancestor|ancestor-or-self|attribute|child|descendant|descendant-or-self|following|following-sibling|namespace|parent|preceding|preceding-sibling|self)::/
|
||||
def RelativeLocationPath path, parsed
|
||||
#puts "RelativeLocationPath #{path}"
|
||||
while path.size > 0
|
||||
# (axis or @ or <child::>) nodetest predicate >
|
||||
# OR > / Step
|
||||
|
@ -227,7 +224,6 @@ module REXML
|
|||
end
|
||||
else
|
||||
if path[0] == ?@
|
||||
#puts "ATTRIBUTE"
|
||||
parsed << :attribute
|
||||
path = path[1..-1]
|
||||
# Goto Nodetest
|
||||
|
@ -239,10 +235,8 @@ module REXML
|
|||
parsed << :child
|
||||
end
|
||||
|
||||
#puts "NODETESTING '#{path}'"
|
||||
n = []
|
||||
path = NodeTest( path, n)
|
||||
#puts "NODETEST RETURNED '#{path}'"
|
||||
|
||||
if path[0] == ?[
|
||||
path = Predicate( path, n )
|
||||
|
@ -282,7 +276,6 @@ module REXML
|
|||
NODE_TYPE = /^(comment|text|node)\(\s*\)/m
|
||||
PI = /^processing-instruction\(/
|
||||
def NodeTest path, parsed
|
||||
#puts "NodeTest with #{path}"
|
||||
case path
|
||||
when /^\*/
|
||||
path = $'
|
||||
|
@ -304,13 +297,11 @@ module REXML
|
|||
parsed << :processing_instruction
|
||||
parsed << (literal || '')
|
||||
when NCNAMETEST
|
||||
#puts "NCNAMETEST"
|
||||
prefix = $1
|
||||
path = $'
|
||||
parsed << :namespace
|
||||
parsed << prefix
|
||||
when QNAME
|
||||
#puts "QNAME"
|
||||
prefix = $1
|
||||
name = $2
|
||||
path = $'
|
||||
|
@ -324,22 +315,18 @@ module REXML
|
|||
|
||||
# Filters the supplied nodeset on the predicate(s)
|
||||
def Predicate path, parsed
|
||||
#puts "PREDICATE with #{path}"
|
||||
return nil unless path[0] == ?[
|
||||
predicates = []
|
||||
while path[0] == ?[
|
||||
path, expr = get_group(path)
|
||||
predicates << expr[1..-2] if expr
|
||||
end
|
||||
#puts "PREDICATES = #{predicates.inspect}"
|
||||
predicates.each{ |pred|
|
||||
#puts "ORING #{pred}"
|
||||
preds = []
|
||||
parsed << :predicate
|
||||
parsed << preds
|
||||
OrExpr(pred, preds)
|
||||
}
|
||||
#puts "PREDICATES = #{predicates.inspect}"
|
||||
path
|
||||
end
|
||||
|
||||
|
@ -350,10 +337,8 @@ module REXML
|
|||
#| OrExpr S 'or' S AndExpr
|
||||
#| AndExpr
|
||||
def OrExpr path, parsed
|
||||
#puts "OR >>> #{path}"
|
||||
n = []
|
||||
rest = AndExpr( path, n )
|
||||
#puts "OR <<< #{rest}"
|
||||
if rest != path
|
||||
while rest =~ /^\s*( or )/
|
||||
n = [ :or, n, [] ]
|
||||
|
@ -371,16 +356,12 @@ module REXML
|
|||
#| AndExpr S 'and' S EqualityExpr
|
||||
#| EqualityExpr
|
||||
def AndExpr path, parsed
|
||||
#puts "AND >>> #{path}"
|
||||
n = []
|
||||
rest = EqualityExpr( path, n )
|
||||
#puts "AND <<< #{rest}"
|
||||
if rest != path
|
||||
while rest =~ /^\s*( and )/
|
||||
n = [ :and, n, [] ]
|
||||
#puts "AND >>> #{rest}"
|
||||
rest = EqualityExpr( $', n[-1] )
|
||||
#puts "AND <<< #{rest}"
|
||||
end
|
||||
end
|
||||
if parsed.size == 0 and n.size != 0
|
||||
|
@ -394,10 +375,8 @@ module REXML
|
|||
#| EqualityExpr ('=' | '!=') RelationalExpr
|
||||
#| RelationalExpr
|
||||
def EqualityExpr path, parsed
|
||||
#puts "EQUALITY >>> #{path}"
|
||||
n = []
|
||||
rest = RelationalExpr( path, n )
|
||||
#puts "EQUALITY <<< #{rest}"
|
||||
if rest != path
|
||||
while rest =~ /^\s*(!?=)\s*/
|
||||
if $1[0] == ?!
|
||||
|
@ -419,10 +398,8 @@ module REXML
|
|||
#| RelationalExpr ('<' | '>' | '<=' | '>=') AdditiveExpr
|
||||
#| AdditiveExpr
|
||||
def RelationalExpr path, parsed
|
||||
#puts "RELATION >>> #{path}"
|
||||
n = []
|
||||
rest = AdditiveExpr( path, n )
|
||||
#puts "RELATION <<< #{rest}"
|
||||
if rest != path
|
||||
while rest =~ /^\s*([<>]=?)\s*/
|
||||
if $1[0] == ?<
|
||||
|
@ -446,10 +423,8 @@ module REXML
|
|||
#| AdditiveExpr ('+' | S '-') MultiplicativeExpr
|
||||
#| MultiplicativeExpr
|
||||
def AdditiveExpr path, parsed
|
||||
#puts "ADDITIVE >>> #{path}"
|
||||
n = []
|
||||
rest = MultiplicativeExpr( path, n )
|
||||
#puts "ADDITIVE <<< #{rest}"
|
||||
if rest != path
|
||||
while rest =~ /^\s*(\+| -)\s*/
|
||||
if $1[0] == ?+
|
||||
|
@ -471,10 +446,8 @@ module REXML
|
|||
#| MultiplicativeExpr ('*' | S ('div' | 'mod') S) UnaryExpr
|
||||
#| UnaryExpr
|
||||
def MultiplicativeExpr path, parsed
|
||||
#puts "MULT >>> #{path}"
|
||||
n = []
|
||||
rest = UnaryExpr( path, n )
|
||||
#puts "MULT <<< #{rest}"
|
||||
if rest != path
|
||||
while rest =~ /^\s*(\*| div | mod )\s*/
|
||||
if $1[0] == ?*
|
||||
|
@ -507,10 +480,8 @@ module REXML
|
|||
end
|
||||
parsed << :neg if mult < 0
|
||||
|
||||
#puts "UNARY >>> #{path}"
|
||||
n = []
|
||||
path = UnionExpr( path, n )
|
||||
#puts "UNARY <<< #{path}"
|
||||
parsed.concat( n )
|
||||
path
|
||||
end
|
||||
|
@ -518,10 +489,8 @@ module REXML
|
|||
#| UnionExpr '|' PathExpr
|
||||
#| PathExpr
|
||||
def UnionExpr path, parsed
|
||||
#puts "UNION >>> #{path}"
|
||||
n = []
|
||||
rest = PathExpr( path, n )
|
||||
#puts "UNION <<< #{rest}"
|
||||
if rest != path
|
||||
while rest =~ /^\s*(\|)\s*/
|
||||
n = [ :union, n, [] ]
|
||||
|
@ -541,16 +510,13 @@ module REXML
|
|||
def PathExpr path, parsed
|
||||
path =~ /^\s*/
|
||||
path = $'
|
||||
#puts "PATH >>> #{path}"
|
||||
n = []
|
||||
rest = FilterExpr( path, n )
|
||||
#puts "PATH <<< '#{rest}'"
|
||||
if rest != path
|
||||
if rest and rest[0] == ?/
|
||||
return RelativeLocationPath(rest, n)
|
||||
end
|
||||
end
|
||||
#puts "BEFORE WITH '#{rest}'"
|
||||
rest = LocationPath(rest, n) if rest =~ /\A[\/\.\@\[\w*]/
|
||||
parsed.concat(n)
|
||||
return rest
|
||||
|
@ -559,12 +525,9 @@ module REXML
|
|||
#| FilterExpr Predicate
|
||||
#| PrimaryExpr
|
||||
def FilterExpr path, parsed
|
||||
#puts "FILTER >>> #{path}"
|
||||
n = []
|
||||
path = PrimaryExpr( path, n )
|
||||
#puts "FILTER <<< #{path}"
|
||||
path = Predicate(path, n) if path and path[0] == ?[
|
||||
#puts "FILTER <<< #{path}"
|
||||
parsed.concat(n)
|
||||
path
|
||||
end
|
||||
|
@ -586,23 +549,19 @@ module REXML
|
|||
parsed << varname
|
||||
#arry << @variables[ varname ]
|
||||
when /^(\w[-\w]*)(?:\()/
|
||||
#puts "PrimaryExpr :: Function >>> #$1 -- '#$''"
|
||||
fname = $1
|
||||
tmp = $'
|
||||
#puts "#{fname} =~ #{NT.inspect}"
|
||||
return path if fname =~ NT
|
||||
path = tmp
|
||||
parsed << :function
|
||||
parsed << fname
|
||||
path = FunctionCall(path, parsed)
|
||||
when NUMBER
|
||||
#puts "LITERAL or NUMBER: #$1"
|
||||
varname = $1.nil? ? $2 : $1
|
||||
path = $'
|
||||
parsed << :literal
|
||||
parsed << (varname.include?('.') ? varname.to_f : varname.to_i)
|
||||
when LITERAL
|
||||
#puts "LITERAL or NUMBER: #$1"
|
||||
varname = $1.nil? ? $2 : $1
|
||||
path = $'
|
||||
parsed << :literal
|
||||
|
|
|
@ -145,7 +145,6 @@ module REXML
|
|||
|
||||
def next( event )
|
||||
#print "In next with #{event.inspect}. "
|
||||
#puts "Next (#@current) is #{@events[@current]}"
|
||||
#p @previous
|
||||
return @previous.pop.next( event ) if @events[@current].nil?
|
||||
expand_ref_in( @events, @current ) if @events[@current].class == Ref
|
||||
|
@ -154,19 +153,15 @@ module REXML
|
|||
@events[@current-1].previous = self
|
||||
return @events[@current-1].next( event )
|
||||
end
|
||||
#puts "Current isn't a state"
|
||||
if ( @events[@current].matches?(event) )
|
||||
@current += 1
|
||||
if @events[@current].nil?
|
||||
#puts "#{inspect[0,5]} 1RETURNING #{@previous.inspect[0,5]}"
|
||||
return @previous.pop
|
||||
elsif @events[@current].kind_of? State
|
||||
@current += 1
|
||||
#puts "#{inspect[0,5]} 2RETURNING (#{@current-1}) #{@events[@current-1].inspect[0,5]}; on return, next is #{@events[@current]}"
|
||||
@events[@current-1].previous = self
|
||||
return @events[@current-1]
|
||||
else
|
||||
#puts "#{inspect[0,5]} RETURNING self w/ next(#@current) = #{@events[@current]}"
|
||||
return self
|
||||
end
|
||||
else
|
||||
|
@ -393,13 +388,10 @@ module REXML
|
|||
# Remove the references
|
||||
# Find the events
|
||||
end
|
||||
#puts "In next with #{event.inspect}."
|
||||
#puts "events is #{@events.inspect}"
|
||||
unless @events
|
||||
@events = []
|
||||
return nil
|
||||
end
|
||||
#puts "current = #@current"
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -409,8 +401,6 @@ module REXML
|
|||
end
|
||||
|
||||
def expected
|
||||
#puts "IN CHOICE EXPECTED"
|
||||
#puts "EVENTS = #{@events.inspect}"
|
||||
return [@events[@current]] if @events.size > 0
|
||||
return @choices.collect do |x|
|
||||
if x[0].kind_of? State
|
||||
|
@ -479,8 +469,6 @@ module REXML
|
|||
@choice += 1
|
||||
end
|
||||
|
||||
#puts "In next with #{event.inspect}."
|
||||
#puts "events is #{@events.inspect}"
|
||||
@events = [] unless @events
|
||||
end
|
||||
|
||||
|
@ -491,29 +479,22 @@ module REXML
|
|||
return nil unless @events[@current]
|
||||
|
||||
expand_ref_in( @events, @current ) if @events[@current].class == Ref
|
||||
#puts "In next with #{event.inspect}."
|
||||
#puts "Next (#@current) is #{@events[@current]}"
|
||||
if ( @events[@current].kind_of? State )
|
||||
@current += 1
|
||||
@events[@current-1].previous = self
|
||||
return @events[@current-1].next( event )
|
||||
end
|
||||
#puts "Current isn't a state"
|
||||
return @previous.pop.next( event ) if @events[@current].nil?
|
||||
if ( @events[@current].matches?(event) )
|
||||
@current += 1
|
||||
if @events[@current].nil?
|
||||
#puts "#{inspect[0,5]} 1RETURNING self" unless @choices[@choice].nil?
|
||||
return self unless @choices[@choice].nil?
|
||||
#puts "#{inspect[0,5]} 1RETURNING #{@previous[-1].inspect[0,5]}"
|
||||
return @previous.pop
|
||||
elsif @events[@current].kind_of? State
|
||||
@current += 1
|
||||
#puts "#{inspect[0,5]} 2RETURNING (#{@current-1}) #{@events[@current-1].inspect[0,5]}; on return, next is #{@events[@current]}"
|
||||
@events[@current-1].previous = self
|
||||
return @events[@current-1]
|
||||
else
|
||||
#puts "#{inspect[0,5]} RETURNING self w/ next(#@current) = #{@events[@current]}"
|
||||
return self
|
||||
end
|
||||
else
|
||||
|
@ -527,8 +508,6 @@ module REXML
|
|||
end
|
||||
|
||||
def expected
|
||||
#puts "IN CHOICE EXPECTED"
|
||||
#puts "EVENTS = #{@events.inspect}"
|
||||
return [@events[@current]] if @events[@current]
|
||||
return @choices[@choice..-1].collect do |x|
|
||||
if x[0].kind_of? State
|
||||
|
|
|
@ -15,8 +15,6 @@ module REXML
|
|||
puts @root.inspect
|
||||
end
|
||||
def validate( event )
|
||||
#puts "Current: #@current"
|
||||
#puts "Event: #{event.inspect}"
|
||||
@attr_stack = [] unless defined? @attr_stack
|
||||
match = @current.next(event)
|
||||
raise ValidationException.new( "Validation error. Expected: "+
|
||||
|
@ -27,7 +25,6 @@ module REXML
|
|||
# Check for attributes
|
||||
case event[0]
|
||||
when :start_element
|
||||
#puts "Checking attributes"
|
||||
@attr_stack << event[2]
|
||||
begin
|
||||
sattr = [:start_attribute, nil]
|
||||
|
@ -35,22 +32,14 @@ module REXML
|
|||
text = [:text, nil]
|
||||
k, = event[2].find { |key,value|
|
||||
sattr[1] = key
|
||||
#puts "Looking for #{sattr.inspect}"
|
||||
m = @current.next( sattr )
|
||||
#puts "Got #{m.inspect}"
|
||||
if m
|
||||
# If the state has text children...
|
||||
#puts "Looking for #{eattr.inspect}"
|
||||
#puts "Expect #{m.expected}"
|
||||
if m.matches?( eattr )
|
||||
#puts "Got end"
|
||||
@current = m
|
||||
else
|
||||
#puts "Didn't get end"
|
||||
text[1] = value
|
||||
#puts "Looking for #{text.inspect}"
|
||||
m = m.next( text )
|
||||
#puts "Got #{m.inspect}"
|
||||
text[1] = nil
|
||||
return false unless m
|
||||
@current = m if m
|
||||
|
@ -94,7 +83,6 @@ module REXML
|
|||
end
|
||||
|
||||
def matches?( event )
|
||||
#puts "#@event_type =? #{event[0]} && #@event_arg =? #{event[1]} "
|
||||
return false unless event[0] == @event_type
|
||||
case event[0]
|
||||
when nil
|
||||
|
|
|
@ -63,18 +63,12 @@ module REXML
|
|||
end
|
||||
|
||||
def parse path, nodeset
|
||||
#puts "#"*40
|
||||
path_stack = @parser.parse( path )
|
||||
#puts "PARSE: #{path} => #{path_stack.inspect}"
|
||||
#puts "PARSE: nodeset = #{nodeset.inspect}"
|
||||
match( path_stack, nodeset )
|
||||
end
|
||||
|
||||
def get_first path, nodeset
|
||||
#puts "#"*40
|
||||
path_stack = @parser.parse( path )
|
||||
#puts "PARSE: #{path} => #{path_stack.inspect}"
|
||||
#puts "PARSE: nodeset = #{nodeset.inspect}"
|
||||
first( path_stack, nodeset )
|
||||
end
|
||||
|
||||
|
@ -93,7 +87,6 @@ module REXML
|
|||
#
|
||||
# FIXME: This method is incomplete!
|
||||
def first( path_stack, node )
|
||||
#puts "#{depth}) Entering match( #{path.inspect}, #{tree.inspect} )"
|
||||
return nil if path.size == 0
|
||||
|
||||
case path[0]
|
||||
|
@ -102,16 +95,12 @@ module REXML
|
|||
return first( path[1..-1], node )
|
||||
when :child
|
||||
for c in node.children
|
||||
#puts "#{depth}) CHILD checking #{name(c)}"
|
||||
r = first( path[1..-1], c )
|
||||
#puts "#{depth}) RETURNING #{r.inspect}" if r
|
||||
return r if r
|
||||
end
|
||||
when :qname
|
||||
name = path[2]
|
||||
#puts "#{depth}) QNAME #{name(tree)} == #{name} (path => #{path.size})"
|
||||
if node.name == name
|
||||
#puts "#{depth}) RETURNING #{tree.inspect}" if path.size == 3
|
||||
return node if path.size == 3
|
||||
return first( path[3..-1], node )
|
||||
else
|
||||
|
@ -134,10 +123,7 @@ module REXML
|
|||
|
||||
|
||||
def match( path_stack, nodeset )
|
||||
#puts "MATCH: path_stack = #{path_stack.inspect}"
|
||||
#puts "MATCH: nodeset = #{nodeset.inspect}"
|
||||
r = expr( path_stack, nodeset )
|
||||
#puts "MAIN EXPR => #{r.inspect}"
|
||||
r
|
||||
end
|
||||
|
||||
|
@ -164,15 +150,9 @@ module REXML
|
|||
ALL = [ :attribute, :element, :text, :processing_instruction, :comment ]
|
||||
ELEMENTS = [ :element ]
|
||||
def expr( path_stack, nodeset, context=nil )
|
||||
#puts "#"*15
|
||||
#puts "In expr with #{path_stack.inspect}"
|
||||
#puts "Returning" if path_stack.length == 0 || nodeset.length == 0
|
||||
node_types = ELEMENTS
|
||||
return nodeset if path_stack.length == 0 || nodeset.length == 0
|
||||
while path_stack.length > 0
|
||||
#puts "#"*5
|
||||
#puts "Path stack = #{path_stack.inspect}"
|
||||
#puts "Nodeset is #{nodeset.inspect}"
|
||||
if nodeset.length == 0
|
||||
path_stack.clear
|
||||
return []
|
||||
|
@ -180,21 +160,15 @@ module REXML
|
|||
case (op = path_stack.shift)
|
||||
when :document
|
||||
nodeset = [ nodeset[0].root_node ]
|
||||
#puts ":document, nodeset = #{nodeset.inspect}"
|
||||
|
||||
when :qname
|
||||
#puts "IN QNAME"
|
||||
prefix = path_stack.shift
|
||||
name = path_stack.shift
|
||||
nodeset.delete_if do |node|
|
||||
# FIXME: This DOUBLES the time XPath searches take
|
||||
ns = get_namespace( node, prefix )
|
||||
#puts "NS = #{ns.inspect}"
|
||||
#puts "node.node_type == :element => #{node.node_type == :element}"
|
||||
if node.node_type == :element
|
||||
#puts "node.name == #{name} => #{node.name == name}"
|
||||
if node.name == name
|
||||
#puts "node.namespace == #{ns.inspect} => #{node.namespace == ns}"
|
||||
end
|
||||
end
|
||||
!(node.node_type == :element and
|
||||
|
@ -204,10 +178,7 @@ module REXML
|
|||
node_types = ELEMENTS
|
||||
|
||||
when :any
|
||||
#puts "ANY 1: nodeset = #{nodeset.inspect}"
|
||||
#puts "ANY 1: node_types = #{node_types.inspect}"
|
||||
nodeset.delete_if { |node| !node_types.include?(node.node_type) }
|
||||
#puts "ANY 2: nodeset = #{nodeset.inspect}"
|
||||
|
||||
when :self
|
||||
# This space left intentionally blank
|
||||
|
@ -250,15 +221,11 @@ module REXML
|
|||
name = path_stack.shift
|
||||
for element in nodeset
|
||||
if element.node_type == :element
|
||||
#puts "Element name = #{element.name}"
|
||||
#puts "get_namespace( #{element.inspect}, #{prefix} ) = #{get_namespace(element, prefix)}"
|
||||
attrib = element.attribute( name, get_namespace(element, prefix) )
|
||||
#puts "attrib = #{attrib.inspect}"
|
||||
new_nodeset << attrib if attrib
|
||||
end
|
||||
end
|
||||
when :any
|
||||
#puts "ANY"
|
||||
for element in nodeset
|
||||
if element.node_type == :element
|
||||
new_nodeset += element.attributes.to_a
|
||||
|
@ -268,10 +235,8 @@ module REXML
|
|||
nodeset = new_nodeset
|
||||
|
||||
when :parent
|
||||
#puts "PARENT 1: nodeset = #{nodeset}"
|
||||
nodeset = nodeset.collect{|n| n.parent}.compact
|
||||
#nodeset = expr(path_stack.dclone, nodeset.collect{|n| n.parent}.compact)
|
||||
#puts "PARENT 2: nodeset = #{nodeset.inspect}"
|
||||
node_types = ELEMENTS
|
||||
|
||||
when :ancestor
|
||||
|
@ -305,41 +270,30 @@ module REXML
|
|||
pred = path_stack.shift
|
||||
nodeset.each_with_index { |node, index|
|
||||
subcontext[ :node ] = node
|
||||
#puts "PREDICATE SETTING CONTEXT INDEX TO #{index+1}"
|
||||
subcontext[ :index ] = index+1
|
||||
pc = pred.dclone
|
||||
#puts "#{node.hash}) Recursing with #{pred.inspect} and [#{node.inspect}]"
|
||||
result = expr( pc, [node], subcontext )
|
||||
result = result[0] if result.kind_of? Array and result.length == 1
|
||||
#puts "#{node.hash}) Result = #{result.inspect} (#{result.class.name})"
|
||||
if result.kind_of? Numeric
|
||||
#puts "Adding node #{node.inspect}" if result == (index+1)
|
||||
new_nodeset << node if result == (index+1)
|
||||
elsif result.instance_of? Array
|
||||
if result.size > 0 and result.inject(false) {|k,s| s or k}
|
||||
#puts "Adding node #{node.inspect}" if result.size > 0
|
||||
new_nodeset << node if result.size > 0
|
||||
end
|
||||
else
|
||||
#puts "Adding node #{node.inspect}" if result
|
||||
new_nodeset << node if result
|
||||
end
|
||||
}
|
||||
#puts "New nodeset = #{new_nodeset.inspect}"
|
||||
#puts "Path_stack = #{path_stack.inspect}"
|
||||
nodeset = new_nodeset
|
||||
=begin
|
||||
predicate = path_stack.shift
|
||||
ns = nodeset.clone
|
||||
result = expr( predicate, ns )
|
||||
#puts "Result = #{result.inspect} (#{result.class.name})"
|
||||
#puts "nodeset = #{nodeset.inspect}"
|
||||
if result.kind_of? Array
|
||||
nodeset = result.zip(ns).collect{|m,n| n if m}.compact
|
||||
else
|
||||
nodeset = result ? nodeset : []
|
||||
end
|
||||
#puts "Outgoing NS = #{nodeset.inspect}"
|
||||
=end
|
||||
|
||||
when :descendant_or_self
|
||||
|
@ -360,7 +314,6 @@ module REXML
|
|||
node_types = ELEMENTS
|
||||
|
||||
when :following_sibling
|
||||
#puts "FOLLOWING_SIBLING 1: nodeset = #{nodeset}"
|
||||
results = []
|
||||
nodeset.each do |node|
|
||||
next if node.parent.nil?
|
||||
|
@ -369,7 +322,6 @@ module REXML
|
|||
following_siblings = all_siblings[ current_index+1 .. -1 ]
|
||||
results += expr( path_stack.dclone, following_siblings )
|
||||
end
|
||||
#puts "FOLLOWING_SIBLING 2: nodeset = #{nodeset}"
|
||||
nodeset = results
|
||||
|
||||
when :preceding_sibling
|
||||
|
@ -389,7 +341,6 @@ module REXML
|
|||
nodeset.each do |node|
|
||||
new_nodeset += preceding( node )
|
||||
end
|
||||
#puts "NEW NODESET => #{new_nodeset.inspect}"
|
||||
nodeset = new_nodeset
|
||||
node_types = ELEMENTS
|
||||
|
||||
|
@ -402,7 +353,6 @@ module REXML
|
|||
node_types = ELEMENTS
|
||||
|
||||
when :namespace
|
||||
#puts "In :namespace"
|
||||
new_nodeset = []
|
||||
prefix = path_stack.shift
|
||||
nodeset.each do |node|
|
||||
|
@ -414,9 +364,6 @@ module REXML
|
|||
else
|
||||
namespaces = node.element.namesapces
|
||||
end
|
||||
#puts "Namespaces = #{namespaces.inspect}"
|
||||
#puts "Prefix = #{prefix.inspect}"
|
||||
#puts "Node.namespace = #{node.namespace}"
|
||||
if (node.namespace == namespaces[prefix])
|
||||
new_nodeset << node
|
||||
end
|
||||
|
@ -434,24 +381,18 @@ module REXML
|
|||
# :or and false for :and).
|
||||
when :eq, :neq, :lt, :lteq, :gt, :gteq, :or
|
||||
left = expr( path_stack.shift, nodeset.dup, context )
|
||||
#puts "LEFT => #{left.inspect} (#{left.class.name})"
|
||||
right = expr( path_stack.shift, nodeset.dup, context )
|
||||
#puts "RIGHT => #{right.inspect} (#{right.class.name})"
|
||||
res = equality_relational_compare( left, op, right )
|
||||
#puts "RES => #{res.inspect}"
|
||||
return res
|
||||
|
||||
when :and
|
||||
left = expr( path_stack.shift, nodeset.dup, context )
|
||||
#puts "LEFT => #{left.inspect} (#{left.class.name})"
|
||||
return [] unless left
|
||||
if left.respond_to?(:inject) and !left.inject(false) {|a,b| a | b}
|
||||
return []
|
||||
end
|
||||
right = expr( path_stack.shift, nodeset.dup, context )
|
||||
#puts "RIGHT => #{right.inspect} (#{right.class.name})"
|
||||
res = equality_relational_compare( left, op, right )
|
||||
#puts "RES => #{res.inspect}"
|
||||
return res
|
||||
|
||||
when :div
|
||||
|
@ -492,7 +433,6 @@ module REXML
|
|||
when :function
|
||||
func_name = path_stack.shift.tr('-','_')
|
||||
arguments = path_stack.shift
|
||||
#puts "FUNCTION 0: #{func_name}(#{arguments.collect{|a|a.inspect}.join(', ')})"
|
||||
subcontext = context ? nil : { :size => nodeset.size }
|
||||
|
||||
res = []
|
||||
|
@ -505,19 +445,15 @@ module REXML
|
|||
end
|
||||
arg_clone = arguments.dclone
|
||||
args = arg_clone.collect { |arg|
|
||||
#puts "FUNCTION 1: Calling expr( #{arg.inspect}, [#{n.inspect}] )"
|
||||
expr( arg, [n], cont )
|
||||
}
|
||||
#puts "FUNCTION 2: #{func_name}(#{args.collect{|a|a.inspect}.join(', ')})"
|
||||
Functions.context = cont
|
||||
res << Functions.send( func_name, *args )
|
||||
#puts "FUNCTION 3: #{res[-1].inspect}"
|
||||
}
|
||||
return res
|
||||
|
||||
end
|
||||
end # while
|
||||
#puts "EXPR returning #{nodeset.inspect}"
|
||||
return nodeset
|
||||
end
|
||||
|
||||
|
@ -532,21 +468,15 @@ module REXML
|
|||
|
||||
def descendant_or_self( path_stack, nodeset )
|
||||
rs = []
|
||||
#puts "#"*80
|
||||
#puts "PATH_STACK = #{path_stack.inspect}"
|
||||
#puts "NODESET = #{nodeset.collect{|n|n.inspect}.inspect}"
|
||||
d_o_s( path_stack, nodeset, rs )
|
||||
#puts "RS = #{rs.collect{|n|n.inspect}.inspect}"
|
||||
document_order(rs.flatten.compact)
|
||||
#rs.flatten.compact
|
||||
end
|
||||
|
||||
def d_o_s( p, ns, r )
|
||||
#puts "IN DOS with #{ns.inspect}; ALREADY HAVE #{r.inspect}"
|
||||
nt = nil
|
||||
ns.each_index do |i|
|
||||
n = ns[i]
|
||||
#puts "P => #{p.inspect}"
|
||||
x = expr( p.dclone, [ n ] )
|
||||
nt = n.node_type
|
||||
d_o_s( p, n.children, x ) if nt == :element or nt == :document and n.children.size > 0
|
||||
|
@ -574,7 +504,6 @@ module REXML
|
|||
end
|
||||
new_arry << [ node_idx.reverse, node ]
|
||||
}
|
||||
#puts "new_arry = #{new_arry.inspect}"
|
||||
new_arry.sort{ |s1, s2| s1[0] <=> s2[0] }.collect{ |s| s[1] }
|
||||
end
|
||||
|
||||
|
@ -593,7 +522,6 @@ module REXML
|
|||
# preceding:: includes every element in the document that precedes this node,
|
||||
# except for ancestors
|
||||
def preceding( node )
|
||||
#puts "IN PRECEDING"
|
||||
ancestors = []
|
||||
p = node.parent
|
||||
while p
|
||||
|
@ -603,7 +531,6 @@ module REXML
|
|||
|
||||
acc = []
|
||||
p = preceding_node_of( node )
|
||||
#puts "P = #{p.inspect}"
|
||||
while p
|
||||
if ancestors.include? p
|
||||
ancestors.delete(p)
|
||||
|
@ -611,15 +538,11 @@ module REXML
|
|||
acc << p
|
||||
end
|
||||
p = preceding_node_of( p )
|
||||
#puts "P = #{p.inspect}"
|
||||
end
|
||||
acc
|
||||
end
|
||||
|
||||
def preceding_node_of( node )
|
||||
#puts "NODE: #{node.inspect}"
|
||||
#puts "PREVIOUS NODE: #{node.previous_sibling_node.inspect}"
|
||||
#puts "PARENT NODE: #{node.parent}"
|
||||
psn = node.previous_sibling_node
|
||||
if psn.nil?
|
||||
if node.parent.nil? or node.parent.class == Document
|
||||
|
@ -635,22 +558,16 @@ module REXML
|
|||
end
|
||||
|
||||
def following( node )
|
||||
#puts "IN PRECEDING"
|
||||
acc = []
|
||||
p = next_sibling_node( node )
|
||||
#puts "P = #{p.inspect}"
|
||||
while p
|
||||
acc << p
|
||||
p = following_node_of( p )
|
||||
#puts "P = #{p.inspect}"
|
||||
end
|
||||
acc
|
||||
end
|
||||
|
||||
def following_node_of( node )
|
||||
#puts "NODE: #{node.inspect}"
|
||||
#puts "PREVIOUS NODE: #{node.previous_sibling_node.inspect}"
|
||||
#puts "PARENT NODE: #{node.parent}"
|
||||
if node.kind_of? Element and node.children.size > 0
|
||||
return node.children[0]
|
||||
end
|
||||
|
@ -665,7 +582,6 @@ module REXML
|
|||
end
|
||||
node = node.parent
|
||||
psn = node.next_sibling_node
|
||||
#puts "psn = #{psn.inspect}"
|
||||
end
|
||||
return psn
|
||||
end
|
||||
|
@ -684,22 +600,17 @@ module REXML
|
|||
end
|
||||
|
||||
def equality_relational_compare( set1, op, set2 )
|
||||
#puts "EQ_REL_COMP(#{set1.inspect} #{op.inspect} #{set2.inspect})"
|
||||
if set1.kind_of? Array and set2.kind_of? Array
|
||||
#puts "#{set1.size} & #{set2.size}"
|
||||
if set1.size == 1 and set2.size == 1
|
||||
set1 = set1[0]
|
||||
set2 = set2[0]
|
||||
elsif set1.size == 0 or set2.size == 0
|
||||
nd = set1.size==0 ? set2 : set1
|
||||
rv = nd.collect { |il| compare( il, op, nil ) }
|
||||
#puts "RV = #{rv.inspect}"
|
||||
return rv
|
||||
else
|
||||
res = []
|
||||
SyncEnumerator.new( set1, set2 ).each { |i1, i2|
|
||||
#puts "i1 = #{i1.inspect} (#{i1.class.name})"
|
||||
#puts "i2 = #{i2.inspect} (#{i2.class.name})"
|
||||
i1 = norm( i1 )
|
||||
i2 = norm( i2 )
|
||||
res << compare( i1, op, i2 )
|
||||
|
@ -707,8 +618,6 @@ module REXML
|
|||
return res
|
||||
end
|
||||
end
|
||||
#puts "EQ_REL_COMP: #{set1.inspect} (#{set1.class.name}), #{op}, #{set2.inspect} (#{set2.class.name})"
|
||||
#puts "COMPARING VALUES"
|
||||
# If one is nodeset and other is number, compare number to each item
|
||||
# in nodeset s.t. number op number(string(item))
|
||||
# If one is nodeset and other is string, compare string to each item
|
||||
|
@ -716,7 +625,6 @@ module REXML
|
|||
# If one is nodeset and other is boolean, compare boolean to each item
|
||||
# in nodeset s.t. boolean op boolean(item)
|
||||
if set1.kind_of? Array or set2.kind_of? Array
|
||||
#puts "ISA ARRAY"
|
||||
if set1.kind_of? Array
|
||||
a = set1
|
||||
b = set2
|
||||
|
@ -732,10 +640,8 @@ module REXML
|
|||
return a.collect {|v| compare( Functions::number(v), op, b )}
|
||||
when /^\d+(\.\d+)?$/
|
||||
b = Functions::number( b )
|
||||
#puts "B = #{b.inspect}"
|
||||
return a.collect {|v| compare( Functions::number(v), op, b )}
|
||||
else
|
||||
#puts "Functions::string( #{b}(#{b.class.name}) ) = #{Functions::string(b)}"
|
||||
b = Functions::string( b )
|
||||
return a.collect { |v| compare( Functions::string(v), op, b ) }
|
||||
end
|
||||
|
@ -749,10 +655,7 @@ module REXML
|
|||
# Convert both to numbers and compare
|
||||
s1 = set1.to_s
|
||||
s2 = set2.to_s
|
||||
#puts "EQ_REL_COMP: #{set1}=>#{s1}, #{set2}=>#{s2}"
|
||||
if s1 == 'true' or s1 == 'false' or s2 == 'true' or s2 == 'false'
|
||||
#puts "Functions::boolean(#{set1})=>#{Functions::boolean(set1)}"
|
||||
#puts "Functions::boolean(#{set2})=>#{Functions::boolean(set2)}"
|
||||
set1 = Functions::boolean( set1 )
|
||||
set2 = Functions::boolean( set2 )
|
||||
else
|
||||
|
@ -769,15 +672,12 @@ module REXML
|
|||
set2 = Functions::number( set2 )
|
||||
end
|
||||
end
|
||||
#puts "EQ_REL_COMP: #{set1} #{op} #{set2}"
|
||||
#puts ">>> #{compare( set1, op, set2 )}"
|
||||
return compare( set1, op, set2 )
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def compare a, op, b
|
||||
#puts "COMPARE #{a.inspect}(#{a.class.name}) #{op} #{b.inspect}(#{b.class.name})"
|
||||
case op
|
||||
when :eq
|
||||
a == b
|
||||
|
|
Loading…
Reference in a new issue