summaryrefslogtreecommitdiffstats
path: root/lib/rexml/xpath_parser.rb
diff options
context:
space:
mode:
authorser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-04 15:39:05 +0000
committerser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-04 15:39:05 +0000
commit672b0304fbce0a2f72b763b7a809c81ae9f17244 (patch)
tree526863f5aa43f0870a611103ca307043d81e4904 /lib/rexml/xpath_parser.rb
parent41d6e7c60133613db75130fa5a0d300f20a2dcbc (diff)
downloadruby-672b0304fbce0a2f72b763b7a809c81ae9f17244.tar.gz
ruby-672b0304fbce0a2f72b763b7a809c81ae9f17244.tar.xz
ruby-672b0304fbce0a2f72b763b7a809c81ae9f17244.zip
* Added the treeparser, and added the file to the MANIFEST.
r1002 | ser | 2004-06-07 07:45:53 -0400 (Mon, 07 Jun 2004) | 2 lines * Workin' in the coal mine, goin' down, down, down... r1003 | ser | 2004-06-08 22:24:08 -0400 (Tue, 08 Jun 2004) | 7 lines * Entirely rewrote the validation code; the finite state machine, while cool, didn't survive the encounter with Interleave. It was getting sort of hacky, too. The new mechanism is less elegant, but is basically still a FSM, and is more flexible without having to add hacks to extend it. Large chunks of the FSM may be reusable in other validation mechanisms. * Added interleave support r1004 | ser | 2004-06-09 07:24:17 -0400 (Wed, 09 Jun 2004) | 2 lines * Added suppert for mixed r1005 | ser | 2004-06-09 08:01:33 -0400 (Wed, 09 Jun 2004) | 3 lines * Added Kou's patch to normalize attribute values passed through the SAX2 and Stream parsers. r1006 | ser | 2004-06-09 08:12:35 -0400 (Wed, 09 Jun 2004) | 2 lines * Applied Kou's preceding-sibling patch, which fixes the order of the axe results r1009 | ser | 2004-06-20 11:02:55 -0400 (Sun, 20 Jun 2004) | 8 lines * Redesigned and rewrote the RelaxNG code. It isn't elegant, but it works. Particular problems encountered were interleave and ref. Interleave means I can't use a clean FSM design, and ref means the dirty FSM design has to be modified during validation. There's a lot of code that could be cleaned up in here. However, I'm pretty sure that this design is reasonably fast and space efficient. I'm not entirely convinced that it is correct; more tests are required. * This version adds support for defines and refs. r1011 | ser | 2004-06-20 11:20:07 -0400 (Sun, 20 Jun 2004) | 3 lines * Removed debugging output from unit test * Moved ">" in Element.inspect r1014 | ser | 2004-06-20 11:40:30 -0400 (Sun, 20 Jun 2004) | 2 lines * Minor big in missing includes for validation rules r1023 | ser | 2004-07-03 08:57:34 -0400 (Sat, 03 Jul 2004) | 2 lines * Fixed bug #34, typo in xpath_parser. r1024 | ser | 2004-07-03 10:22:08 -0400 (Sat, 03 Jul 2004) | 9 lines * Previous fix, (include? -> includes?) was incorrect. * Added another test for encoding * Started AnyName support in RelaxNG * Added Element#Attributes#to_a, so that it does something intelligent. This was needed by XPath, for '@*' * Fixed XPath so that @* works. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6579 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/xpath_parser.rb')
-rw-r--r--lib/rexml/xpath_parser.rb28
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb
index 8aadb8ef8..5a976d5e8 100644
--- a/lib/rexml/xpath_parser.rb
+++ b/lib/rexml/xpath_parser.rb
@@ -43,8 +43,6 @@ module REXML
@variables[ variable_name ] = value
end
- private
-
def match( path_stack, nodeset )
while ( path_stack.size > 0 and nodeset.size > 0 )
#puts "PARSE: #{path_stack.inspect} '#{nodeset.collect{|n|n.class}.inspect}'"
@@ -55,6 +53,8 @@ module REXML
nodeset
end
+ private
+
def internal_parse path_stack, nodeset
#puts "INTERNAL_PARSE RETURNING WITH NO RESULTS" if nodeset.size == 0 or path_stack.size == 0
return nodeset if nodeset.size == 0 or path_stack.size == 0
@@ -151,13 +151,14 @@ module REXML
end
end
when :any
+ #puts "ANY"
for element in nodeset
if element.node_type == :element
- attr = element.attributes
+ new_nodeset += element.attributes.to_a
end
end
end
- #puts "RETURNING #{new_nodeset.collect{|n|n.to_s}.inspect}"
+ #puts "RETURNING #{new_nodeset.collect{|n|n.to_s}.inspect}"
return new_nodeset
when :parent
@@ -182,7 +183,7 @@ module REXML
new_nodeset << node
while ( node.parent )
node = node.parent
- new_nodeset << node unless new_nodeset.includes? node
+ new_nodeset << node unless new_nodeset.include? node
end
end
end
@@ -423,17 +424,15 @@ module REXML
current_index = all_siblings.index( node )
preceding_siblings = all_siblings[ 0 .. current_index-1 ]
- preceding_siblings.reverse!
preceding = []
- recurse( preceding_siblings ) { |node| preceding << node }
- preceding.reverse
+ recurse( preceding_siblings ) { |node| preceding.unshift( node ) }
+ preceding
end
def equality_relational_compare( set1, op, set2 )
- #puts "EQ_REL_COMP: #{set1.to_s}, #{op}, #{set2.to_s}"
- #puts "#{set1.class.name} #{op} #{set2.class.name}"
+ #puts "#"*80
if set1.kind_of? Array and set2.kind_of? Array
- #puts "#{set1.size} & #{set2.size}"
+ #puts "#{set1.size} & #{set2.size}"
if set1.size == 1 and set2.size == 1
set1 = set1[0]
set2 = set2[0]
@@ -451,6 +450,7 @@ module REXML
return false
end
end
+ #puts "EQ_REL_COMP: #{set1.class.name} #{set1.inspect}, #{op}, #{set2.class.name} #{set2.inspect}"
#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))
@@ -459,7 +459,7 @@ 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"
+ #puts "ISA ARRAY"
if set1.kind_of? Array
a = set1
b = set2.to_s
@@ -486,8 +486,10 @@ module REXML
return true if compare( v, op, b )
end
else
+ #puts "Functions::string( #{b}(#{b.class.name}) ) = #{Functions::string(b)}"
b = Functions::string( b )
for v in a
+ #puts "v = #{v.class.name} #{v.inspect}"
v = Functions::string(v)
return true if compare( v, op, b )
end
@@ -530,7 +532,7 @@ module REXML
end
def compare a, op, b
- #puts "COMPARE #{a.to_s} #{op} #{b.to_s}"
+ #puts "COMPARE #{a.to_s}(#{a.class.name}) #{op} #{b.to_s}(#{a.class.name})"
case op
when :eq
a == b