mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
rexml: Add codes for debugging XPath logic
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63087 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1d6ca665f5
commit
478d3dffa2
1 changed files with 26 additions and 0 deletions
|
@ -51,6 +51,7 @@ module REXML
|
||||||
@parser = REXML::Parsers::XPathParser.new
|
@parser = REXML::Parsers::XPathParser.new
|
||||||
@namespaces = nil
|
@namespaces = nil
|
||||||
@variables = {}
|
@variables = {}
|
||||||
|
@nest = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def namespaces=( namespaces={} )
|
def namespaces=( namespaces={} )
|
||||||
|
@ -151,9 +152,11 @@ module REXML
|
||||||
ALL = [ :attribute, :element, :text, :processing_instruction, :comment ]
|
ALL = [ :attribute, :element, :text, :processing_instruction, :comment ]
|
||||||
ELEMENTS = [ :element ]
|
ELEMENTS = [ :element ]
|
||||||
def expr( path_stack, nodeset, context=nil )
|
def expr( path_stack, nodeset, context=nil )
|
||||||
|
# enter(:expr, path_stack, nodeset)
|
||||||
node_types = ELEMENTS
|
node_types = ELEMENTS
|
||||||
return nodeset if path_stack.length == 0 || nodeset.length == 0
|
return nodeset if path_stack.length == 0 || nodeset.length == 0
|
||||||
while path_stack.length > 0
|
while path_stack.length > 0
|
||||||
|
# trace(:while, path_stack, nodeset)
|
||||||
if nodeset.length == 0
|
if nodeset.length == 0
|
||||||
path_stack.clear
|
path_stack.clear
|
||||||
return []
|
return []
|
||||||
|
@ -165,6 +168,7 @@ module REXML
|
||||||
when :qname
|
when :qname
|
||||||
prefix = path_stack.shift
|
prefix = path_stack.shift
|
||||||
name = path_stack.shift
|
name = path_stack.shift
|
||||||
|
# enter(:qname, path_stack, prefix, name, nodeset)
|
||||||
nodeset.delete_if do |node|
|
nodeset.delete_if do |node|
|
||||||
# FIXME: This DOUBLES the time XPath searches take
|
# FIXME: This DOUBLES the time XPath searches take
|
||||||
ns = get_namespace( node, prefix )
|
ns = get_namespace( node, prefix )
|
||||||
|
@ -176,6 +180,7 @@ module REXML
|
||||||
node.name == name and
|
node.name == name and
|
||||||
node.namespace == ns )
|
node.namespace == ns )
|
||||||
end
|
end
|
||||||
|
# leave(:qname, path_stack, nodeset)
|
||||||
node_types = ELEMENTS
|
node_types = ELEMENTS
|
||||||
|
|
||||||
when :any
|
when :any
|
||||||
|
@ -206,12 +211,14 @@ module REXML
|
||||||
nt = nil
|
nt = nil
|
||||||
nodeset.each do |node|
|
nodeset.each do |node|
|
||||||
nt = node.node_type
|
nt = node.node_type
|
||||||
|
# trace(:child, nt, node)
|
||||||
new_nodeset += node.children if nt == :element or nt == :document
|
new_nodeset += node.children if nt == :element or nt == :document
|
||||||
end
|
end
|
||||||
nodeset = new_nodeset
|
nodeset = new_nodeset
|
||||||
node_types = ELEMENTS
|
node_types = ELEMENTS
|
||||||
|
|
||||||
when :literal
|
when :literal
|
||||||
|
# trace(:literal, path_stack, nodeset)
|
||||||
return path_stack.shift
|
return path_stack.shift
|
||||||
|
|
||||||
when :attribute
|
when :attribute
|
||||||
|
@ -277,6 +284,7 @@ module REXML
|
||||||
new_nodeset = []
|
new_nodeset = []
|
||||||
subcontext = { :size => nodeset.size }
|
subcontext = { :size => nodeset.size }
|
||||||
pred = path_stack.shift
|
pred = path_stack.shift
|
||||||
|
# enter(:predicate, pred, nodeset)
|
||||||
nodeset.each_with_index { |node, index|
|
nodeset.each_with_index { |node, index|
|
||||||
subcontext[ :node ] = node
|
subcontext[ :node ] = node
|
||||||
subcontext[ :index ] = index+1
|
subcontext[ :index ] = index+1
|
||||||
|
@ -294,6 +302,7 @@ module REXML
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
nodeset = new_nodeset
|
nodeset = new_nodeset
|
||||||
|
# leave(:predicate_return, nodeset)
|
||||||
=begin
|
=begin
|
||||||
predicate = path_stack.shift
|
predicate = path_stack.shift
|
||||||
ns = nodeset.clone
|
ns = nodeset.clone
|
||||||
|
@ -393,6 +402,7 @@ module REXML
|
||||||
left = expr( path_stack.shift, nodeset.dup, context )
|
left = expr( path_stack.shift, nodeset.dup, context )
|
||||||
right = expr( path_stack.shift, nodeset.dup, context )
|
right = expr( path_stack.shift, nodeset.dup, context )
|
||||||
res = equality_relational_compare( left, op, right )
|
res = equality_relational_compare( left, op, right )
|
||||||
|
# trace(op, left, right, res)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
when :and
|
when :and
|
||||||
|
@ -465,8 +475,24 @@ module REXML
|
||||||
end
|
end
|
||||||
end # while
|
end # while
|
||||||
return nodeset
|
return nodeset
|
||||||
|
# ensure
|
||||||
|
# leave(:expr, path_stack, nodeset)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def trace(*args)
|
||||||
|
indent = " " * @nest
|
||||||
|
puts("#{indent}#{args.inspect}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def enter(tag, *args)
|
||||||
|
trace(:enter, tag, *args)
|
||||||
|
@nest += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def leave(tag, *args)
|
||||||
|
@nest -= 1
|
||||||
|
trace(:leave, tag, *args)
|
||||||
|
end
|
||||||
|
|
||||||
##########################################################
|
##########################################################
|
||||||
# FIXME
|
# FIXME
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue