summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2005-12-12 13:32:29 +0000
committerBurak Emir <emir@epfl.ch>2005-12-12 13:32:29 +0000
commit54d61d5149854784432d34bc221cdb6af01969ae (patch)
treef4e112eb6af9d6f7b02a24f54f30c7005ba8fb3b /sources
parent5dbdf2cc8cb2b96271b1a8183319592f239173f6 (diff)
downloadscala-54d61d5149854784432d34bc221cdb6af01969ae.tar.gz
scala-54d61d5149854784432d34bc221cdb6af01969ae.tar.bz2
scala-54d61d5149854784432d34bc221cdb6af01969ae.zip
toString
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/xml/dtd/ElementValidator.scala2
-rw-r--r--sources/scala/xml/parsing/MarkupParser.scala73
-rw-r--r--sources/scala/xml/xsd/ContentModel.scala2
-rw-r--r--sources/scala/xml/xsd/Decl.scala8
4 files changed, 65 insertions, 20 deletions
diff --git a/sources/scala/xml/dtd/ElementValidator.scala b/sources/scala/xml/dtd/ElementValidator.scala
index 7c5fe6d625..52ba82cb54 100644
--- a/sources/scala/xml/dtd/ElementValidator.scala
+++ b/sources/scala/xml/dtd/ElementValidator.scala
@@ -80,7 +80,7 @@ class ElementValidator() extends Function1[Node,Boolean] {
exc = fromUndefinedAttribute( attr.key ) :: exc;
case AttrDecl(_, tpe, DEFAULT(true, fixedValue)) if(attr.value != fixedValue) =>
- exc = fromFixedAttribute( attr.key, fixedValue, attr.value) :: exc;
+ exc = fromFixedAttribute( attr.key, fixedValue, attr.value.toString()) :: exc;
case s =>
//Console.println("s: "+s);
diff --git a/sources/scala/xml/parsing/MarkupParser.scala b/sources/scala/xml/parsing/MarkupParser.scala
index 2556529d42..09569bd106 100644
--- a/sources/scala/xml/parsing/MarkupParser.scala
+++ b/sources/scala/xml/parsing/MarkupParser.scala
@@ -104,10 +104,10 @@ import scala.xml.dtd._ ;
m.getValue("encoding") match {
case null => ;
- case enc => if (!isValidIANAEncoding(enc))
+ case enc => if (!isValidIANAEncoding(enc.toString()))
reportSyntaxError("\"" + enc + "\" is not a valid encoding");
else {
- info_enc = Some(enc);
+ info_enc = Some(enc.toString());
n = n + 1;
}
}
@@ -142,10 +142,10 @@ import scala.xml.dtd._ ;
m.getValue("encoding") match {
case null => ;
- case enc => if (!isValidIANAEncoding(enc))
+ case enc => if (!isValidIANAEncoding(enc.toString()))
reportSyntaxError("\"" + enc + "\" is not a valid encoding");
else {
- info_enc = Some(enc);
+ info_enc = Some(enc.toString());
n = n + 1;
}
}
@@ -331,9 +331,8 @@ import scala.xml.dtd._ ;
val str = cbuf.toString();
cbuf.setLength(0);
- // @todo: normalize attribute value
// well-formedness constraint
- str
+ normalizeAttributeValue(str)
}
@@ -409,25 +408,25 @@ import scala.xml.dtd._ ;
*
* see [66]
*/
- def xCharRef: String = {
- val hex = (ch == 'x') && { nextch; true };
+ def xCharRef(ch: () => Char, nextch: () => Unit): String = {
+ val hex = (ch() == 'x') && { nextch(); true };
val base = if (hex) 16 else 10;
var i = 0;
- while (ch != ';') {
- ch match {
+ while (ch() != ';') {
+ ch() match {
case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' =>
- i = i * base + Character.digit( ch, base );
+ i = i * base + Character.digit( ch(), base );
case 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F' =>
if (! hex)
reportSyntaxError("hex char not allowed in decimal char ref\n"
+"Did you mean to write &#x ?");
else
- i = i * base + Character.digit(ch, base);
+ i = i * base + Character.digit(ch(), base);
case _ =>
- reportSyntaxError("character '" + ch + " not allowed in char ref\n");
+ reportSyntaxError("character '" + ch() + " not allowed in char ref\n");
}
- nextch;
+ nextch();
}
new String(Predef.Array(i.asInstanceOf[char]))
}
@@ -518,7 +517,8 @@ import scala.xml.dtd._ ;
ch match {
case '#' => // CharacterRef
nextch;
- val theChar = handle.text( tmppos, xCharRef );
+ val theChar = handle.text( tmppos,
+ xCharRef ({ ()=> ch },{ () => nextch }) );
xToken(';');
ts &+ theChar ;
case _ => // EntityRef
@@ -1177,4 +1177,47 @@ import scala.xml.dtd._ ;
//Console.println(inpStack.map { x => x.descr });
}
+ /** for the moment, replace only character references
+ * see spec 3.3.3
+ * precond: cbuf empty
+ */
+ def normalizeAttributeValue(attval: String) = {
+ val s:Seq[Char] = attval;
+ val it = s.elements;
+ while(it.hasNext) {
+ it.next match {
+ case ' '|'\t'|'\n'|'\r' =>
+ cbuf.append(' ');
+ case '&' => it.next match {
+ case '#' =>
+ var c = it.next;
+ val s = xCharRef ({ () => c }, { () => c = it.next });
+ cbuf.append(s);
+ case nchar =>
+ val nbuf = new StringBuffer();
+ var d = nchar;
+ do {
+ nbuf.append(d);
+ d = it.next;
+ } while(d != ';');
+ nbuf.toString() match {
+ case "lt" => cbuf.append('<');
+ case "gt" => cbuf.append('>');
+ case "amp" => cbuf.append('&');
+ case "quote" => cbuf.append('"');
+ case name =>
+ //don't handle entityrefs for now
+ cbuf.append('&');
+ cbuf.append(name);
+ cbuf.append(';');
+ }
+ }
+ case c => cbuf.append(c);
+ }
+ }
+ val name = cbuf.toString();
+ cbuf.setLength(0);
+ name
+ }
+
}
diff --git a/sources/scala/xml/xsd/ContentModel.scala b/sources/scala/xml/xsd/ContentModel.scala
index ae73162a44..11e513d26d 100644
--- a/sources/scala/xml/xsd/ContentModel.scala
+++ b/sources/scala/xml/xsd/ContentModel.scala
@@ -25,7 +25,7 @@ object ContentModel extends WordExp {
case "choice" => Alt(fromSchema(node.child):_*);
case "group" => Sequ(fromSchema(node.child):_*);
case "element" =>
- val name = node.attribute("name");
+ val name = node.attribute("name").toString();
Letter(ElemRef(name)); // ouch, anonymous? references?
}
}
diff --git a/sources/scala/xml/xsd/Decl.scala b/sources/scala/xml/xsd/Decl.scala
index 42e64cdfd9..18a61f3b2b 100644
--- a/sources/scala/xml/xsd/Decl.scala
+++ b/sources/scala/xml/xsd/Decl.scala
@@ -15,10 +15,12 @@ abstract class Decl ;
/** name - label of the element
* typeName - reference to a (possibly generated) type name
*/
-case class ElemDecl(name: String, tpe: TypeSymbol) ;
+case class ElemDecl(name: String, tpe: TypeSymbol) extends Decl;
-case class ComplexTypeDecl(name: String, derivedFrom: DerivSym, contentModel: ContentModel) ;
+abstract class TypeDecl ;
-case class SimpleTypeDecl(name: String);
+case class ComplexTypeDecl(name: String, derivedFrom: DerivSym, contentModel: ContentModel) extends TypeDecl;
+
+case class SimpleTypeDecl(name: String) extends TypeDecl;;
abstract class xsdBuiltin(name: String) extends SimpleTypeDecl(name);