summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2005-05-19 16:43:39 +0000
committerburaq <buraq@epfl.ch>2005-05-19 16:43:39 +0000
commit2c5078a2ee7ac2c95b54f1c7442d7d1324cbafb8 (patch)
tree6d06d8243d893ea9f7cd3149c97d52db0ffded99
parent5e7ea748c3af8f3844e5ec76a8b932fb523dbe83 (diff)
downloadscala-2c5078a2ee7ac2c95b54f1c7442d7d1324cbafb8.tar.gz
scala-2c5078a2ee7ac2c95b54f1c7442d7d1324cbafb8.tar.bz2
scala-2c5078a2ee7ac2c95b54f1c7442d7d1324cbafb8.zip
entity handling
-rw-r--r--sources/scala/xml/dtd/DTD.scala32
-rw-r--r--sources/scala/xml/parsing/MarkupHandler.scala12
-rw-r--r--sources/scala/xml/parsing/MarkupParser.scala28
3 files changed, 56 insertions, 16 deletions
diff --git a/sources/scala/xml/dtd/DTD.scala b/sources/scala/xml/dtd/DTD.scala
index 20a329714f..73a372cd3f 100644
--- a/sources/scala/xml/dtd/DTD.scala
+++ b/sources/scala/xml/dtd/DTD.scala
@@ -1,5 +1,6 @@
package scala.xml.dtd;
+import scala.io.Source;
import scala.collection.mutable.{ HashMap, Map }
/** a document type declaration */
@@ -17,6 +18,8 @@ abstract class DTD {
var attr: Map[String, AttListDecl] =
new HashMap[String, AttListDecl]();
+ var ent: Map[String, EntityDecl] =
+ new HashMap[String, EntityDecl]();
var decls: List[Decl] = Nil;
@@ -34,15 +37,24 @@ abstract class DTD {
sb.append("]").toString()
}
- /** creates fresh type symbols from declarations */
- def createTypeSymbols(): Unit = {
- elem.clear;
- /*
- for(val d <- decl)
- d.match {
- case ElemDecl(name, contentModel) =>
- elementType.update(name, new ElementType(name, contentModel)
- }
- */
+ def initializeEntities() = {
+ for(val x <- decls) x match {
+ case y @ ParsedEntityDecl(name, _) => ent.update(name, y);
+ case y @ UnparsedEntityDecl(name, _, _) => ent.update(name, y);
+ case y @ ParameterEntityDecl(name, _) => ent.update(name, y);
+ case _ =>
+ }
}
+
+ def replacementText( entityName: String ): Source = {
+ ent.get(entityName).match {
+ case Some(ParsedEntityDecl(_, IntDef(value))) =>
+ Source.fromString(value);
+ case Some(_) =>
+ Source.fromString("<!-- "+entityName+"; -->");
+ case None =>
+ Source.fromString("<!-- unknown entity "+entityName+"; -->")
+ }
+ }
+
}
diff --git a/sources/scala/xml/parsing/MarkupHandler.scala b/sources/scala/xml/parsing/MarkupHandler.scala
index 0e84c3d529..46995f357a 100644
--- a/sources/scala/xml/parsing/MarkupHandler.scala
+++ b/sources/scala/xml/parsing/MarkupHandler.scala
@@ -51,12 +51,16 @@ abstract class MarkupHandler {
def attListDecl(name: String, attList: List[AttrDecl]): Unit = {}
- def parameterEntityDecl(name: String, edef: EntityDef): Unit =
- decls = ParameterEntityDecl(name, edef) :: decls;
+ def parameterEntityDecl(name: String, edef: EntityDef): Unit = edef.match {
+ case _:ExtDef if !isValidating =>
+ ; // ignore (cf REC-xml 4.4.1)
+ case _ =>
+ decls = ParameterEntityDecl(name, edef) :: decls;
+ }
def parsedEntityDecl(name: String, edef: EntityDef): Unit = edef.match {
- case _:ExtDef if isValidating =>
- ; // ignore (cf 4.4.1)
+ case _:ExtDef if !isValidating =>
+ ; // ignore (cf REC-xml 4.8 and 4.4.1)
case _ =>
decls = ParsedEntityDecl(name, edef) :: decls;
}
diff --git a/sources/scala/xml/parsing/MarkupParser.scala b/sources/scala/xml/parsing/MarkupParser.scala
index 9297aacbe4..486936852e 100644
--- a/sources/scala/xml/parsing/MarkupParser.scala
+++ b/sources/scala/xml/parsing/MarkupParser.scala
@@ -16,15 +16,20 @@ import scala.xml.dtd._ ;
* and returns whatever the markup handler returns. Use ConstructingParser
* if you just want to parse XML to construct instances of scala.xml.Node.
*/
-abstract class MarkupParser(input: Source): MarkupHandler with TokenTests {
+abstract class MarkupParser(_input: Source): MarkupHandler with TokenTests {
//
// variables, values
//
+ var input: Source = _input;
+
/** the handler of the markup, should return this */
val handle: MarkupHandler;
+ /** stack of inputs */
+ var inpStack: List[Source] = Nil;
+
/** holds the position in the source file */
var pos: Int = _;
@@ -168,7 +173,9 @@ abstract class MarkupParser(input: Source): MarkupHandler with TokenTests {
if(input.hasNext) {
ch = input.next;
pos = input.pos;
- } else
+ } else if (Nil!=inpStack)
+ pop();
+ else
eof = true;
}
@@ -422,7 +429,10 @@ abstract class MarkupParser(input: Source): MarkupHandler with TokenTests {
case _ => // EntityRef
val n = xName ;
xToken(';');
+ /*
ts + handle.entityRef( tmppos, n ) ;
+ */
+ push( n );
}
case _ => // text content
//Console.println("text content?? pos = "+pos);
@@ -494,6 +504,7 @@ abstract class MarkupParser(input: Source): MarkupHandler with TokenTests {
override var externalID = extID;
override val decls = handle.decls.reverse;
}
+ this.dtd.initializeEntities();
}
def element(pscope: NamespaceBinding): NodeSeq = {
@@ -864,4 +875,17 @@ abstract class MarkupParser(input: Source): MarkupHandler with TokenTests {
}
+ def push(entityName:String) = {
+
+ inpStack = input :: inpStack;
+ input = this.dtd.replacementText( entityName );
+ nextch;
+ }
+
+ def pop() = {
+ input = inpStack.head;
+ inpStack = inpStack.tail;
+ nextch;
+ }
+
}