From b72a0cd2ed849cb4bd0ad0d343727bfffb1ab3d5 Mon Sep 17 00:00:00 2001 From: Burak Emir Date: Thu, 1 Dec 2005 09:34:38 +0000 Subject: fixes bugs --- sources/scala/xml/PrettyPrinter.scala | 24 ++++----- sources/scala/xml/parsing/MarkupHandler.scala | 5 +- sources/scala/xml/parsing/MarkupParser.scala | 76 ++++++++++++++------------- 3 files changed, 51 insertions(+), 54 deletions(-) diff --git a/sources/scala/xml/PrettyPrinter.scala b/sources/scala/xml/PrettyPrinter.scala index 0e48042b48..2863930374 100644 --- a/sources/scala/xml/PrettyPrinter.scala +++ b/sources/scala/xml/PrettyPrinter.scala @@ -48,10 +48,10 @@ class PrettyPrinter( width:Int, step:Int ) { return List(Box(ind,s)); val sb = new StringBuffer(); var i = s.indexOf(' '); - if( i > tmp ) throw new BrokenException(); // cannot break + if(i > tmp || i == -1) throw new BrokenException(); // cannot break - var last = i::Nil; - while( i < tmp ) { + var last:List[Int] = Nil; + while(i < tmp) { last = i::last; i = s.indexOf(' ', i ); } @@ -121,16 +121,6 @@ class PrettyPrinter( width:Int, step:Int ) { sb.toString(); } - - protected def breakable( n:Node ):boolean = { - val it = n.child.elements; - while( it.hasNext ) - it.next match { - case _:Atom[Any] | _: Molecule[Any] | _:Comment | _:EntityRef | _:ProcInstr => - case _:Node => return true; - } - return false - } /** @param tail: what we'd like to sqeeze in */ protected def traverse( node:Node, pscope: NamespaceBinding, ind:int ):Unit = { node match { @@ -141,7 +131,7 @@ class PrettyPrinter( width:Int, step:Int ) { case _:Node => val sb = new StringBuffer(); val test = { Utility.toXML(node, pscope, sb, false); sb.toString()}; - if(( test.length() < width - cur )&&( !breakable( node ))){ // all ? + if( test.length() < width - cur ) { makeBox( ind, test ); } else { // start tag + content + end tag //Console.println(node.label+" ind="+ind); @@ -201,14 +191,20 @@ class PrettyPrinter( width:Int, step:Int ) { def format(n: Node, pscope:NamespaceBinding, sb: StringBuffer): Unit = { // entry point reset(); traverse( n, pscope, 0 ); + var last = 0; var cur = 0; //Console.println( items.reverse ); for( val b <- items.reverse ) b match { case Break => sb.append('\n'); // on windows: \r\n ? cur = 0; + while( cur < last ) { + sb.append(' '); + cur = cur + 1; + } case Box(i, s) => + last = i; while( cur < i ) { sb.append(' '); cur = cur + 1; diff --git a/sources/scala/xml/parsing/MarkupHandler.scala b/sources/scala/xml/parsing/MarkupHandler.scala index d2f35cc728..d90dea2752 100644 --- a/sources/scala/xml/parsing/MarkupHandler.scala +++ b/sources/scala/xml/parsing/MarkupHandler.scala @@ -42,8 +42,7 @@ abstract class MarkupHandler extends AnyRef with Logged { lookup(decls) } - def replacementText( entityName: String ): Source = { - ent.get(entityName) match { + def replacementText( entityName: String ): Source = ent.get(entityName) match { case Some(ParsedEntityDecl(_, IntDef(value))) => Source.fromString(value); case Some(ParameterEntityDecl(_, IntDef(value))) => @@ -53,7 +52,7 @@ abstract class MarkupHandler extends AnyRef with Logged { case None => Source.fromString("") } - } + //def checkChildren(pos:int, pre: String, label:String,ns:NodeSeq): Unit = {} diff --git a/sources/scala/xml/parsing/MarkupParser.scala b/sources/scala/xml/parsing/MarkupParser.scala index 6cf17ae6f4..18833c3efd 100644 --- a/sources/scala/xml/parsing/MarkupParser.scala +++ b/sources/scala/xml/parsing/MarkupParser.scala @@ -82,11 +82,12 @@ import scala.xml.dtd._ ; } /** <? prolog ::= xml S + * // this is a bit more lenient than necessary... */ def prolog(): Tuple3[Option[String], Option[String], Option[Boolean]] = { //Console.println("(DEBUG) prolog"); - + var n = 0; var info_ver: Option[String] = None; var info_enc: Option[String] = None; var info_stdl: Option[Boolean] = None; @@ -95,38 +96,32 @@ import scala.xml.dtd._ ; xSpace; - if (!m.isPrefixed && m.key == "version") { - if (m.value == "1.0") { - info_ver = Some("1.0"); - m = m.next; - } else { - reportSyntaxError("cannot deal with versions != 1.0"); - } - } else - reportSyntaxError("VersionInfo expected!"); - - if (!m.isPrefixed && m.key == "encoding") { - val enc = m.value; - if (!isValidIANAEncoding(enc)) - reportSyntaxError("\"" + enc + "\" is not a valid encoding"); - info_enc = Some(enc); - m = m.next + m.getValue("version") match { + case null => ; + case "1.0" => info_ver = Some("1.0"); n = n + 1; + case _ => reportSyntaxError("cannot deal with versions != 1.0"); } - if (!m.isPrefixed && m.key == "standalone") { - m.value match { - case "yes" => - info_stdl = Some(true); - case "no" => - info_stdl = Some(false); - case _ => - reportSyntaxError("either 'yes' or 'no' expected"); - } - m = m.next + m.getValue("encoding") match { + case null => ; + case enc => if (!isValidIANAEncoding(enc)) + reportSyntaxError("\"" + enc + "\" is not a valid encoding"); + else { + info_enc = Some(enc); + n = n + 1; + } + } + m.getValue("standalone") match { + case null => ; + case "yes" => info_stdl = Some(true); n = n + 1; + case "no" => info_stdl = Some(false); n = n + 1; + case _ => reportSyntaxError("either 'yes' or 'no' expected"); } - if (m != Null) + if(m.length - n != 0) { + Console.println("[length "+(m.length - n)+"]"); reportSyntaxError("VersionInfo EncodingDecl? SDDecl? or '?>' expected!"); + } Tuple3(info_ver,info_enc,info_stdl) } @@ -513,16 +508,23 @@ import scala.xml.dtd._ ; ch match { case '#' => // CharacterRef nextch; - val theChar = handle.text( tmppos, xCharRef ); - xToken(';'); - ts &+ theChar ; + val theChar = handle.text( tmppos, xCharRef ); + xToken(';'); + ts &+ theChar ; case _ => // EntityRef val n = xName ; xToken(';'); - /* - ts + handle.entityRef( tmppos, n ) ; - */ - push( n ); + xName match { + case "lt" => ts &+ '<'; + case "gt" => ts &+ '>'; + case "amp" => ts &+ '&'; + case "quote" => ts &+ '"'; + case _ => + /* + ts + handle.entityRef( tmppos, n ) ; + */ + push( n ); + } } case _ => // text content //Console.println("text content?? pos = "+pos); @@ -576,13 +578,13 @@ import scala.xml.dtd._ ; //external ID if('S' == ch || 'P' == ch) { extID = externalID(); - xSpace; + xSpaceOpt; } /* parse external subset of DTD */ - if(null != extID) { + if((null != extID)&&(isValidating)) { pushExternal(extID.systemId); //val extSubsetSrc = externalSource( extID.systemId ); -- cgit v1.2.3