REXML hadn't been tested with Ruby 1.8.0, which was really, really,

unbelievably stupid of me.  There were a lot of warnings and some errors
that were caused by Block vs. Proc differences; these have been fixed.
REXML passes all of the tests under Ruby 1.8.0.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ser 2003-06-15 18:31:16 +00:00
parent 4d33715fe4
commit 2403ad9e7d
5 changed files with 28 additions and 26 deletions

View File

@ -42,7 +42,9 @@ module REXML
if node.kind_of? String if node.kind_of? String
node = [ :text, node ] node = [ :text, node ]
elsif node.nil? elsif node.nil?
node = [ :start_document, nil, nil ] node = [ :document, nil, nil ]
elsif node[0] == :start_element
node[0] = :element
end end
replace( node ) replace( node )
_old_put( 1, 0, 1 ) _old_put( 1, 0, 1 )
@ -117,6 +119,10 @@ module REXML
end end
end end
def =~( path )
XPath.match( self, path )
end
# Doesn't handle namespaces yet # Doesn't handle namespaces yet
def []=( reference, ns, value=nil ) def []=( reference, ns, value=nil )
el!() el!()
@ -139,7 +145,7 @@ module REXML
# object. Otherwise, the element argument is a string, the namespace (if # object. Otherwise, the element argument is a string, the namespace (if
# provided) is the namespace the element is created in. # provided) is the namespace the element is created in.
def << element def << element
if text? if node_type() == :text
at(-1) << element at(-1) << element
else else
newnode = Node.new( element ) newnode = Node.new( element )
@ -150,7 +156,7 @@ module REXML
end end
def node_type def node_type
self[0] _old_get(0)
end end
def text=( foo ) def text=( foo )
@ -163,10 +169,6 @@ module REXML
context = context.at(1) while context.at(1) context = context.at(1) while context.at(1)
end end
def element?
at(0) == :start_element
end
def has_name?( name, namespace = '' ) def has_name?( name, namespace = '' )
el!() el!()
at(3) == name and namespace() == namespace at(3) == name and namespace() == namespace
@ -181,19 +183,16 @@ module REXML
at(1) at(1)
end end
def text?
at(0) == :text
end
def to_s def to_s
end end
def el! def el!
if text?() if node_type() != :element and node_type() != :document
_old_put( 0, :start_element ) _old_put( 0, :element )
push({}) push({})
end end
self
end end
private private

View File

