1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* Fixed the inheritance bug in the pull parser that James Britt found.

* Indentation changes, and changed some exceptions to runtime
  exceptions.
* Backed out the patch that changed the versions
* Wasn't including Text class.
* Fixes issue:25 (Trac)
* Fixes ticket:3 (Issue38 in Roundup.)
* Numerous fixes in the XPath interpreter correcting, among other
  things, ordering bugs and some incorrect behavior.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ser 2005-08-12 12:08:52 +00:00
parent 1b12d598f8
commit 69e5c7d297
15 changed files with 792 additions and 786 deletions

View file

@ -101,20 +101,20 @@ module REXML
end
@unnormalized = nil
@value = @normalized = Text::normalize( @value, doctype )
@normalized = Text::normalize( @value, doctype )
end
# Returns the UNNORMALIZED value of this attribute. That is, entities
# have been expanded to their values
def value
@unnormalized if @unnormalized
return @unnormalized if @unnormalized
doctype = nil
if @element
doc = @element.document
doctype = doc.doctype if doc
end
@normalized = nil
@value = @unnormalized = Text::unnormalize( @value, doctype )
@unnormalized = Text::unnormalize( @value, doctype )
end
# Returns a copy of this attribute

View file

@ -158,12 +158,12 @@ module REXML
# unable to parse proper XML, we have to provide a hack to generate XML
# that IE's limited abilities can handle. This hack inserts a space
# before the /> on empty tags. Defaults to false
def write( output=$stdout, indent_level=-1, transitive=false, ie_hack=false )
def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
output = Output.new( output, xml_decl.encoding ) if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
@children.each { |node|
indent( output, indent_level ) if node.node_type == :element
if node.write( output, indent_level, transitive, ie_hack )
output << "\n" unless indent_level<0 or node == @children[-1]
indent( output, indent ) if node.node_type == :element
if node.write( output, indent, transitive, ie_hack )
output << "\n" unless indent<0 or node == @children[-1]
end
}
end

View file

@ -36,8 +36,6 @@ module REXML
# If an Element, the object will be shallowly cloned; name,
# attributes, and namespaces will be copied. Children will +not+ be
# copied.
# If a Source, the source will be scanned and parsed for an Element,
# and all child elements will be recursively parsed as well.
# parent::
# if supplied, must be a Parent, and will be used as
# the parent of this object.
@ -223,7 +221,7 @@ module REXML
# b.namespace("y") # -> '2'
def namespace(prefix=nil)
if prefix.nil?
prefix = self.prefix()
prefix = prefix()
end
if prefix == ''
prefix = "xmlns"

View file

@ -339,6 +339,8 @@ module REXML
end
def Functions::sum( nodes )
nodes = [nodes] unless nodes.kind_of? Array
nodes.inject(0) { |r,n| r += number(string(n)) }
end
def Functions::floor( number )

View file

@ -38,8 +38,8 @@ module REXML
Instruction.new self
end
def write writer, indent_level=-1, transitive=false, ie_hack=false
indent(writer, indent_level)
def write writer, indent=-1, transitive=false, ie_hack=false
indent(writer, indent)
writer << START.sub(/\\/u, '')
writer << @target
writer << ' '

View file

@ -1,3 +1,5 @@
require 'forwardable'
require 'rexml/parseexception'
require 'rexml/parsers/baseparser'
require 'rexml/xmltokens'
@ -25,11 +27,17 @@ module REXML
# Nat Price gave me some good ideas for the API.
class PullParser
include XMLTokens
extend Forwardable
def_delegators( :@parser, :has_next? )
def_delegators( :@parser, :entity )
def_delegators( :@parser, :empty? )
def initialize stream
@entities = {}
@listeners = nil
@parser = BaseParser.new( stream )
@my_stack = []
end
def add_listener( listener )
@ -44,14 +52,18 @@ module REXML
end
def peek depth=0
PullEvent.new(@parser.peek(depth))
if @my_stack.length <= depth
(depth - @my_stack.length + 1).times {
e = PullEvent.new(@parser.pull)
@my_stack.push(e)
}
end
def has_next?
@parser.has_next?
@my_stack[depth]
end
def pull
return @my_stack.shift if @my_stack.length > 0
event = @parser.pull
case event[0]
when :entitydecl
@ -65,17 +77,8 @@ module REXML
end
def unshift token
@parser.unshift token
@my_stack.unshift token
end
def entity reference
@parser.entity( reference )
end
def empty?
@parser.empty?
end
end
# A parsing event. The contents of the event are accessed as an +Array?,

View file

