summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2005-04-25 09:15:04 +0000
committerburaq <buraq@epfl.ch>2005-04-25 09:15:04 +0000
commit96cf49a321afe8a50fa33326a2edfdf9c28cb335 (patch)
tree65b0861501817fa5f0b83faaee6d6a97b0f9c7db /sources
parent5c5a13fc7e83f6d1abc8305591a62d932254d9d3 (diff)
downloadscala-96cf49a321afe8a50fa33326a2edfdf9c28cb335.tar.gz
scala-96cf49a321afe8a50fa33326a2edfdf9c28cb335.tar.bz2
scala-96cf49a321afe8a50fa33326a2edfdf9c28cb335.zip
rearranging the library some more
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/xml/MetaData.scala160
-rw-r--r--sources/scala/xml/NamespaceBinding.scala18
-rw-r--r--sources/scala/xml/Null.scala59
-rw-r--r--sources/scala/xml/Parsing.scala4
-rw-r--r--sources/scala/xml/PrefixedAttribute.scala63
-rw-r--r--sources/scala/xml/ProcInstr.scala2
-rw-r--r--sources/scala/xml/TextBuffer.scala4
-rw-r--r--sources/scala/xml/TopScope.scala20
-rw-r--r--sources/scala/xml/UnprefixedAttribute.scala44
-rw-r--r--sources/scala/xml/Utility.scala2
-rw-r--r--sources/scala/xml/dtd/Decl.scala2
-rw-r--r--sources/scala/xml/dtd/DocType.scala2
-rw-r--r--sources/scala/xml/dtd/ExternalID.scala6
-rw-r--r--sources/scala/xml/dtd/Scanner.scala48
-rw-r--r--sources/scala/xml/parsing/MarkupParser.scala16
15 files changed, 226 insertions, 224 deletions
diff --git a/sources/scala/xml/MetaData.scala b/sources/scala/xml/MetaData.scala
index e3d0ee06b9..9ed7e4363b 100644
--- a/sources/scala/xml/MetaData.scala
+++ b/sources/scala/xml/MetaData.scala
@@ -108,3 +108,163 @@ abstract class MetaData extends Iterable[MetaData] with java.io.Serializable {
}
+/** prefixed attributes always have a non-null namespace
+ */
+class PrefixedAttribute(val pre: String, val key: String, val value: String, val next: MetaData) extends MetaData {
+
+ /** returns a copy of this unprefixed attribute with the given next field*/
+ def copy(next: MetaData) =
+ new PrefixedAttribute(pre, key, value, next);
+
+ //** duplicates the MetaData (deep copy), not preserving order */
+ //def deepCopy: MetaData = deepCopy(null);
+
+ //** duplicates the MetaData (deep copy), prepending it to tail */
+ /*
+ def deepCopy(tail:MetaData): MetaData = {
+ val md = copy(tail);
+ if(null == next)
+ md
+ else
+ next.deepCopy(md)
+ }
+ */
+
+ def equals1(m:MetaData) = m.isPrefixed && (m.asInstanceOf[PrefixedAttribute].pre == pre) && (m.key == key) && (m.value == value);
+
+ def getNamespace(owner: Node) =
+ owner.getNamespace(pre);
+
+ /** forwards the call to next */
+ def getValue(key: String): String = next.getValue(key);
+
+ /** gets attribute value of qualified (prefixed) attribute with given key
+ */
+ def getValue(namespace: String, scope: NamespaceBinding, key: String): String = {
+ if(key == this.key && scope.getURI(pre) == namespace)
+ value
+ else
+ next.getValue(namespace, scope, key);
+ }
+
+ /** returns true */
+ final def isPrefixed = true;
+
+ override def hashCode() =
+ pre.hashCode() * 41 + key.hashCode() * 7 + value.hashCode() * 3 + next.hashCode();
+
+
+ def toString1(sb:StringBuffer): Unit = {
+ sb.append(pre);
+ sb.append(':');
+ sb.append(key);
+ sb.append('=');
+ Utility.appendQuoted(value, sb);
+ }
+
+ def wellformed(scope: NamespaceBinding): Boolean = {
+ (null == next.getValue(scope.getURI(pre), scope, key)
+ && next.wellformed(scope));
+ }
+
+}
+
+/** unprefixed attributes have the null namespace
+ */
+class UnprefixedAttribute(val key: String, val value: String, val next: MetaData) extends MetaData {
+
+ /** returns a copy of this unprefixed attribute with the given next field*/
+ def copy(next: MetaData) =
+ new UnprefixedAttribute(key, value, next);
+
+ def equals1(m:MetaData) = !m.isPrefixed && (m.key == key) && (m.value == value);
+
+ /** returns null */
+ final def getNamespace(owner: Node): String =
+ null;
+
+ /** gets value of unqualified (unprefixed) attribute with given key */
+ def getValue(key: String): String =
+ if(key == this.key)
+ value
+ else
+ next.getValue(key);
+
+ /** forwards the call to next */
+ def getValue(namespace: String, scope: NamespaceBinding, key: String): String =
+ next.getValue(namespace, scope, key);
+
+ override def hashCode() =
+ key.hashCode() * 7 + value.hashCode() * 53 + next.hashCode();
+
+ /** returns false */
+ final def isPrefixed = false;
+
+ def toString1(sb:StringBuffer): Unit = {
+ sb.append(key);
+ sb.append('=');
+ Utility.appendQuoted(value, sb);
+ }
+
+ def wellformed(scope: NamespaceBinding): Boolean =
+ (null == next.getValue(null, scope, key)) && next.wellformed(scope);
+
+}
+
+case object Null extends MetaData {
+
+ /** appends given MetaData items to this MetaData list */
+ override def append(m: MetaData): MetaData = m;
+
+ override def containedIn1(m:MetaData): Boolean = false;
+
+ /** returns a copy of this MetaData item with next field set to argument */
+ def copy(next: MetaData) = next;
+
+ /** returns null */
+ def getNamespace(owner: Node) = null;
+
+ final override def hasNext = false;
+
+ final override def length = 0;
+
+ final override def length(i:Int) = i;
+
+ def isPrefixed = false;
+
+ /** deep equals method */
+ override def equals(that: Any) = that match {
+ case m:MetaData => m.length == 0
+ case _ => false;
+ }
+
+ def equals1(that:MetaData) = that.length == 0;
+
+ def key = null;
+
+ def value = null;
+
+ def next = null;
+
+ /** null */
+ def getValue(key: String) = null;
+
+ /** gets value of qualified (prefixed) attribute with given key */
+ def getValue(namespace: String, scope: NamespaceBinding, key: String) =
+ null;
+
+ override def hashCode(): Int = 0;
+
+ override def toString1(): String = "";
+
+ //appends string representations of single attribute to StringBuffer
+ def toString1(sb:StringBuffer) = {};
+
+ override def toString(): String = "";
+
+ override def toString(sb: StringBuffer): Unit = {}
+
+ override def wellformed(scope: NamespaceBinding) = true;
+
+
+}
diff --git a/sources/scala/xml/NamespaceBinding.scala b/sources/scala/xml/NamespaceBinding.scala
index 67222d912d..d6de574dd9 100644
--- a/sources/scala/xml/NamespaceBinding.scala
+++ b/sources/scala/xml/NamespaceBinding.scala
@@ -57,3 +57,21 @@ class NamespaceBinding(val prefix: String, val uri: String, val parent: Namespac
}
+case object TopScope extends NamespaceBinding(null,null,null) {
+
+ /*
+ override def contains(pre:String) = false;
+ */
+ override def getURI(_prefix: String) = null;
+
+ override def getPrefix(_uri: String) = null;
+
+ override def toString() = "";
+
+ override def toString(stop: NamespaceBinding) = "";
+
+ override def toString(sb: StringBuffer, ignore: NamespaceBinding) = {
+ }
+
+}
+
diff --git a/sources/scala/xml/Null.scala b/sources/scala/xml/Null.scala
deleted file mode 100644
index 544b05c743..0000000000
--- a/sources/scala/xml/Null.scala
+++ /dev/null
@@ -1,59 +0,0 @@
-package scala.xml;
-
-case object Null extends MetaData {
-
- /** appends given MetaData items to this MetaData list */
- override def append(m: MetaData): MetaData = m;
-
- override def containedIn1(m:MetaData): Boolean = false;
-
- /** returns a copy of this MetaData item with next field set to argument */
- def copy(next: MetaData) = next;
-
- /** returns null */
- def getNamespace(owner: Node) = null;
-
- final override def hasNext = false;
-
- final override def length = 0;
-
- final override def length(i:Int) = i;
-
- def isPrefixed = false;
-
- /** deep equals method */
- override def equals(that: Any) = that match {
- case m:MetaData => m.length == 0
- case _ => false;
- }
-
- def equals1(that:MetaData) = that.length == 0;
-
- def key = null;
-
- def value = null;
-
- def next = null;
-
- /** null */
- def getValue(key: String) = null;
-
- /** gets value of qualified (prefixed) attribute with given key */
- def getValue(namespace: String, scope: NamespaceBinding, key: String) =
- null;
-
- override def hashCode(): Int = 0;
-
- override def toString1(): String = "";
-
- //appends string representations of single attribute to StringBuffer
- def toString1(sb:StringBuffer) = {};
-
- override def toString(): String = "";
-
- override def toString(sb: StringBuffer): Unit = {}
-
- override def wellformed(scope: NamespaceBinding) = true;
-
-
-}
diff --git a/sources/scala/xml/Parsing.scala b/sources/scala/xml/Parsing.scala
index 514516dd7a..bc86d18e62 100644
--- a/sources/scala/xml/Parsing.scala
+++ b/sources/scala/xml/Parsing.scala
@@ -8,7 +8,9 @@
\* */
package scala.xml ;
-/** helper functions for parsing XML fragments */
+/** DEPRECATED - use either parsing.TokenTests, or Utilty (helper functions
+ * for parsing XML fragments ).
+ */
object Parsing {
/** (#x20 | #x9 | #xD | #xA) */
diff --git a/sources/scala/xml/PrefixedAttribute.scala b/sources/scala/xml/PrefixedAttribute.scala
deleted file mode 100644
index 7be7ffe338..0000000000
--- a/sources/scala/xml/PrefixedAttribute.scala
+++ /dev/null
@@ -1,63 +0,0 @@
-package scala.xml;
-
-/** prefixed attributes always have a non-null namespace
- */
-class PrefixedAttribute(val pre: String, val key: String, val value: String, val next: MetaData) extends MetaData {
-
- /** returns a copy of this unprefixed attribute with the given next field*/
- def copy(next: MetaData) =
- new PrefixedAttribute(pre, key, value, next);
-
- //** duplicates the MetaData (deep copy), not preserving order */
- //def deepCopy: MetaData = deepCopy(null);
-
- //** duplicates the MetaData (deep copy), prepending it to tail */
- /*
- def deepCopy(tail:MetaData): MetaData = {
- val md = copy(tail);
- if(null == next)
- md
- else
- next.deepCopy(md)
- }
- */
-
- def equals1(m:MetaData) = m.isPrefixed && (m.asInstanceOf[PrefixedAttribute].pre == pre) && (m.key == key) && (m.value == value);
-
- def getNamespace(owner: Node) =
- owner.getNamespace(pre);
-
- /** forwards the call to next */
- def getValue(key: String): String = next.getValue(key);
-
- /** gets attribute value of qualified (prefixed) attribute with given key
- */
- def getValue(namespace: String, scope: NamespaceBinding, key: String): String = {
- if(key == this.key && scope.getURI(pre) == namespace)
- value
- else
- next.getValue(namespace, scope, key);
- }
-
- /** returns true */
- final def isPrefixed = true;
-
- override def hashCode() =
- pre.hashCode() * 41 + key.hashCode() * 7 + value.hashCode() * 3 + next.hashCode();
-
-
- def toString1(sb:StringBuffer): Unit = {
- sb.append(pre);
- sb.append(':');
- sb.append(key);
- sb.append('=');
- Utility.appendQuoted(value, sb);
- }
-
- def wellformed(scope: NamespaceBinding): Boolean = {
- (null == next.getValue(scope.getURI(pre), scope, key)
- && next.wellformed(scope));
- }
-
-}
-
diff --git a/sources/scala/xml/ProcInstr.scala b/sources/scala/xml/ProcInstr.scala
index 7a5ce461d6..08dd5c8feb 100644
--- a/sources/scala/xml/ProcInstr.scala
+++ b/sources/scala/xml/ProcInstr.scala
@@ -18,7 +18,7 @@ package scala.xml;
case class ProcInstr(target:String, text:String) extends SpecialNode {
- if( !Parsing.isName( target ) )
+ if( !Utility.isName( target ) )
throw new IllegalArgumentException(target+" must be an XML Name");
else if( text.indexOf("?>" ) != -1 )
throw new IllegalArgumentException(text+" may not contain \"?>\"");
diff --git a/sources/scala/xml/TextBuffer.scala b/sources/scala/xml/TextBuffer.scala
index ee89bef6da..ab286ed318 100644
--- a/sources/scala/xml/TextBuffer.scala
+++ b/sources/scala/xml/TextBuffer.scala
@@ -30,7 +30,7 @@ class TextBuffer {
/** appends this string to the text buffer, trimming whitespaces as needed */
def append( cs:Seq[Char] ):TextBuffer = {
for( val c <- cs ) {
- if( Parsing.isSpace( c ) )
+ if( Utility.isSpace( c ) )
appendSpace;
else
appendChar( c )
@@ -43,7 +43,7 @@ class TextBuffer {
var len = sb.length(); /* invariant */
if( len == 0 ) return Nil;
- if( Parsing.isSpace( sb.charAt( len - 1 ) )) {
+ if( Utility.isSpace( sb.charAt( len - 1 ) )) {
len = len - 1;
sb.setLength( len )
}
diff --git a/sources/scala/xml/TopScope.scala b/sources/scala/xml/TopScope.scala
deleted file mode 100644
index 200fb3b21f..0000000000
--- a/sources/scala/xml/TopScope.scala
+++ /dev/null
@@ -1,20 +0,0 @@
-package scala.xml;
-
-case object TopScope extends NamespaceBinding(null,null,null) {
-
- /*
- override def contains(pre:String) = false;
- */
- override def getURI(_prefix: String) = null;
-
- override def getPrefix(_uri: String) = null;
-
- override def toString() = "";
-
- override def toString(stop: NamespaceBinding) = "";
-
- override def toString(sb: StringBuffer, ignore: NamespaceBinding) = {
- }
-
-}
-
diff --git a/sources/scala/xml/UnprefixedAttribute.scala b/sources/scala/xml/UnprefixedAttribute.scala
deleted file mode 100644
index 90081909a6..0000000000
--- a/sources/scala/xml/UnprefixedAttribute.scala
+++ /dev/null
@@ -1,44 +0,0 @@
-package scala.xml;
-
-/** unprefixed attributes have the null namespace
- */
-class UnprefixedAttribute(val key: String, val value: String, val next: MetaData) extends MetaData {
-
- /** returns a copy of this unprefixed attribute with the given next field*/
- def copy(next: MetaData) =
- new UnprefixedAttribute(key, value, next);
-
- def equals1(m:MetaData) = !m.isPrefixed && (m.key == key) && (m.value == value);
-
- /** returns null */
- final def getNamespace(owner: Node): String =
- null;
-
- /** gets value of unqualified (unprefixed) attribute with given key */
- def getValue(key: String): String =
- if(key == this.key)
- value
- else
- next.getValue(key);
-
- /** forwards the call to next */
- def getValue(namespace: String, scope: NamespaceBinding, key: String): String =
- next.getValue(namespace, scope, key);
-
- override def hashCode() =
- key.hashCode() * 7 + value.hashCode() * 53 + next.hashCode();
-
- /** returns false */
- final def isPrefixed = false;
-
- def toString1(sb:StringBuffer): Unit = {
- sb.append(key);
- sb.append('=');
- Utility.appendQuoted(value, sb);
- }
-
- def wellformed(scope: NamespaceBinding): Boolean =
- (null == next.getValue(null, scope, key)) && next.wellformed(scope);
-
-}
-
diff --git a/sources/scala/xml/Utility.scala b/sources/scala/xml/Utility.scala
index 08ce7febce..a14f7cf8c0 100644
--- a/sources/scala/xml/Utility.scala
+++ b/sources/scala/xml/Utility.scala
@@ -16,7 +16,7 @@ import scala.collection.mutable;
* Utility functions for processing instances of bound and not bound XML
* classes, as well as escaping text nodes
*/
-object Utility {
+object Utility with parsing.TokenTests {
def view(s: String): Text[String] = Text(s);
diff --git a/sources/scala/xml/dtd/Decl.scala b/sources/scala/xml/dtd/Decl.scala
index 246ee4a5a0..2b4c4a56e0 100644
--- a/sources/scala/xml/dtd/Decl.scala
+++ b/sources/scala/xml/dtd/Decl.scala
@@ -61,7 +61,7 @@ case class NotationDecl( name:String, tpe:String ) extends MarkupDecl;
/** a parsed entity reference */
case class PEReference(ent:String) extends Decl {
- if( !Parsing.isName( ent ))
+ if( !Utility.isName( ent ))
throw new IllegalArgumentException("ent must be an XML Name");
final override def toString() = "%"+ent+";"
diff --git a/sources/scala/xml/dtd/DocType.scala b/sources/scala/xml/dtd/DocType.scala
index 0ad93097fa..014c7046aa 100644
--- a/sources/scala/xml/dtd/DocType.scala
+++ b/sources/scala/xml/dtd/DocType.scala
@@ -19,7 +19,7 @@ package scala.xml.dtd;
case class DocType( name:String, extID:ExternalID, intSubset:Seq[dtd.Decl]) {
- if( !Parsing.isName( name ) )
+ if( !Utility.isName( name ) )
throw new IllegalArgumentException(name+" must be an XML Name");
/** hashcode for this processing instruction */
diff --git a/sources/scala/xml/dtd/ExternalID.scala b/sources/scala/xml/dtd/ExternalID.scala
index 3463f853e6..ea0f7fbc6c 100644
--- a/sources/scala/xml/dtd/ExternalID.scala
+++ b/sources/scala/xml/dtd/ExternalID.scala
@@ -26,7 +26,7 @@ class ExternalID ;
case class SystemID( systemLiteral:String ) extends ExternalID {
- if( !Parsing.checkSysID( systemLiteral ) )
+ if( !Utility.checkSysID( systemLiteral ) )
throw new IllegalArgumentException(
"can't use both \" and ' in systemLiteral"
);
@@ -43,11 +43,11 @@ case class SystemID( systemLiteral:String ) extends ExternalID {
**/
case class PublicID( publicLiteral:String, systemLiteral:String ) extends ExternalID {
- if( !Parsing.checkPubID( publicLiteral ))
+ if( !Utility.checkPubID( publicLiteral ))
throw new IllegalArgumentException(
"publicLiteral must consist of PubidChars"
);
- if( !Parsing.checkSysID( systemLiteral ) )
+ if( !Utility.checkSysID( systemLiteral ) )
throw new IllegalArgumentException(
"can't use both \" and ' in systemLiteral"
);
diff --git a/sources/scala/xml/dtd/Scanner.scala b/sources/scala/xml/dtd/Scanner.scala
index aeda38e364..0d42e06b4a 100644
--- a/sources/scala/xml/dtd/Scanner.scala
+++ b/sources/scala/xml/dtd/Scanner.scala
@@ -1,7 +1,9 @@
package scala.xml.dtd ;
-/** Scanner for regexps (content models in DTD element declarations) */
-class Scanner with Tokens {
+/** Scanner for regexps (content models in DTD element declarations)
+ * todo: cleanup
+ */
+class Scanner with Tokens with parsing.TokenTests {
// zzz constants zzz
final val ENDCH = '\u0000';
@@ -45,33 +47,39 @@ class Scanner with Tokens {
val jt = ds.elements; while( jt.hasNext ) { acc( jt.next ) }
}
+ /*
final def isSpace = c match {
case '\u0020' | '\u0009' | '\u000D' | '\u000A' => true
case _ => false;
}
+ */
- final def readToken:int = if( isSpace ) {
- while( isSpace ) { it.next }; S
- } else c match {
- case '(' => next; LPAREN
- case ')' => next; RPAREN
- case ',' => next; COMMA
- case '*' => next; STAR
- case '+' => next; PLUS
- case '?' => next; OPT
- case '|' => next; CHOICE
- case '#' => next; accS( "PCDATA" ); TOKEN_PCDATA
- case ENDCH => END;
- case _ =>
- if( Parsing.isNameStart( c ) ) name; // NAME
- else {
- error("unexpected character:"+c); END
+ final def readToken:int =
+ if(isSpace(c)) {
+ while( isSpace(c) ) {
+ c = it.next;
}
- }
+ S
+ } else c match {
+ case '(' => next; LPAREN
+ case ')' => next; RPAREN
+ case ',' => next; COMMA
+ case '*' => next; STAR
+ case '+' => next; PLUS
+ case '?' => next; OPT
+ case '|' => next; CHOICE
+ case '#' => next; accS( "PCDATA" ); TOKEN_PCDATA
+ case ENDCH => END;
+ case _ =>
+ if( isNameStart( c ) ) name; // NAME
+ else {
+ error("unexpected character:"+c); END
+ }
+ }
final def name = {
val sb = new StringBuffer();
- do { sb.append( c ); next } while ( Parsing.isNameChar( c ) ) ;
+ do { sb.append( c ); next } while ( isNameChar( c ) ) ;
value = sb.toString();
NAME
}
diff --git a/sources/scala/xml/parsing/MarkupParser.scala b/sources/scala/xml/parsing/MarkupParser.scala
index e7bf6d3efd..633c610a53 100644
--- a/sources/scala/xml/parsing/MarkupParser.scala
+++ b/sources/scala/xml/parsing/MarkupParser.scala
@@ -13,7 +13,7 @@ package scala.xml.parsing;
* 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 {
+abstract class MarkupParser with TokenTests {
/** the handler of the markup */
val handle: MarkupHandler;
@@ -70,7 +70,7 @@ abstract class MarkupParser {
def xAttributes(pscope:NamespaceBinding): Pair[MetaData,NamespaceBinding] = {
var scope: NamespaceBinding = pscope;
var aMap: MetaData = Null;
- while( xml.Parsing.isNameStart( ch )) {
+ while( isNameStart( ch )) {
val pos = this.pos;
val qname = xName;
@@ -135,7 +135,7 @@ abstract class MarkupParser {
xSpaceOpt;
val Pair(aMap: MetaData, scope: NamespaceBinding) = {
- if(xml.Parsing.isNameStart( ch ))
+ if(isNameStart( ch ))
xAttributes(pscope)
else
Pair(Null, pscope)
@@ -339,11 +339,11 @@ abstract class MarkupParser {
* see [5] of XML 1.0 specification
*/
def xName: String = {
- if (xml.Parsing.isNameStart(ch)) {
+ if (isNameStart(ch)) {
do {
putChar(ch);
nextch;
- } while (xml.Parsing.isNameChar(ch));
+ } while (isNameChar(ch));
val n = cbuf.toString().intern();
cbuf.setLength(0);
n
@@ -358,11 +358,11 @@ abstract class MarkupParser {
def xEQ = { xSpaceOpt; xToken('='); xSpaceOpt }
/** skip optional space S? */
- def xSpaceOpt = while (xml.Parsing.isSpace(ch)) { nextch; };
+ def xSpaceOpt = while (isSpace(ch)) { nextch; };
/** scan [3] S ::= (#x20 | #x9 | #xD | #xA)+ */
def xSpace = {
- if (xml.Parsing.isSpace(ch)) {
+ if (isSpace(ch)) {
nextch; xSpaceOpt
}
else {
@@ -377,7 +377,7 @@ abstract class MarkupParser {
def xProcInstr: NodeSeq = {
val sb:StringBuffer = new StringBuffer();
val n = xName;
- if( xml.Parsing.isSpace( ch ) ) {
+ if( isSpace( ch ) ) {
xSpace;
while (true) {
if (ch=='?' && { sb.append( ch ); nextch; ch == '>' }) {