@ -23,14 +23,15 @@ module REXML
# #
# Nat Price gave me some good ideas for the API. # Nat Price gave me some good ideas for the API.
class BaseParser class BaseParser
NCNAME_STR= '[\w:][-\w\d.]*' NCNAME_STR= '[\w:][\-\w\d.]*'
NAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}" NAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
NAMECHAR = '[-\w\d\.:]' NAMECHAR = '[\-\w\d\.:]'
NAME = "([\\w:]#{NAMECHAR}*)" NAME = "([\\w:]#{NAMECHAR}*)"
NMTOKEN = "(?:#{NAMECHAR})+" NMTOKEN = "(?:#{NAMECHAR})+"
NMTOKENS = "#{NMTOKEN}(\\s+#{NMTOKEN})*" NMTOKENS = "#{NMTOKEN}(\\s+#{NMTOKEN})*"
REFERENCE = "(?:&#{NAME};|&#\\d+;|&#x[0-9a-fA-F]+;)" REFERENCE = "(?:&#{NAME};|&#\\d+;|&#x[0-9a-fA-F]+;)"
REFERENCE_RE = /#{REFERENCE}/
DOCTYPE_START = /\A\s*<!DOCTYPE\s/um DOCTYPE_START = /\A\s*<!DOCTYPE\s/um
DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
@ -38,6 +39,7 @@ module REXML
COMMENT_START = /\A<!--/u COMMENT_START = /\A<!--/u
COMMENT_PATTERN = /<!--(.*?)-->/um COMMENT_PATTERN = /<!--(.*?)-->/um
CDATA_START = /\A<!\[CDATA\[/u CDATA_START = /\A<!\[CDATA\[/u
CDATA_END = /^\s*\]\s*>/um
CDATA_PATTERN = /<!\[CDATA\[(.*?)\]\]>/um CDATA_PATTERN = /<!\[CDATA\[(.*?)\]\]>/um
XMLDECL_START = /\A<\?xml\s/u; XMLDECL_START = /\A<\?xml\s/u;
XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um
@ -51,7 +53,7 @@ module REXML
STANDALONE = /\bstandalone=["'](.*?)['"]/um STANDALONE = /\bstandalone=["'](.*?)['"]/um
ENTITY_START = /^\s*<!ENTITY/ ENTITY_START = /^\s*<!ENTITY/
IDENTITY = /^([!\*\w-]+)(\s+#{NCNAME_STR})?(\s+["'].*?['"])?(\s+['"].*?["'])?/u IDENTITY = /^([!\*\w\-]+)(\s+#{NCNAME_STR})?(\s+["'].*?['"])?(\s+['"].*?["'])?/u
ELEMENTDECL_START = /^\s*<!ELEMENT/um ELEMENTDECL_START = /^\s*<!ELEMENT/um
ELEMENTDECL_PATTERN = /^\s*(<!ELEMENT.*?)>/um ELEMENTDECL_PATTERN = /^\s*(<!ELEMENT.*?)>/um
ENUMERATION = "\\(\\s*#{NMTOKEN}(?:\\s*\\|\\s*#{NMTOKEN})*\\s*\\)" ENUMERATION = "\\(\\s*#{NMTOKEN}(?:\\s*\\|\\s*#{NMTOKEN})*\\s*\\)"
@ -61,16 +63,17 @@ module REXML
ATTVALUE = "(?:\"((?:[^<&\"]|#{REFERENCE})*)\")|(?:'((?:[^<&']|#{REFERENCE})*)')" ATTVALUE = "(?:\"((?:[^<&\"]|#{REFERENCE})*)\")|(?:'((?:[^<&']|#{REFERENCE})*)')"
DEFAULTDECL = "(#REQUIRED|#IMPLIED|(?:(#FIXED\\s+)?#{ATTVALUE}))" DEFAULTDECL = "(#REQUIRED|#IMPLIED|(?:(#FIXED\\s+)?#{ATTVALUE}))"
ATTDEF = "\\s+#{NAME}\\s+#{ATTTYPE}\\s+#{DEFAULTDECL}" ATTDEF = "\\s+#{NAME}\\s+#{ATTTYPE}\\s+#{DEFAULTDECL}"
ATTDEF_RE = /#{ATTDEF}/
ATTLISTDECL_START = /^\s*<!ATTLIST/um ATTLISTDECL_START = /^\s*<!ATTLIST/um
ATTLISTDECL_PATTERN = /^\s*<!ATTLIST\s+#{NAME}(?:#{ATTDEF})*\s*>/um ATTLISTDECL_PATTERN = /^\s*<!ATTLIST\s+#{NAME}(?:#{ATTDEF})*\s*>/um
NOTATIONDECL_START = /^\s*<!NOTATION/um NOTATIONDECL_START = /^\s*<!NOTATION/um
PUBLIC = /^\s*<!NOTATION\s+(\w[-\w]*)\s+(PUBLIC)\s+((["']).*?\4)\s*>/um PUBLIC = /^\s*<!NOTATION\s+(\w[\-\w]*)\s+(PUBLIC)\s+((["']).*?\4)\s*>/um
SYSTEM = /^\s*<!NOTATION\s+(\w[-\w]*)\s+(SYSTEM)\s+((["']).*?\4)\s*>/um SYSTEM = /^\s*<!NOTATION\s+(\w[\-\w]*)\s+(SYSTEM)\s+((["']).*?\4)\s*>/um
TEXT_PATTERN = /\A([^<]*)/um TEXT_PATTERN = /\A([^<]*)/um
# Entity constants # Entity constants
PUBIDCHAR = "\x20\x0D\x0Aa-zA-Z0-9-()+,./:=?;!*@$_%#" PUBIDCHAR = "\x20\x0D\x0Aa-zA-Z0-9\\-()+,./:=?;!*@$_%#"
SYSTEMLITERAL = %Q{((?:"[^"]*")|(?:'[^']*'))} SYSTEMLITERAL = %Q{((?:"[^"]*")|(?:'[^']*'))}
PUBIDLITERAL = %Q{("[#{PUBIDCHAR}']*"|'[#{PUBIDCHAR}]*')} PUBIDLITERAL = %Q{("[#{PUBIDCHAR}']*"|'[#{PUBIDCHAR}]*')}
EXTERNALID = "(?:(?:(SYSTEM)\\s+#{SYSTEMLITERAL})|(?:(PUBLIC)\\s+#{PUBIDLITERAL}\\s+#{SYSTEMLITERAL}))" EXTERNALID = "(?:(?:(SYSTEM)\\s+#{SYSTEMLITERAL})|(?:(PUBLIC)\\s+#{PUBIDLITERAL}\\s+#{SYSTEMLITERAL}))"
@ -243,7 +246,7 @@ module REXML
contents = md[0] contents = md[0]
pairs = {} pairs = {}
values = md[0].scan( ATTDEF ) values = md[0].scan( ATTDEF_RE )
values.each do |attdef| values.each do |attdef|
unless attdef[3] == "#IMPLIED" unless attdef[3] == "#IMPLIED"
attdef.compact! attdef.compact!
@ -263,9 +266,9 @@ module REXML
raise REXML::ParseException.new( "error parsing notation: no matching pattern", @source ) raise REXML::ParseException.new( "error parsing notation: no matching pattern", @source )
end end
return [ :notationdecl, md[1], md[2], md[3] ] return [ :notationdecl, md[1], md[2], md[3] ]
when /^\s*\]\s*>/um when CDATA_END
@document_status = :after_doctype @document_status = :after_doctype
@source.match( /^\s*\]\s*>/um, true ) @source.match( CDATA_END, true )
return [ :end_doctype ] return [ :end_doctype ]
end end
end end
@ -358,7 +361,7 @@ module REXML
def unnormalize( string, entities=nil, filter=nil ) def unnormalize( string, entities=nil, filter=nil )
rv = string.clone rv = string.clone
rv.gsub!( /\r\n?/, "\n" ) rv.gsub!( /\r\n?/, "\n" )
matches = rv.scan( REFERENCE) matches = rv.scan( REFERENCE_RE )
return rv if matches.size == 0 return rv if matches.size == 0
rv.gsub!( /&#0*((?:\d+)|(?:x[a-fA-F0-9]+));/ ) {|m| rv.gsub!( /&#0*((?:\d+)|(?:x[a-fA-F0-9]+));/ ) {|m|
m=$1 m=$1

View File

@ -185,7 +185,7 @@ module REXML
end end
def add( pair ) def add( pair )
if pair[-1].kind_of? Proc if pair[-1].kind_of? Proc or (defined? Block and pair[-1].kind_of? Block)
@procs << pair unless @procs.include? pair @procs << pair unless @procs.include? pair
else else
@listeners << pair unless @listeners.include? pair @listeners << pair unless @listeners.include? pair

View File

@ -31,7 +31,7 @@ module REXML
results = filter([element], path) results = filter([element], path)
when /^\*/u when /^\*/u
results = filter(element.to_a, path) results = filter(element.to_a, path)
when /^[\[!\w:]/u when /^[[!\w:]/u
# match on child # match on child
matches = [] matches = []
children = element.to_a children = element.to_a

View File

@ -22,5 +22,5 @@
module REXML module REXML
Copyright = "Copyright #{Time.now.year} Sean Russell <ser@germane-software.com>" Copyright = "Copyright #{Time.now.year} Sean Russell <ser@germane-software.com>"
Date = "+2003/110" Date = "+2003/110"
Version = "2.7.0" Version = "2.7.1"
end end