@ -1,9 +1,11 @@
require 'rexml/parsers/baseparser'
require 'rexml/parseexception'
require 'rexml/namespace'
require 'rexml/text'
module REXML
module Parsers
# SAX2Parser
class SAX2Parser
def initialize source
@parser = BaseParser.new(source)
@ -37,6 +39,10 @@ module REXML
# :processing_instruction, :doctype, :attlistdecl, :elementdecl,
# :entitydecl, :notationdecl, :cdata, :xmldecl, :comment
#
# There is an additional symbol that can be listened for: :progress.
# This will be called for every event generated, passing in the current
# stream position.
#
# Array contains regular expressions or strings which will be matched
# against fully qualified element names.
#
@ -161,6 +167,7 @@ module REXML
:elementdecl, :cdata, :notationdecl, :xmldecl
handle( *event )
end
handle( :progress, @parser.source.position )
end
end

View file

@ -11,7 +11,7 @@
# Main page:: http://www.germane-software.com/software/rexml
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
# Version:: 3.1.3
# Date:: +2005/138
# Date:: 2005/224
#
# This API documentation can be downloaded from the REXML home page, or can
# be accessed online[http://www.germane-software.com/software/rexml_doc]
@ -20,7 +20,7 @@
# or can be accessed
# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
module REXML
Copyright = "Copyright © 2001-2005 Sean Russell <ser@germane-software.com>"
Date = "+2005/138"
Copyright = "Copyright © 2001, 2002, 2003, 2004 Sean Russell <ser@germane-software.com>"
Date = "2005/224"
Version = "3.1.3"
end

View file

@ -90,5 +90,7 @@ module REXML
# @p comment The content of the comment
def comment comment
end
def progress position
end
end
end

View file

@ -98,6 +98,10 @@ module REXML
@buffer == ""
end
def position
@orig.index( @buffer )
end
# @return the current line in the source
def current_line
lines = @orig.split
@ -194,6 +198,10 @@ module REXML
super and ( @source.nil? || @source.eof? )
end
def position
@er_source.pos
end
# @return the current line in the source
def current_line
begin

View file

@ -82,10 +82,13 @@ module REXML
@event_arg = event_arg
end
attr_reader :done?
attr_reader :event_type
attr_accessor :event_arg
def done?
@done
end
def single?
return (@event_type != :start_element and @event_type != :start_attribute)
end

View file

@ -37,9 +37,9 @@ module REXML
XMLDecl.new(self)
end
def write writer, indent_level=-1, transitive=false, ie_hack=false
def write writer, indent=-1, transitive=false, ie_hack=false
return nil unless @writethis or writer.kind_of? Output
indent( writer, indent_level )
indent( writer, indent )
writer << START.sub(/\\/u, '')
if writer.kind_of? Output
writer << " #{content writer.encoding}"

View file

@ -20,16 +20,6 @@ module REXML
# XPath.first( doc, "//b"} )
# XPath.first( node, "a/x:b", { "x"=>"http://doofus" } )
def XPath::first element, path=nil, namespaces={}, variables={}
=begin
raise "The namespaces argument, if supplied, must be a hash object." unless namespaces.kind_of? Hash
raise "The variables argument, if supplied, must be a hash object." unless variables.kind_of? Hash
parser = XPathParser.new
parser.namespaces = namespaces
parser.variables = variables
path = "*" unless path
parser.first( path, element );
=end
#=begin
raise "The namespaces argument, if supplied, must be a hash object." unless namespaces.kind_of? Hash
raise "The variables argument, if supplied, must be a hash object." unless variables.kind_of? Hash
parser = XPathParser.new
@ -38,7 +28,6 @@ module REXML
path = "*" unless path
element = [element] unless element.kind_of? Array
parser.parse(path, element).flatten[0]
#=end
end
# Itterates over nodes that match the given path, calling the supplied

View file

@ -76,6 +76,8 @@ module REXML
# Performs a depth-first (document order) XPath search, and returns the
# first match. This is the fastest, lightest way to return a single result.
#
# FIXME: This method is incomplete!
def first( path_stack, node )
#puts "#{depth}) Entering match( #{path.inspect}, #{tree.inspect} )"
return nil if path.size == 0
@ -123,14 +125,6 @@ module REXML
r = expr( path_stack, nodeset )
#puts "MAIN EXPR => #{r.inspect}"
r
#while ( path_stack.size > 0 and nodeset.size > 0 )
# #puts "MATCH: #{path_stack.inspect} '#{nodeset.collect{|n|n.class}.inspect}'"
# nodeset = expr( path_stack, nodeset )
# #puts "NODESET: #{nodeset.inspect}"
# #puts "PATH_STACK: #{path_stack.inspect}"
#end
#nodeset
end
private