summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2006-11-05 02:53:14 +0000
committerBurak Emir <emir@epfl.ch>2006-11-05 02:53:14 +0000
commit1e23988361e85f275b44041207988ef9aa0099f2 (patch)
tree167c7224dfbec04561337d771226fd678a3d1ae0 /src/library
parent9d507e381c8c101a3edf16e0c065e9b8efd5feec (diff)
downloadscala-1e23988361e85f275b44041207988ef9aa0099f2.tar.gz
scala-1e23988361e85f275b44041207988ef9aa0099f2.tar.bz2
scala-1e23988361e85f275b44041207988ef9aa0099f2.zip
caseclass->product
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/List.scala5
-rw-r--r--src/library/scala/Option.scala5
-rw-r--r--src/library/scala/Product.scala42
-rw-r--r--src/library/scala/Product0.scala35
-rw-r--r--src/library/scala/Product1.scala25
-rw-r--r--src/library/scala/Product2.scala28
-rw-r--r--src/library/scala/Product3.scala31
-rw-r--r--src/library/scala/Product4.scala34
-rw-r--r--src/library/scala/Product5.scala37
-rw-r--r--src/library/scala/Product6.scala40
-rw-r--r--src/library/scala/Product7.scala43
-rw-r--r--src/library/scala/Product8.scala46
-rw-r--r--src/library/scala/Product9.scala49
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala61
-rw-r--r--src/library/scala/runtime/matching/Address.scala38
-rw-r--r--src/library/scala/runtime/matching/NonTerm.scala58
-rw-r--r--src/library/scala/runtime/matching/PatternTests.scala17
-rw-r--r--src/library/scala/runtime/matching/Rule.scala112
-rw-r--r--src/library/scala/runtime/matching/TestAlphabet.scala21
-rw-r--r--src/library/scala/xml/Comment.scala2
-rw-r--r--src/library/scala/xml/EntityRef.scala2
-rw-r--r--src/library/scala/xml/MetaData.scala2
-rw-r--r--src/library/scala/xml/Null.scala2
-rw-r--r--src/library/scala/xml/ProcInstr.scala2
-rw-r--r--src/library/scala/xml/SpecialNode.scala4
-rw-r--r--src/library/scala/xml/dtd/ContentModel.scala10
-rw-r--r--src/library/scala/xml/dtd/Decl.scala56
-rw-r--r--src/library/scala/xml/dtd/ExternalID.scala42
28 files changed, 500 insertions, 349 deletions
diff --git a/src/library/scala/List.scala b/src/library/scala/List.scala
index 1410068344..3d622bd68c 100644
--- a/src/library/scala/List.scala
+++ b/src/library/scala/List.scala
@@ -371,7 +371,7 @@ object List {
* @author Martin Odersky and others
* @version 1.0, 16/07/2003
*/
-sealed abstract class List[+a] extends Seq[a] with CaseClass {
+sealed abstract class List[+a] extends Seq[a] {
/** Returns true if the list does not contain any elements.
* @return true, iff the list is empty.
@@ -1079,7 +1079,8 @@ sealed abstract class List[+a] extends Seq[a] with CaseClass {
b.toList
}
- override protected def stringPrefix: String = "List"
+ protected override def stringPrefix: String = "List"
+
}
/** The empty list.
diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala
index 9d8e547c28..cb92cbd39d 100644
--- a/src/library/scala/Option.scala
+++ b/src/library/scala/Option.scala
@@ -22,7 +22,7 @@ import Predef._
* @author Matthias Zenger
* @version 1.0, 16/07/2003
*/
-sealed abstract class Option[+A] extends Iterable[A] with CaseClass {
+sealed abstract class Option[+A] extends Iterable[A] {
def isEmpty: Boolean = this match {
case None => true
@@ -80,8 +80,7 @@ sealed abstract class Option[+A] extends Iterable[A] with CaseClass {
* @author Martin Odersky
* @version 1.0, 16/07/2003
*/
-final case class Some[+A](x: A) extends Option[A];
-
+final case class Some[+A](x: A) extends Option[A]
/** This case object represents non-existent values.
*
* @author Martin Odersky
diff --git a/src/library/scala/Product.scala b/src/library/scala/Product.scala
new file mode 100644
index 0000000000..07bc5b045c
--- /dev/null
+++ b/src/library/scala/Product.scala
@@ -0,0 +1,42 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id: CaseClass.scala 8756 2006-09-22 16:00:23Z michelou $
+
+
+package scala
+
+/** The trait <code>CaseClass</code> defines access functions for instances
+ * of case classes.
+ *
+ * @author Burak Emir
+ * @version 1.0
+ */
+trait Product extends AnyRef {
+
+ /** for a case class <code>A(x_1,...,x_k))</code>, returns <code>x_i</code>
+ * for <code>1 &lt;= i &lt; k</code>
+ *
+ * @param n the position of the n-th element
+ * @throws IndexOutOfBoundsException
+ * @return ...
+ */
+ def element(n: Int): Any
+
+ /** return k for a product <code>A(x_1,...,x_k))</code>
+ */
+ def arity: Int
+
+ /**
+ * By default the empty string. Implementations may override this
+ * method in order to prepend a string prefix to the result of the
+ * toString methods.
+ */
+ def productPrefix = ""
+
+}
diff --git a/src/library/scala/Product0.scala b/src/library/scala/Product0.scala
new file mode 100644
index 0000000000..a78fdd8ffe
--- /dev/null
+++ b/src/library/scala/Product0.scala
@@ -0,0 +1,35 @@
+
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// generated on Sun Nov 05 03:50:36 CET 2006
+package scala
+
+import Predef._
+
+/** Product0 is a cartesian product of 0 components
+ */
+trait Product0 extends Product {
+
+ /**
+ * The arity of this product.
+ * @return 0
+ */
+ override def arity = 0
+
+ /**
+ * Returns the n-th projection of this product if 0<n<=arity, otherwise null
+ * @param n number of the projection to be returned
+ * @throws IndexOutOfBoundsException
+ */
+ override def element(n: Int) = n match {
+ case _ => throw new IndexOutOfBoundsException(n.toString())
+ }
+
+
+}
diff --git a/src/library/scala/Product1.scala b/src/library/scala/Product1.scala
index 9f4860041c..944a49534b 100644
--- a/src/library/scala/Product1.scala
+++ b/src/library/scala/Product1.scala
@@ -7,12 +7,33 @@
** |/ **
\* */
-// generated on Fri Oct 27 18:56:23 CEST 2006
+// generated on Sun Nov 05 03:50:36 CET 2006
package scala
import Predef._
-trait Product1 [+T1] {
+/** Product1 is a cartesian product of 1 components
+ */
+trait Product1 [+T1] extends Product {
+
+ /**
+ * The arity of this product.
+ * @return 1
+ */
+ override def arity = 1
+
+ /**
+ * Returns the n-th projection of this product if 0<n<=arity, otherwise null
+ * @param n number of the projection to be returned
+ * @throws IndexOutOfBoundsException
+ */
+ override def element(n: Int) = n match {
+ case 1 => _1
+ case _ => throw new IndexOutOfBoundsException(n.toString())
+ }
+
+ /** projection of this product */
def _1:T1
+
}
diff --git a/src/library/scala/Product2.scala b/src/library/scala/Product2.scala
index 822b2f798c..b23fe3bd01 100644
--- a/src/library/scala/Product2.scala
+++ b/src/library/scala/Product2.scala
@@ -7,13 +7,37 @@
** |/ **
\* */
-// generated on Fri Oct 27 18:56:23 CEST 2006
+// generated on Sun Nov 05 03:50:36 CET 2006
package scala
import Predef._
-trait Product2 [+T1, +T2] {
+/** Product2 is a cartesian product of 2 components
+ */
+trait Product2 [+T1, +T2] extends Product {
+
+ /**
+ * The arity of this product.
+ * @return 2
+ */
+ override def arity = 2
+
+ /**
+ * Returns the n-th projection of this product if 0<n<=arity, otherwise null
+ * @param n number of the projection to be returned
+ * @throws IndexOutOfBoundsException
+ */
+ override def element(n: Int) = n match {
+ case 1 => _1
+ case 2 => _2
+ case _ => throw new IndexOutOfBoundsException(n.toString())
+ }
+
+ /** projection of this product */
def _1:T1
+
+ /** projection of this product */
def _2:T2
+
}
diff --git a/src/library/scala/Product3.scala b/src/library/scala/Product3.scala
index 868d388ca2..ee17610110 100644
--- a/src/library/scala/Product3.scala
+++ b/src/library/scala/Product3.scala
@@ -7,14 +7,41 @@
** |/ **
\* */
-// generated on Fri Oct 27 18:56:23 CEST 2006
+// generated on Sun Nov 05 03:50:36 CET 2006
package scala
import Predef._
-trait Product3 [+T1, +T2, +T3] {
+/** Product3 is a cartesian product of 3 components
+ */
+trait Product3 [+T1, +T2, +T3] extends Product {
+
+ /**
+ * The arity of this product.
+ * @return 3
+ */
+ override def arity = 3
+
+ /**
+ * Returns the n-th projection of this product if 0<n<=arity, otherwise null
+ * @param n number of the projection to be returned
+ * @throws IndexOutOfBoundsException
+ */
+ override def element(n: Int) = n match {
+ case 1 => _1
+ case 2 => _2
+ case 3 => _3
+ case _ => throw new IndexOutOfBoundsException(n.toString())
+ }
+
+ /** projection of this product */
def _1:T1
+
+ /** projection of this product */
def _2:T2
+
+ /** projection of this product */
def _3:T3
+
}
diff --git a/src/library/scala/Product4.scala b/src/library/scala/Product4.scala
index d6ed33e35e..5537c28ace 100644
--- a/src/library/scala/Product4.scala
+++ b/src/library/scala/Product4.scala
@@ -7,15 +7,45 @@
** |/ **
\* */
-// generated on Fri Oct 27 18:56:23 CEST 2006
+// generated on Sun Nov 05 03:50:36 CET 2006
package scala
import Predef._
-trait Product4 [+T1, +T2, +T3, +T4] {
+/** Product4 is a cartesian product of 4 components
+ */
+trait Product4 [+T1, +T2, +T3, +T4] extends Product {
+
+ /**
+ * The arity of this product.
+ * @return 4
+ */
+ override def arity = 4
+
+ /**
+ * Returns the n-th projection of this product if 0<n<=arity, otherwise null
+ * @param n number of the projection to be returned
+ * @throws IndexOutOfBoundsException
+ */
+ override def element(n: Int) = n match {
+ case 1 => _1
+ case 2 => _2
+ case 3 => _3
+ case 4 => _4
+ case _ => throw new IndexOutOfBoundsException(n.toString())
+ }
+
+ /** projection of this product */
def _1:T1
+
+ /** projection of this product */
def _2:T2
+
+ /** projection of this product */
def _3:T3
+
+ /** projection of this product */
def _4:T4
+
}
diff --git a/src/library/scala/Product5.scala b/src/library/scala/Product5.scala
index 0229c9f495..ffd29713d1 100644
--- a/src/library/scala/Product5.scala
+++ b/src/library/scala/Product5.scala
@@ -7,16 +7,49 @@
** |/ **
\* */
-// generated on Fri Oct 27 18:56:23 CEST 2006
+// generated on Sun Nov 05 03:50:36 CET 2006
package scala
import Predef._
-trait Product5 [+T1, +T2, +T3, +T4, +T5] {
+/** Product5 is a cartesian product of 5 components
+ */
+trait Product5 [+T1, +T2, +T3, +T4, +T5] extends Product {
+
+ /**
+ * The arity of this product.
+ * @return 5
+ */
+ override def arity = 5
+
+ /**
+ * Returns the n-th projection of this product if 0<n<=arity, otherwise null
+ * @param n number of the projection to be returned
+ * @throws IndexOutOfBoundsException
+ */
+ override def element(n: Int) = n match {
+ case 1 => _1
+ case 2 => _2
+ case 3 => _3
+ case 4 => _4
+ case 5 => _5
+ case _ => throw new IndexOutOfBoundsException(n.toString())
+ }
+
+ /** projection of this product */
def _1:T1
+
+ /** projection of this product */
def _2:T2
+
+ /** projection of this product */
def _3:T3
+
+ /** projection of this product */
def _4:T4
+
+ /** projection of this product */
def _5:T5
+
}
diff --git a/src/library/scala/Product6.scala b/src/library/scala/Product6.scala
index 318b8a1524..4dd5140315 100644
--- a/src/library/scala/Product6.scala
+++ b/src/library/scala/Product6.scala
@@ -7,17 +7,53 @@
** |/ **
\* */
-// generated on Fri Oct 27 18:56:23 CEST 2006
+// generated on Sun Nov 05 03:50:36 CET 2006
package scala
import Predef._
-trait Product6 [+T1, +T2, +T3, +T4, +T5, +T6] {
+/** Product6 is a cartesian product of 6 components
+ */
+trait Product6 [+T1, +T2, +T3, +T4, +T5, +T6] extends Product {
+
+ /**
+ * The arity of this product.
+ * @return 6
+ */
+ override def arity = 6
+
+ /**
+ * Returns the n-th projection of this product if 0<n<=arity, otherwise null
+ * @param n number of the projection to be returned
+ * @throws IndexOutOfBoundsException
+ */
+ override def element(n: Int) = n match {
+ case 1 => _1
+ case 2 => _2
+ case 3 => _3
+ case 4 => _4
+ case 5 => _5
+ case 6 => _6
+ case _ => throw new IndexOutOfBoundsException(n.toString())
+ }
+
+ /** projection of this product */
def _1:T1
+
+ /** projection of this product */
def _2:T2
+
+ /** projection of this product */
def _3:T3
+
+ /** projection of this product */
def _4:T4
+
+ /** projection of this product */
def _5:T5
+
+ /** projection of this product */
def _6:T6
+
}
diff --git a/src/library/scala/Product7.scala b/src/library/scala/Product7.scala
index 523c7c6dc6..ce0ebfaac0 100644
--- a/src/library/scala/Product7.scala
+++ b/src/library/scala/Product7.scala
@@ -7,18 +7,57 @@
** |/ **
\* */
-// generated on Fri Oct 27 18:56:23 CEST 2006
+// generated on Sun Nov 05 03:50:36 CET 2006
package scala
import Predef._
-trait Product7 [+T1, +T2, +T3, +T4, +T5, +T6, +T7] {
+/** Product7 is a cartesian product of 7 components
+ */
+trait Product7 [+T1, +T2, +T3, +T4, +T5, +T6, +T7] extends Product {
+
+ /**
+ * The arity of this product.
+ * @return 7
+ */
+ override def arity = 7
+
+ /**
+ * Returns the n-th projection of this product if 0<n<=arity, otherwise null
+ * @param n number of the projection to be returned
+ * @throws IndexOutOfBoundsException
+ */
+ override def element(n: Int) = n match {
+ case 1 => _1
+ case 2 => _2
+ case 3 => _3
+ case 4 => _4
+ case 5 => _5
+ case 6 => _6
+ case 7 => _7
+ case _ => throw new IndexOutOfBoundsException(n.toString())
+ }
+
+ /** projection of this product */
def _1:T1
+
+ /** projection of this product */
def _2:T2
+
+ /** projection of this product */
def _3:T3
+
+ /** projection of this product */
def _4:T4
+
+ /** projection of this product */
def _5:T5
+
+ /** projection of this product */
def _6:T6
+
+ /** projection of this product */
def _7:T7
+
}
diff --git a/src/library/scala/Product8.scala b/src/library/scala/Product8.scala
index 57ee647c69..bbe8275f6b 100644
--- a/src/library/scala/Product8.scala
+++ b/src/library/scala/Product8.scala
@@ -7,19 +7,61 @@
** |/ **
\* */
-// generated on Fri Oct 27 18:56:23 CEST 2006
+// generated on Sun Nov 05 03:50:36 CET 2006
package scala
import Predef._
-trait Product8 [+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8] {
+/** Product8 is a cartesian product of 8 components
+ */
+trait Product8 [+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8] extends Product {
+
+ /**
+ * The arity of this product.
+ * @return 8
+ */
+ override def arity = 8
+
+ /**
+ * Returns the n-th projection of this product if 0<n<=arity, otherwise null
+ * @param n number of the projection to be returned
+ * @throws IndexOutOfBoundsException
+ */
+ override def element(n: Int) = n match {
+ case 1 => _1
+ case 2 => _2
+ case 3 => _3
+ case 4 => _4
+ case 5 => _5
+ case 6 => _6
+ case 7 => _7
+ case 8 => _8
+ case _ => throw new IndexOutOfBoundsException(n.toString())
+ }
+
+ /** projection of this product */
def _1:T1
+
+ /** projection of this product */
def _2:T2
+
+ /** projection of this product */
def _3:T3
+
+ /** projection of this product */
def _4:T4
+
+ /** projection of this product */
def _5:T5
+
+ /** projection of this product */
def _6:T6
+
+ /** projection of this product */
def _7:T7
+
+ /** projection of this product */
def _8:T8
+
}
diff --git a/src/library/scala/Product9.scala b/src/library/scala/Product9.scala
index e7a7f73982..354d1d09ef 100644
--- a/src/library/scala/Product9.scala
+++ b/src/library/scala/Product9.scala
@@ -7,20 +7,65 @@
** |/ **
\* */
-// generated on Fri Oct 27 18:56:23 CEST 2006
+// generated on Sun Nov 05 03:50:36 CET 2006
package scala
import Predef._
-trait Product9 [+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9] {
+/** Product9 is a cartesian product of 9 components
+ */
+trait Product9 [+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9] extends Product {
+
+ /**
+ * The arity of this product.
+ * @return 9
+ */
+ override def arity = 9
+
+ /**
+ * Returns the n-th projection of this product if 0<n<=arity, otherwise null
+ * @param n number of the projection to be returned
+ * @throws IndexOutOfBoundsException
+ */
+ override def element(n: Int) = n match {
+ case 1 => _1
+ case 2 => _2
+ case 3 => _3
+ case 4 => _4
+ case 5 => _5
+ case 6 => _6
+ case 7 => _7
+ case 8 => _8
+ case 9 => _9
+ case _ => throw new IndexOutOfBoundsException(n.toString())
+ }
+
+ /** projection of this product */
def _1:T1
+
+ /** projection of this product */
def _2:T2
+
+ /** projection of this product */
def _3:T3
+
+ /** projection of this product */
def _4:T4
+
+ /** projection of this product */
def _5:T5
+
+ /** projection of this product */
def _6:T6
+
+ /** projection of this product */
def _7:T7
+
+ /** projection of this product */
def _8:T8
+
+ /** projection of this product */
def _9:T9
+
}
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index 10d8683891..f32db05a23 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -75,23 +75,50 @@ object ScalaRunTime {
else x.caseElement(from) :: fields(from + 1);
fields(0)
}
-
- def _toString(x: CaseClass): String = {
+ def caseFields(x: Product): List[Any] = {
+ val arity = x.arity;
+ def fields(from: Int): List[Any] =
+ if (from > arity) List()
+ else x.element(from) :: fields(from + 1);
+ fields(1)
+ }
+ def _toStringCaseClass(x: CaseClass): String = {
caseFields(x).mkString(x.caseName + "(", ",", ")")
}
-
- def _hashCode(x: CaseClass): Int = {
+ def _toStringProduct(x: Product): String = {
+ caseFields(x).mkString(x.productPrefix + "(", ",", ")")
+ }
+ /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */
+ def _toString(x: AnyRef): String = x match {
+ case xc: CaseClass => _toStringCaseClass(xc)
+ case xp: Product => _toStringProduct(xp)
+ }
+ def _hashCodeCaseClass(x: CaseClass): Int = {
var code = x.getClass().hashCode();
- val arity = x.caseArity;
+ val arr = x.caseArity
var i = 0;
- while (i < arity) {
+ while (i < arr) {
code = code * 41 + x.caseElement(i).hashCode();
i = i + 1
}
code
}
-
- def _equals(x: CaseClass, y: Any): Boolean = y match {
+ def _hashCodeProduct(x: Product): Int = {
+ var code = x.getClass().hashCode();
+ val arr = x.arity
+ var i = 1;
+ while (i <= arr) {
+ code = code * 41 + x.element(i).hashCode();
+ i = i + 1
+ }
+ code
+ }
+ /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */
+ def _hashCode(x: AnyRef): Int = x match {
+ case xc: CaseClass => _hashCodeCaseClass(xc)
+ case xp: Product => _hashCodeProduct(xp)
+ }
+ def _equalsCaseClass(x: CaseClass, y: Any): Boolean = y match {
case y1: CaseClass =>
/*(x.getClass() eq y1.getClass() &&*/ {
val arity = x.caseArity;
@@ -103,7 +130,23 @@ object ScalaRunTime {
case _ =>
false
}
-
+ def _equalsProduct(x: Product, y: Any): Boolean = y match {
+ case y1: Product if x.arity == y1.arity =>
+ /*(x.getClass() eq y1.getClass() &&*/ {
+ val arity = x.arity;
+ var i = 1;
+ while (i <= arity && x.element(i) == y1.element(i))
+ i = i + 1;
+ i == arity + 1
+ }
+ case _ =>
+ false
+ }
+ /** only for bootstrapping 2.2.1 remove afterwards, keeping only _equalsProduct */
+ def _equals(x: AnyRef, y: Any): Boolean = x match {
+ case xc: CaseClass => _equalsCaseClass(xc, y)
+ case xp: Product => _equalsProduct(xp, y)
+ }
//def checkDefined[T >: Null](x: T): T =
// if (x == null) throw new UndefinedException else x
diff --git a/src/library/scala/runtime/matching/Address.scala b/src/library/scala/runtime/matching/Address.scala
deleted file mode 100644
index e8f09d50c9..0000000000
--- a/src/library/scala/runtime/matching/Address.scala
+++ /dev/null
@@ -1,38 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.runtime.matching ;
-
-
-object Address {
- def empty = new Address();
-}
-
-//import List.list2ordered;
-
-/** Address holds the path in reverse Dewey notation
-*/
-class Address( l:Int* ) extends Ordered[Address] {
-
- private val list:List[Int] = l.toList;
-
- def compare (y: Address): int = list.reverse.compare(y.list.reverse)
-
- def down: Address = new Address( ( 1 :: list ):_* );
-
- /** precond: p is nonempty */
- def right: Address = list match {
- case i :: rest => new Address( ((i+1) :: rest ):_* )
- }
-
- override def toString() = list.mkString("Address(",".",")");
-
-}
diff --git a/src/library/scala/runtime/matching/NonTerm.scala b/src/library/scala/runtime/matching/NonTerm.scala
deleted file mode 100644
index d97e3e94b3..0000000000
--- a/src/library/scala/runtime/matching/NonTerm.scala
+++ /dev/null
@@ -1,58 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.runtime.matching ;
-
-
-import scala.collection.immutable ;
-
-abstract class NonTerm {
-
- override def toString() = this match {
- case TreeNT( i ) => "t"+i;
- case h @ HedgeNT( i ) => "h"+i+{ if( h.nullable )"~" else "" };
- }
-
-}
-
-/** tree nonterminal. holds set of binding variable indices.
- */
-case class TreeNT(i:int) extends NonTerm with Ordered[TreeNT] {
-
- var vset:immutable.Set[Int] = new immutable.TreeSet[Int]() ;
-
- /** vset should be sorted to allow fast lookup */
- def this( i:int, vset:immutable.Set[Int] ) = {
- this( i );
- this.vset = new immutable.TreeSet[Int]() incl vset ;
- }
-
- def compare (y: TreeNT): int = i compare y.i
-}
-
-/** hedge nonterminals. holds nullable property.
- */
-case class HedgeNT(i:int) extends NonTerm with Ordered[HedgeNT] {
-
- var nullable:boolean = false;
-
- def this( i:int, nullable:boolean ) = {
- this( i );
- this.nullable = nullable;
- }
-
- def compare (y: HedgeNT): int = i compare y.i
-}
-
-//case object EMPTYHEDGE extends HedgeNT( 0, true ) ;
-//case object ANYHEDGE extends HedgeNT( 1, true ) ;
-object ANYTREE extends TreeNT( 1 );
-
diff --git a/src/library/scala/runtime/matching/PatternTests.scala b/src/library/scala/runtime/matching/PatternTests.scala
deleted file mode 100644
index 6fefc5e276..0000000000
--- a/src/library/scala/runtime/matching/PatternTests.scala
+++ /dev/null
@@ -1,17 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.runtime.matching ;
-
-
-abstract class PatternTests extends Function2[Int,Any,Boolean]{
- def apply(i:Int, inp:Any): Boolean;
-}
diff --git a/src/library/scala/runtime/matching/Rule.scala b/src/library/scala/runtime/matching/Rule.scala
deleted file mode 100644
index b9a14d6063..0000000000
--- a/src/library/scala/runtime/matching/Rule.scala
+++ /dev/null
@@ -1,112 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.runtime.matching ;
-
-
-/* hedge grammar rules */
-abstract class Rule extends Ordered[Rule] {
-
- def compare (that: Rule): int = {
- if( rule_smaller( this, that ) )
- -1
- else if( rule_eq( this, that ) )
- 0
- else
- 1
- }
-
- final def rule_smaller( r1:Rule, r2:Rule ):boolean = r1 match {
- case HedgeRule( h1, _, hh1 ) => r2 match {
- case HedgeRule( h2, _, hh2 ) =>
- ((h1 == h2)&&( hh1.i < hh2.i )) || h1.i < h2.i;
- case HedgeChainRule( h2, hh2 ) =>
- ((h1 == h2)&&( hh1.i < hh2.i )) || h1.i < h2.i;
- case _ => false;
- }
- case HedgeChainRule( h1, hh1 ) => r2 match {
- case HedgeRule( h2, _, hh2 ) =>
- ((h1 == h2)&&( hh1.i < hh2.i )) || h1.i < h2.i;
- case HedgeChainRule( h2, hh2 ) =>
- ((h1 == h2)&&( hh1.i < hh2.i )) || h1.i < h2.i;
- case _ => false;
- }
- case TreeRule( t1, _, hh1 ) => r2 match {
- case TreeRule( t2, _, hh2 ) =>
- ((t1 == t2 )&&(hh1.i < hh2.i )) || t1.i < t2.i;
- case AnyTreeRule( t2 ) => false;
- case AnyNodeRule( t2, hh2 ) =>
- ((t1 == t2 )&&(hh1.i < hh2.i )) || t1.i < t2.i;
- case _ => true;
- }
- case AnyTreeRule( t1 ) => r2 match {
- case TreeRule( _, _ , _ ) => true;
- case AnyTreeRule( t2 ) => t1.i < t2.i;
- case AnyNodeRule( t2, _ ) => true
- case _ => true;
- }
- case AnyNodeRule( t1, hh1 ) => r2 match {
- case TreeRule( t2, _, hh2 ) =>
- ((t1 == t2 )&&(hh1.i < hh2.i )) || t1.i < t2.i;
- case AnyTreeRule( t2 ) => false;
- case AnyNodeRule( t2, hh2 ) =>
- ((t1 == t2 )&&(hh1.i < hh2.i )) || t1.i < t2.i;
- case _ => true;
- }
- };
- final def rule_eq( r1:Rule, r2:Rule ):boolean = r1 == r2;
-
-
- override def toString() = this match {
- case HedgeChainRule( n, m ) =>
- n.toString()+" ::= "+m.toString();
-
- case TreeRule( n, label, n2 ) =>
- (n.toString()+{ if( !n.vset.isEmpty ) n.vset.toString() else "" }+
- " ::= "+label+"( "+n2.toString()+{if( n2.nullable ) "~" else ""}+" )")
-
- case AnyTreeRule( n ) =>
- n.toString()+{ if( !n.vset.isEmpty ) n.vset.toString() else "" }+" ::= _ ";
-
- case AnyNodeRule( n, h ) =>
- n.toString()+{ if( !n.vset.isEmpty ) n.vset.toString() else "" }+" ::= _ ( "+h.toString()+" )";
-
- case HedgeRule( n, t, h ) =>
- n.toString()+(
- if( n.nullable ) "~" else " "
- )+" ::= "+(
- if( t == ANYTREE ) "_" else t.toString()
- )+" "+h.toString();
-
- }
-}
-
-abstract class TRule extends Rule;
-abstract class HRule extends Rule;
-/*
-a tree rule is of the from A -> s(B)
-where A,B are TreeNTs and s is an identifier (string).
-
-If s is the empty string, then the node label is arbitrary
-If HedgeNT is AnyHedgeNT, then the tree is arbitrary
-*/
-case class HedgeChainRule( n: HedgeNT, rhs: HedgeNT ) extends HRule;
-case class TreeRule( n:TreeNT, test:Int, h:HedgeNT ) extends TRule {
- def this(i:Int, s:Int, n:Int ) = {
- this( new TreeNT(i), s, new HedgeNT(n));
- }
-};
-case class AnyTreeRule( n:TreeNT ) extends TRule {
-}
-case class AnyNodeRule( n:TreeNT, h:HedgeNT ) extends TRule {
-}
-case class HedgeRule( n:HedgeNT, t:TreeNT, h:HedgeNT ) extends HRule;
-
diff --git a/src/library/scala/runtime/matching/TestAlphabet.scala b/src/library/scala/runtime/matching/TestAlphabet.scala
deleted file mode 100644
index 39237b4aa5..0000000000
--- a/src/library/scala/runtime/matching/TestAlphabet.scala
+++ /dev/null
@@ -1,21 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.runtime.matching ;
-
-
-abstract class TestAlphabet;
-
-case class TestLabel(i: Int) extends TestAlphabet ;
-
-case object AnyNode extends TestAlphabet {
- def view(x: Int): TestLabel = TestLabel(x);
-}
diff --git a/src/library/scala/xml/Comment.scala b/src/library/scala/xml/Comment.scala
index 2f4ad96e9e..484d72def8 100644
--- a/src/library/scala/xml/Comment.scala
+++ b/src/library/scala/xml/Comment.scala
@@ -42,6 +42,6 @@ case class Comment(commentText: String) extends SpecialNode {
override def text = ""
/** appends &quot;<!-- text -->&quot; to this stringbuffer */
- def toString(sb: StringBuilder) =
+ override def toString(sb: StringBuilder) =
sb.append("<!--").append(commentText).append("-->")
}
diff --git a/src/library/scala/xml/EntityRef.scala b/src/library/scala/xml/EntityRef.scala
index a649ab4d5b..33cdef33e3 100644
--- a/src/library/scala/xml/EntityRef.scala
+++ b/src/library/scala/xml/EntityRef.scala
@@ -45,7 +45,7 @@ case class EntityRef(entityName: String) extends SpecialNode {
}
/** appends "&amp; entityName;" to this stringbuffer */
- def toString(sb: StringBuilder) =
+ override def toString(sb: StringBuilder) =
sb.append("&").append(entityName).append(";")
}
diff --git a/src/library/scala/xml/MetaData.scala b/src/library/scala/xml/MetaData.scala
index 4e1d48f532..d06f2649f0 100644
--- a/src/library/scala/xml/MetaData.scala
+++ b/src/library/scala/xml/MetaData.scala
@@ -162,7 +162,7 @@ abstract class MetaData extends Iterable[MetaData] {
sb.toString()
}
- def toString(sb: StringBuilder): Unit = {
+ def toString(sb: StringBuilder): StringBuilder = {
sb.append(' ')
toString1(sb)
next.toString(sb)
diff --git a/src/library/scala/xml/Null.scala b/src/library/scala/xml/Null.scala
index e5a4290055..eedc208a2c 100644
--- a/src/library/scala/xml/Null.scala
+++ b/src/library/scala/xml/Null.scala
@@ -69,7 +69,7 @@ case object Null extends MetaData {
override def toString(): String = ""
- override def toString(sb: StringBuilder): Unit = {}
+ override def toString(sb: StringBuilder): StringBuilder = sb
override def wellformed(scope: NamespaceBinding) = true
diff --git a/src/library/scala/xml/ProcInstr.scala b/src/library/scala/xml/ProcInstr.scala
index a355bb3eb4..1b3f78e01f 100644
--- a/src/library/scala/xml/ProcInstr.scala
+++ b/src/library/scala/xml/ProcInstr.scala
@@ -54,7 +54,7 @@ case class ProcInstr(target:String, proctext:String) extends SpecialNode {
/** appends &quot;&lt;?&quot; target (&quot; &quot;+text)?+&quot;?&gt;&quot;
* to this stringbuffer.
*/
- def toString(sb: StringBuilder) = {
+ override def toString(sb: StringBuilder) = {
sb
.append("<?")
.append(target);
diff --git a/src/library/scala/xml/SpecialNode.scala b/src/library/scala/xml/SpecialNode.scala
index f68396250d..9fb23a64a3 100644
--- a/src/library/scala/xml/SpecialNode.scala
+++ b/src/library/scala/xml/SpecialNode.scala
@@ -29,9 +29,7 @@ abstract class SpecialNode extends Node with pull.XMLEvent {
/** always empty */
final def child = Nil
- final override def toString(): String =
- toString(new StringBuilder()).toString()
-
+ /** append string representation to the given stringbuffer */
def toString(sb: StringBuilder): StringBuilder
}
diff --git a/src/library/scala/xml/dtd/ContentModel.scala b/src/library/scala/xml/dtd/ContentModel.scala
index 4ba9b8a51e..0f7eb6e8cb 100644
--- a/src/library/scala/xml/dtd/ContentModel.scala
+++ b/src/library/scala/xml/dtd/ContentModel.scala
@@ -134,13 +134,13 @@ sealed abstract class ContentModel {
}
case object PCDATA extends ContentModel {
- def toString(sb:StringBuilder): StringBuilder = sb.append("(#PCDATA)");
+ override def toString(sb:StringBuilder): StringBuilder = sb.append("(#PCDATA)");
}
case object EMPTY extends ContentModel {
- def toString(sb:StringBuilder): StringBuilder = sb.append("EMPTY");
+ override def toString(sb:StringBuilder): StringBuilder = sb.append("EMPTY");
}
case object ANY extends ContentModel {
- def toString(sb:StringBuilder): StringBuilder = sb.append("ANY");
+ override def toString(sb:StringBuilder): StringBuilder = sb.append("ANY");
}
abstract class DFAContentModel extends ContentModel {
import ContentModel.{ ElemName };
@@ -178,7 +178,7 @@ Console.println("ns = "+ns);
}
}
*/
- def toString(sb:StringBuilder): StringBuilder = {
+ override def toString(sb:StringBuilder): StringBuilder = {
sb.append("(#PCDATA|");
//r match {
// case Alt(Eps, rs@_*) => ContentModel.toString(Alt(rs:_*):RegExp, sb);
@@ -207,6 +207,6 @@ case class ELEMENTS(r:ContentModel.RegExp) extends DFAContentModel {
}
}
*/
- def toString(sb:StringBuilder): StringBuilder =
+ override def toString(sb:StringBuilder): StringBuilder =
ContentModel.toString(r, sb);
}
diff --git a/src/library/scala/xml/dtd/Decl.scala b/src/library/scala/xml/dtd/Decl.scala
index 3a000baac5..3aec3b1c70 100644
--- a/src/library/scala/xml/dtd/Decl.scala
+++ b/src/library/scala/xml/dtd/Decl.scala
@@ -1,10 +1,10 @@
/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
+ ** ________ ___ / / ___ Scala API **
+ ** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
+ ** __\ \/ /__/ __ |/ /__/ __ | **
+ ** /____/\___/_/ |_/____/_/ | | **
+ ** |/ **
+ \* */
// $Id$
@@ -17,13 +17,7 @@ import compat.StringBuilder
abstract class Decl;
abstract class MarkupDecl extends Decl {
-
- final override def toString(): String = {
- toString(new StringBuilder()).toString();
- }
-
def toString(sb: StringBuilder): StringBuilder;
-
}
/** an element declaration
@@ -32,7 +26,7 @@ case class ElemDecl(name: String, contentModel: ContentModel) extends MarkupDecl
//def mixed = ; // to do
- def toString(sb: StringBuilder): StringBuilder = {
+ override def toString(sb: StringBuilder): StringBuilder = {
sb
.append("<!ELEMENT ")
.append(name)
@@ -46,7 +40,7 @@ case class ElemDecl(name: String, contentModel: ContentModel) extends MarkupDecl
case class AttListDecl(name: String, attrs:List[AttrDecl]) extends MarkupDecl with DtdTypeSymbol {
- def toString(sb: StringBuilder): StringBuilder = {
+ override def toString(sb: StringBuilder): StringBuilder = {
sb
.append("<!ATTLIST ")
.append(name)
@@ -61,10 +55,10 @@ case class AttListDecl(name: String, attrs:List[AttrDecl]) extends MarkupDecl wi
*/
case class AttrDecl( name:String, tpe:String, default:DefaultDecl ) {
- final override def toString(): String =
+ override def toString(): String =
toString(new StringBuilder()).toString();
- final def toString(sb: StringBuilder): StringBuilder = {
+ def toString(sb: StringBuilder): StringBuilder = {
sb.append(" ").append( name ).append(' ').append( tpe ).append(' ');
default.toString(sb)
}
@@ -77,7 +71,7 @@ abstract class EntityDecl extends MarkupDecl;
/** a parsed general entity declaration */
case class ParsedEntityDecl( name:String, entdef:EntityDef ) extends EntityDecl {
- final def toString(sb: StringBuilder): StringBuilder = {
+ override def toString(sb: StringBuilder): StringBuilder = {
sb.append("<!ENTITY ").append( name ).append(' ');
entdef.toString(sb).append('>');
}
@@ -85,8 +79,7 @@ case class ParsedEntityDecl( name:String, entdef:EntityDef ) extends EntityDecl
/** a parameter entity declaration */
case class ParameterEntityDecl(name: String, entdef: EntityDef) extends EntityDecl {
-
- final def toString(sb: StringBuilder): StringBuilder = {
+ override def toString(sb: StringBuilder): StringBuilder = {
sb.append("<!ENTITY % ").append( name ).append(' ');
entdef.toString(sb).append('>');
}
@@ -94,23 +87,20 @@ case class ParameterEntityDecl(name: String, entdef: EntityDef) extends EntityDe
/** an unparsed entity declaration */
case class UnparsedEntityDecl( name:String, extID:ExternalID, notation:String ) extends EntityDecl {
- final def toString(sb: StringBuilder): StringBuilder = {
+ override def toString(sb: StringBuilder): StringBuilder = {
sb.append("<!ENTITY ").append( name ).append(' ');
extID.toString(sb).append(" NDATA ").append(notation).append('>');
}
}
/** a notation declaration */
case class NotationDecl( name:String, extID:ExternalID ) extends MarkupDecl {
- final def toString(sb: StringBuilder): StringBuilder = {
+ override def toString(sb: StringBuilder): StringBuilder = {
sb.append("<!NOTATION ").append( name ).append(' ');
extID.toString(sb);
}
}
abstract class EntityDef {
- final override def toString(): String =
- toString(new StringBuilder()).toString();
-
def toString(sb: StringBuilder): StringBuilder;
}
@@ -135,13 +125,13 @@ case class IntDef(value:String) extends EntityDef {
}
validateValue();
- final def toString(sb: StringBuilder): StringBuilder =
+ override def toString(sb: StringBuilder): StringBuilder =
Utility.appendQuoted(value, sb);
}
case class ExtDef(extID:ExternalID) extends EntityDef {
- final def toString(sb: StringBuilder): StringBuilder =
+ override def toString(sb: StringBuilder): StringBuilder =
extID.toString(sb);
}
@@ -152,7 +142,7 @@ case class PEReference(ent:String) extends MarkupDecl {
if( !Utility.isName( ent ))
throw new IllegalArgumentException("ent must be an XML Name");
- final def toString(sb: StringBuilder): StringBuilder =
+ override def toString(sb: StringBuilder): StringBuilder =
sb.append('%').append(ent).append(';');
}
@@ -165,20 +155,20 @@ abstract class DefaultDecl {
}
case object REQUIRED extends DefaultDecl {
- final override def toString(): String = "#REQUIRED";
- final def toString(sb:StringBuilder) = sb.append("#REQUIRED");
+ override def toString(): String = "#REQUIRED";
+ override def toString(sb:StringBuilder) = sb.append("#REQUIRED");
}
case object IMPLIED extends DefaultDecl {
- final override def toString(): String = "#IMPLIED";
- final def toString(sb:StringBuilder) = sb.append("#IMPLIED");
+ override def toString(): String = "#IMPLIED";
+ override def toString(sb:StringBuilder) = sb.append("#IMPLIED");
}
case class DEFAULT(fixed: Boolean, attValue:String) extends DefaultDecl {
- final override def toString(): String =
+ override def toString(): String =
toString(new StringBuilder()).toString();
- final def toString(sb:StringBuilder): StringBuilder = {
+ override def toString(sb:StringBuilder): StringBuilder = {
if(fixed)
sb.append("#FIXED ");
Utility.appendEscapedQuoted( attValue, sb );
diff --git a/src/library/scala/xml/dtd/ExternalID.scala b/src/library/scala/xml/dtd/ExternalID.scala
index 6fa5d4823d..304c8b01e0 100644
--- a/src/library/scala/xml/dtd/ExternalID.scala
+++ b/src/library/scala/xml/dtd/ExternalID.scala
@@ -9,7 +9,7 @@
// $Id$
-package scala.xml.dtd;
+package scala.xml.dtd
import compat.StringBuilder
@@ -24,12 +24,12 @@ import compat.StringBuilder
abstract class ExternalID {
/** returns "PUBLIC "+publicLiteral+" SYSTEM "+systemLiteral */
- override def toString(): String;
+ override def toString(): String
/** returns "PUBLIC "+publicLiteral+" SYSTEM "+systemLiteral */
- def toString(sb: StringBuilder): StringBuilder;
+ def toString(sb: StringBuilder): StringBuilder
- def systemId: String;
+ def systemId: String
}
@@ -44,13 +44,13 @@ case class SystemID( systemId:String ) extends ExternalID with parsing.TokenTest
if( !checkSysID( systemId ) )
throw new IllegalArgumentException(
"can't use both \" and ' in systemLiteral"
- );
+ )
/** returns " SYSTEM "+systemLiteral */
- final override def toString() =
- Utility.systemLiteralToString( systemId );
+ override def toString() =
+ Utility.systemLiteralToString( systemId )
- final def toString(sb: StringBuilder): StringBuilder =
- Utility.systemLiteralToString( sb, systemId );
+ override def toString(sb: StringBuilder): StringBuilder =
+ Utility.systemLiteralToString( sb, systemId )
}
@@ -61,38 +61,30 @@ case class SystemID( systemId:String ) extends ExternalID with parsing.TokenTest
* @param systemLiteral (can be null for notation pubIDs) the system identifier literal
**/
case class PublicID( publicId:String, systemId:String ) extends ExternalID with parsing.TokenTests{
- //Console.println("constructing PublicID \""+publicLiteral+"\" "+systemLiteral);
-
- //Console.println("util returns "+checkPubID( publicLiteral ));
if( !checkPubID( publicId ))
throw new IllegalArgumentException(
"publicId must consist of PubidChars"
- );
+ )
if( systemId != null && !checkSysID( systemId ) )
throw new IllegalArgumentException(
"can't use both \" and ' in systemId"
- );
+ )
/** the constant "#PI" */
- final def label = "#PI";
+ def label = "#PI"
/** always empty */
- final def attribute = Node.NoAttributes;
+ def attribute = Node.NoAttributes
/** always empty */
- final def child = Nil;
-
- /** returns "PUBLIC "+publicId+" SYSTEM "+systemId */
- final override def toString(): String = {
- toString(new StringBuilder()).toString();
- }
+ def child = Nil
/** appends "PUBLIC "+publicId+" SYSTEM "+systemId to argument */
- final def toString(sb: StringBuilder): StringBuilder = {
- Utility.publicLiteralToString( sb, publicId ).append(' ');
+ override def toString(sb: StringBuilder): StringBuilder = {
+ Utility.publicLiteralToString( sb, publicId ).append(' ')
if(systemId!=null)
- Utility.systemLiteralToString( sb, systemId );
+ Utility.systemLiteralToString( sb, systemId )
else
sb
}