summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2008-04-07 16:09:34 +0000
committerMartin Odersky <odersky@gmail.com>2008-04-07 16:09:34 +0000
commit9d37cdde4271f2e8016e369c90b2748616d87e49 (patch)
tree537c2e55221d10f65afa093344f6223ca3479109
parent34fe33a61291ec51cb0598b3702b2c6de8ebb3f2 (diff)
downloadscala-9d37cdde4271f2e8016e369c90b2748616d87e49.tar.gz
scala-9d37cdde4271f2e8016e369c90b2748616d87e49.tar.bz2
scala-9d37cdde4271f2e8016e369c90b2748616d87e49.zip
removed some files (the stuff in scala.util.mat...
removed some files (the stuff in scala.util.matching got copied into experimental/regex)
-rw-r--r--src/library/scala/CharSequence.scala172
-rw-r--r--src/library/scala/LazyCharSequence.scala265
-rw-r--r--src/library/scala/util/matching/BitField.scala149
-rw-r--r--src/library/scala/util/matching/DArrowAssoc.scala40
-rw-r--r--src/library/scala/util/matching/DelayedPair.scala26
-rw-r--r--src/library/scala/util/matching/FixedBitField.scala98
-rw-r--r--src/library/scala/util/matching/MatchData.scala64
-rw-r--r--src/library/scala/util/matching/MatchableBigInt.scala29
-rw-r--r--src/library/scala/util/matching/Regex.scala28
-rw-r--r--src/library/scala/util/matching/TaintedInt.scala58
-rw-r--r--src/library/scala/util/parsing/combinator/lexical/Scanners.scala2
-rw-r--r--src/library/scala/util/parsing/combinatorold/lexical/Scanners.scala2
-rw-r--r--src/library/scala/util/parsing/input/OffsetPosition.scala2
13 files changed, 17 insertions, 918 deletions
diff --git a/src/library/scala/CharSequence.scala b/src/library/scala/CharSequence.scala
deleted file mode 100644
index 651650471c..0000000000
--- a/src/library/scala/CharSequence.scala
+++ /dev/null
@@ -1,172 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id:
-
-
-package scala
-
-import java.io._
-import collection._
-import util.matching.Regex
-
-/** A Scala abstraction of character sequences, similar to, but richer than,
- * java.lang.CharSequence. Sequences can be fixed or lazy. A lazy
- * character sequence may be constructed only while it is read.
- *
- * @author Martin Odersky
- */
-trait CharSequence extends java.lang.CharSequence with Seq[Char] {
-
- /** The length of the character sequence
- * Note: if char sequence is lazy, calling this method
- * will force sequence to be read until the end.
- */
- def length: Int
-
- /** The character at position `index'.
- */
- def charAt(index: Int): Char
-
- /** Is character sequence defined at `index'?
- * Unlike `length' this operation does not force reading
- * a lazy sequence to the end.
- * (the implementation of that method is inherited from Seq).
- */
- def isDefinedAt(index: Int): Boolean
-
- /** Optionally the character at position `index'. None is not in range.
- */
- def get(index: Int): Option[Char] =
- if (isDefinedAt(index)) Some(charAt(index))
- else None
-
- /** The character at position `index'. (same as `charAt')
- */
- def apply(index: Int): Char = charAt(index)
-
- /** the subsequence from index `start' up to and excluding
- * the minimum of index `end' and the length of current sequence.
- */
- def subSequence(start: Int, end: Int): CharSequence
-
- /** The subsequence from index `start' until the end of the current sequence
- * If sequence is lazy, this operation does not force reading to the end.
- */
- def subSequence(start: Int): CharSequence =
- subSequence(start, length)
-
- /** Convert sequence to string */
- def toString: String
-
- /** the elements of this sequence */
- def elements: Iterator[Char] = new Iterator[Char] {
- private var index = 0
- def hasNext: Boolean = isDefinedAt(index)
- def next: Char = {
- val ch = charAt(index)
- index += 1
- ch
- }
- }
-
- /** Return all matches of given regexp in this character sequence as an iterator
- */
- def findAll(regex: Regex): Regex.MatchIterator = regex findAllIn this
-
- /** Return first match of given regexp in this character sequence as an optional value
- */
- def findFirst(regex: Regex): Option[String] = regex findFirstIn this
-
- /** Return first match of given regexp in this character sequence as an optional value
- */
- def findFirstMatch(regex: Regex): Option[Regex.Match] = regex findFirstMatchIn this
-
- /** Return optionally string matching given regexp at the beginning of this
- * character sequence, or None if regexp matches no prefix
- * of the character sequence.
- */
- def findPrefix(regex: Regex): Option[String] = regex findPrefixOf this
-
- /** Return optionally match for given regexp at the beginning of this
- * character sequence, or None if regexp matches no prefix
- * of the character sequence.
- */
- def findPrefixMatch(regex: Regex): Option[Regex.Match] = regex findPrefixMatchOf this
-
- /** Replaces all matches of given regexp by a string.
- *
- * @param regex The regex to match with
- * @param replacement The string that will replace each match
- * @return The resulting string
- */
- def replaceAll(regex: Regex, replacement: String): String = regex replaceAllIn (this, replacement)
-
- /** Replaces the first match of given regexp by a string.
- *
- * @param target The string to match
- * @param replacement The string that will replace the match
- * @return The resulting string
- */
- def replaceFirst(regex: Regex, replacement: String): String = regex replaceFirstIn (this, replacement)
-
- def toArray: Array[Char] = {
- val len = length
- val result = new Array[Char](len)
- var i = 0
- while (i < len) {
- result(i) = charAt(i)
- i += 1
- }
- result
- }
-}
-
-/** The CharSequence object defines variance implementations of character sequences
- */
-object CharSequence {
-
- def fromJava(source: java.lang.CharSequence): CharSequence =
- new JavaWrapper(source)
-
- def fromArray(source: Array[Char]): CharSequence =
- new AsArray(source, 0, source.length)
- def fromArray(source: Array[Char], start: Int): CharSequence =
- new AsArray(source, start, source.length)
- def fromArray(source: Array[Char], start: Int, end: Int): CharSequence =
- new AsArray(source, start, end)
-
- private class JavaWrapper(source: java.lang.CharSequence) extends CharSequence {
- def length: Int = source.length
- def charAt(index: Int): Char = source.charAt(index)
- def subSequence(start: Int, end: Int): CharSequence = new JavaWrapper(source.subSequence(start, end))
- override def toString: String = source.toString
- }
-
- private class AsArray(source: scala.Array[Char], start: Int, end: Int) extends CharSequence {
- if (start < 0) throw new IndexOutOfBoundsException
- if (end > source.length) throw new IndexOutOfBoundsException
-
- def charAt(index: Int) =
- if (start + index < end) source(index + start)
- else throw new IndexOutOfBoundsException
-
- def length: Int = if (end < start) 0 else end - start
-
- def subSequence(_start: Int, _end: Int) =
- new AsArray(source, start + _start, start + _end)
-
- override def toArray: Array[Char] = {
- val result = new Array[Char](length)
- compat.Platform.arraycopy(source, start, result, 0, length)
- result
- }
-
- override def toString = new String(source, start, end - start)
- }
-}
diff --git a/src/library/scala/LazyCharSequence.scala b/src/library/scala/LazyCharSequence.scala
deleted file mode 100644
index bde51f8bd1..0000000000
--- a/src/library/scala/LazyCharSequence.scala
+++ /dev/null
@@ -1,265 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala
-
-import java.io._
-import util.matching.Regex
-
-
-/** The CharSequence object defines variance implementations of character sequences
- */
-object LazyCharSequence {
- final val UndeterminedEnd = Math.MAX_INT
-
- /** Constructs a character sequence from a character iterator */
- def fromChars(source: Iterator[Char]): CharSequence =
- new LazyCharSequence ((chars: Array[Char], start: Int, len: Int) => {
- var i = 0
- while (i < len && source.hasNext) {
- chars(start + i) = source.next
- i += 1
- }
- if (i == 0) -1 else i
- })
-
- /** Constructs a character sequence from a character iterable */
- def fromChars(source: Iterable[Char]): CharSequence =
- fromChars(source.elements)
-
- /** Constructs a character sequence from a string iterator */
- def fromStrings(source: Iterator[String]): CharSequence = {
- var current: String = ""
- def more(chars: Array[Char], start: Int, len: Int): Int =
- if (current.length != 0) {
- val nchars = current.length min len
- current.getChars(0, nchars, chars, start)
- current = current.substring(nchars)
- if (nchars == len) nchars
- else (more(chars, start + nchars, len - nchars) max 0) + nchars
- } else if (source.hasNext) {
- current = source.next
- more(chars, start, len)
- } else -1
- new LazyCharSequence(more(_: Array[Char], _: Int, _: Int))
- }
-
- /** Constructs a character sequence from a string iterable */
- def fromStrings(source: Iterable[String]): CharSequence =
- fromStrings(source.elements)
-
- /** Constructs a character sequence from a line iterator
- * Lines do not contain trailing `\n' characters; The method inserts
- * a line separator `\n' between any two lines in the sequence.
- */
- def fromLines(source: Iterator[String]): CharSequence = {
- var isFirst = true
- fromStrings(source map { line =>
- if (isFirst) line
- else {
- isFirst = false
- "\n"+line
- }
- })
- }
-
- /** Constructs a character sequence from a line iterable
- * Lines do not contain trailing `\n' characters; The method inserts
- * a line separator `\n' between any two lines in the sequence.
- */
- def fromLines(source: Iterable[String]): CharSequence =
- fromLines(source.elements)
-
- /** Constructs a character sequence from an input reader
- */
- def fromReader(source: Reader): CharSequence =
- new LazyCharSequence(source)
-
- /** Constructs a character sequence from an input file
- */
- def fromFile(source: File) =
- new LazyCharSequence(source)
-
- /** Constructs a character sequence from a file with given name
- */
- def fromFile(source: String) =
- new LazyCharSequence(source)
-
- /** Constructs a character sequence from a scala.io.Source value
- */
- def fromSource(source: io.Source) =
- fromLines(source.getLines)
-}
-
-
-import LazyCharSequence._
-
-/** An implementation of lazily computed character sequences
- *
- * @author Martin Odersky
- */
-class LazyCharSequence protected (more: (Array[Char], Int, Int) => Int,
- first: Page, start: Int, end: Int) extends CharSequence {
-
- /** Constructs a character sequence from a method that produces more characters when asked.
- * The producer method is analogous to the read method in java.io.Reader.
- * It takes three parameters: an array of characters, a start index, and an end index.
- * It should try to fill the array between start and end indices (not including end index).
- * It returns the number of characters produced, or -1 if end of logical input stream was reached
- * before any character was read.
- */
- def this(more: (Array[Char], Int, Int) => Int) = this(more, new Page(0), 0, UndeterminedEnd)
-
- /** Constructs a character sequence from an input reader
- */
- def this(source: Reader) =
- this(source.read(_: Array[Char], _: Int, _: Int))
-
- /** Constructs a character sequence from an input file
- */
- def this(source: File) =
- this(new FileReader(source))
-
- /** Constructs a character sequence from a file with given name
- */
- def this(source: String) =
- this(new File(source))
-
- private var current: Page = first
-
- private def latest = first.latest
-
- private def addMore() = latest.addMore(more)
-
- private def page(absindex: Int) = {
- if (absindex < current.start)
- current = first
- while (absindex >= current.end && current.next != null)
- current = current.next
- while (absindex >= current.end && !current.isLast) {
- current = addMore()
- }
- current
- }
-
- /** The length of the character sequence
- * Note: calling this method will force sequence to be read until the end.
- */
- def length: Int = {
- while (!latest.isLast) addMore()
- (latest.end min end) - start
- }
-
- /** The character at position `index'.
- */
- def charAt(index: Int) =
- if (isDefinedAt(index)) page(index + start)(index + start)
- else throw new IndexOutOfBoundsException(index.toString)
-
- /** Is character sequence defined at `index'?
- * Unlike `length' this operation does not force reading
- * a lazy sequence to the end.
- */
- override def isDefinedAt(index: Int) =
- index >= 0 && index < end - start && {
- val p = page(index + start); index + start < p.end
- }
-
- /** Optionally the character at position `index'. None is not in range.
- */
- override def get(index: Int) =
- if (isDefinedAt(index)) Some(page(index + start)(index + start))
- else None
-
- /** the subsequence from index `start' up to and excluding
- * the minimum of index `end' and the length of current sequence.
- */
- def subSequence(_start: Int, _end: Int) = {
- page(start)
- val s = start + _start
- val e = if (_end == UndeterminedEnd) _end else start + _end
- var f = first
- while (f.end <= s && !f.isLast) f = f.next
- new LazyCharSequence(more, f, s, e)
- }
-
- /** The subsequence from index `start' until the end of the current sequence
- * This operation does not force reading to the end.
- */
- override def subSequence(start: Int): CharSequence =
- subSequence(start, UndeterminedEnd)
-
- /** Convert sequence to string */
- override def toString = {
- val buf = new StringBuilder
- for (ch <- elements) buf append ch
- buf.toString
- }
-}
-
-
-/** Page containing up to PageSize characters of the input sequence.
- */
-private class Page(val num: Int) {
-
- private final val PageSize = 4096
-
- /** The next page in the sequence */
- var next : Page = null
-
- /** A later page in the sequence, serves a cachae for pointing to last page */
- var later : Page = this
-
- /** The number of characters read into this page */
- var filled: Int = 0
-
- /** Is this page the permamnently last one in the sequence? Only true once `more'
- * method has returned -1 to signal end of input. */
- var isLast: Boolean = false
-
- /** The character array */
- final val chars = new Array[Char](PageSize)
-
- /** The index of the first character in this page relative to the whole sequence */
- final def start = num * PageSize
-
- /** The index of the character following the last charcater in this page relative
- * to the whole sequence */
- final def end = start + filled
-
- /** The currently last page in the sequence; might change as more charcaters are appended */
- final def latest: Page = {
- if (later.next != null) later = later.next.latest
- later
- }
-
- /** The character at given sequence index.
- * That index is relative to the whole sequence, not the page. */
- def apply(index: Int) = {
- if (index < start || index - start >= filled) throw new IndexOutOfBoundsException(index.toString)
- chars(index - start)
- }
-
- /** produces more characters by calling `more' and appends them on the current page,
- * or fills a subsequent page if current page is full
- * pre: if current page is full, it is the last one in the sequence.
- */
- final def addMore(more: (Array[Char], Int, Int) => Int): Page =
- if (filled == PageSize) {
- next = new Page(num + 1)
- next.addMore(more)
- } else {
- val count = more(chars, filled, PageSize - filled)
- if (count < 0) isLast = true
- else filled += count
- this
- }
-}
diff --git a/src/library/scala/util/matching/BitField.scala b/src/library/scala/util/matching/BitField.scala
deleted file mode 100644
index c225c89987..0000000000
--- a/src/library/scala/util/matching/BitField.scala
+++ /dev/null
@@ -1,149 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2008, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.util.matching
-
-import scala.collection.immutable._
-
-/** This class provides methods for creating and using BitFields.
- * BitFields can easily parse binary data.
- *
- * @author Thibaud Hottelier
- * @version 1.0, 22/12/2007
- *
- * @param fields the list of pair of name and size for each field.
- */
-class BitField(fields: List[Product2[String, TaintedInt]]) extends FixedBitField {
- /** Create a BitField
- * @param vf pair of name and size for each field.
- */
- def this(vf: Product2[String, TaintedInt]*) = this(vf.toList)
-
- /* Get the position of the first variable-size field */
- val f = fields.zip(fields.indices) find {p => p._1.isInstanceOf[DelayedPair[_, _]]}
- val varPos = if (f.isDefined) f.get._2 else fields.size
-
- /* Split the fixed part and the variable part of fields */
- val fixedFields = fields.slice(0, varPos)
- val variableFields = fields.slice(varPos, fields.size)
-
- /* Create a BitField for the fixed part */
- val fixedPart = new FixedBitField(fixedFields.map(p => Pair(p._1, p._2.toInt)))
-
- /** Helper that parses binary data into a MatchData object */
- private def unapplySeq0(input: Array[Byte]): MatchData[BigInt] = {
- /* Extract the fixed length and the variable length part of the input */
- val max = Math.min(fixedPart.size / 8, input.size)
- val finput = input.subArray(0, max)
- val vinput = input.subArray(max, input.size)
-
- /* Parse the fixed length part */
- val fresult = fixedPart.parse(finput)
- BitField.setRes(fresult)
-
- if (varPos == fields.size)
- fresult
- else {
- /* Parse the variable length part */
- val variablePart = setVariableFields
- val vresult = variablePart.parse(vinput)
- new MatchData[BigInt](BigInt(input) :: vresult.getGroups.tail ::: fresult.getGroups.tail,
- fresult.getNames ++ vresult.getNames)
- }
- }
-
- /** Performs the matching.
- *
- * @param a the array to match
- * @return the contents of each field
- */
- override def parse(a: Array[Byte]): MatchData[BigInt] = unapplySeq0(a)
-
- /** Matches an array of bytes or a MatchData[BigInt] instance.
- *
- * @param target the value to be matched. Has to be an Array[Byte]
- * or an MatchData[BigInt] instance.
- * @return the contents of the fields.
- */
- override def unapplySeq(target: Any): Option[List[BigInt]] = {
- if (target.isInstanceOf[Array[Byte]])
- Some(unapplySeq0(target.asInstanceOf[Array[Byte]]).getGroups.tail.reverse)
- else if (target.isInstanceOf[MatchData[_]])
- Some(unapplySeq0(target.asInstanceOf[MatchData[BigInt]]().toByteArray).getGroups.tail.reverse)
- else
- None
- }
-
- /** This operator is used in for-comprehensions to iterate over matches.
- *
- * @param a the data to match
- * @return the result of the matching
- */
- override def ~~ (a: Array[Byte]) = split(a)
-
- /* Helper that splits up binary data and matches each block one by one */
- private def split(input: Array[Byte]): List[MatchData[BigInt]] = {
- def split0(res: List[Array[Byte]], in: Array[Byte]): List[Array[Byte]] = {
- val fin = input.subArray(0, fixedPart.size / 8)
- val fres = fixedPart.parse(fin)
- BitField.setRes(fres)
- val vp = setVariableFields
- val totalSize = (vp.size + fixedPart.size) / 8
- if (in.length <= totalSize)
- in :: res
- else
- split0(in.slice(0, totalSize) :: res, in.slice(totalSize, in.length))
- }
- split0(Nil, input).reverse map {a => unapplySeq0(a)}
- }
-
- /* Returns a FixedBitField that represents the variable-size fields */
- private def setVariableFields: FixedBitField = {
- var fieldsSize: List[(String, Int)] = Nil
- variableFields.reverse foreach { e => fieldsSize = (e._1, e._2.toInt) :: fieldsSize }
- new FixedBitField(fieldsSize)
- }
-}
-
-/** Contains implicit conversions and helper functions */
-object BitField {
- val fresult = new ThreadLocal[MatchData[BigInt]]
-
- private def setRes(fresult: MatchData[BigInt]) = this.fresult.set(fresult)
-
- /** Use this function to reference the contents of a field previously defined when
- * defining the size of the current field.
- *
- * @param label the name of field
- * @return the contents of the field when matching
- */
- def field(label: String): TaintedInt = {
- new TaintedInt(fresult.get.asInstanceOf[MatchData[BigInt]].apply(label).intValue)
- }
-
- /** Creates a new BitField
- *
- * @param vf (name, size) pairs for each field
- * @return the new BitField instance.
- */
- def apply(vf: Product2[String, TaintedInt]*) = new BitField(vf.toList)
-
- implicit def int2TaintedInt(x: Int): TaintedInt = new TaintedInt(x)
-
- implicit def any2DArrowAssoc[A](x: A): DArrowAssoc[A] = new DArrowAssoc(x)
-
- implicit def IntToMatchableInt(s: Array[Byte]): MatchableBigInt = new MatchableBigInt(s)
-
- implicit def IntoptionToBoolean(o: Option[MatchData[BigInt]]): Boolean = o match {
- case None => false
- case Some(_) => true
- }
-}
diff --git a/src/library/scala/util/matching/DArrowAssoc.scala b/src/library/scala/util/matching/DArrowAssoc.scala
deleted file mode 100644
index 05db9565b9..0000000000
--- a/src/library/scala/util/matching/DArrowAssoc.scala
+++ /dev/null
@@ -1,40 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2008, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.util.matching
-
-/** Only used by BitFields. This class is similar to ArrowAssoc.
- * It defines the --> function that creates a pair if the
- * argument is an Int and a DelayedPair if it is a TaintedInt.
- *
- * @author Thibaud Hottelier
- * @version 1.0, 15/12/2007
- */
-private[matching] class DArrowAssoc[A](x: A) {
-
- /** Creates a DelayedPair
- *
- * @param y the TaintedInt
- * @return the DelayedPair
- */
- def --> (y: => TaintedInt): DelayedPair[A, TaintedInt] = {
- new DelayedPair(x, () => y)
- }
-
- /** Creates a pair
- *
- * @param y the Int
- * @return the pair
- */
- def --> (y: Int): Product2[A, TaintedInt] = {
- (x, new TaintedInt(y))
- }
-}
diff --git a/src/library/scala/util/matching/DelayedPair.scala b/src/library/scala/util/matching/DelayedPair.scala
deleted file mode 100644
index 03333ed5df..0000000000
--- a/src/library/scala/util/matching/DelayedPair.scala
+++ /dev/null
@@ -1,26 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2008, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.util.matching
-
-/** A DelayedPair is similar to a pair, except that the second
- * argument is delayed.
- *
- * @author Thibaud Hottelier
- * @version 1.0, 15/12/2007
- *
- * @param a the first element
- * @param b the second element
- */
-class DelayedPair[A, B](a: A, b: () => B) extends Product2[A, B] {
- override def _1: A = a
- override def _2: B = b()
-}
diff --git a/src/library/scala/util/matching/FixedBitField.scala b/src/library/scala/util/matching/FixedBitField.scala
deleted file mode 100644
index 9228202448..0000000000
--- a/src/library/scala/util/matching/FixedBitField.scala
+++ /dev/null
@@ -1,98 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2008, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.util.matching
-
-/** This class provides methods for creating and using FixedBitFields.
- * If you have variable size fields, see @see BitField.
- *
- * @author Thibaud Hottelier
- * @version 1.0, 3/1/2008
- *
- * @param f the list of (name, size) pairs
- */
-class FixedBitField(f: List[Product2[String, Int]]) {
-
- /** Create a new FixedBitField.
- *
- * @param groups the sequence of (name, size) pairs
- */
- def this(groups: (String, Int)*) = this(groups.toList)
-
- val fields = f.reverse
-
- val size = fields.foldLeft(0)((s, p) => s + p._2)
-
- // works around compiler bug (TODO: which one?)
- val t = (fields.zip(fields.indices)) map {p => (p._1._1, p._2 + 1)}
- val groupNames = Map() ++ t
-
- /** Performs the matching using masks */
- private def buildSeq(res: List[BigInt], a: BigInt, i: int, j: int): List[BigInt] = {
- if (i < 0)
- res
- else {
- var mask = BigInt(0)
- for (k <- List.range(1, fields(i)._2 + 1))
- mask = mask.setBit(j-k)
- buildSeq(((a & mask) >> (j - fields(i)._2))::res, a, i - 1, j - fields(i)._2)
- }
- }
-
- /** Match an Array[Byte] or an MatchData[BigInt] instance.
- *
- * @param target the value to be matched. Has to be an Array[Byte]
- * or a MatchData[BigInt] instance
- * @return the field contents
- */
- def unapplySeq(target: Any): Option[List[BigInt]] = {
- if (target.isInstanceOf[Array[Byte]])
- Some(buildSeq(Nil, BigInt(target.asInstanceOf[Array[Byte]]), fields.size - 1, size))
- else if (target.isInstanceOf[MatchData[_]])
- Some(buildSeq(Nil, target.asInstanceOf[MatchData[BigInt]](), fields.size - 1, size).reverse)
- else
- None
- }
-
- /** This operator is used in for-comprehension to iterate over matches.
- *
- * @param a the data to be matched
- * @return the result of the matching
- */
- def ~~ (a: Array[Byte]) = split(a)
-
- /* Builds a MatchData object from the raw matching results */
- private def splitOne(n: BigInt) = {
- new MatchData(n::buildSeq(Nil, n, fields.size - 1, size), groupNames)
- }
-
- /** Performs the matching.
- *
- * @param the array to be matched
- * @return the contents of each field
- */
- def parse(a: Array[Byte]): MatchData[BigInt] = splitOne(BigInt(a))
-
- /** Matches and consumes the same input iteratively */
- private def split(input: Array[Byte]): List[MatchData[BigInt]] = {
- def split0(res: List[BigInt], in: Array[Byte]): List[BigInt] = {
- val bSize = size / 8
- if (in.length <= bSize)
- BigInt(in) :: res
- else {
- val x = in.slice(0, bSize)
- val xs = in.slice(bSize, in.length)
- split0(BigInt(x) :: res, xs)
- }
- }
- split0(Nil, input).reverse map {n => splitOne(n)}
- }
-}
diff --git a/src/library/scala/util/matching/MatchData.scala b/src/library/scala/util/matching/MatchData.scala
deleted file mode 100644
index a67da76694..0000000000
--- a/src/library/scala/util/matching/MatchData.scala
+++ /dev/null
@@ -1,64 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2008, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.util.matching
-
-/** This class provides methods to access
- * the contents of capture groups.
- *
- * @author Thibaud Hottelier
- * @version 1.1, 29/01/2008
- */
-class MatchData[A](groups: List[A], groupNames: Map[String, Int]) {
- def this(groups: List[A]) = this(groups, null)
-
- /** Returns the i-th group
- * @param id The group number
- * @return The i-th group
- */
- def apply(id: Int): A = groups(id)
-
- /** Returns the whole match
- */
- def apply(): A = groups(0)
-
- /** Returns the requested group
- *
- * @param id The group name
- * @return The requested group
- * @throws <code>NoSuchElementException</code> if the requested
- * group name is not defined
- */
- def apply(id: String): A =
- if (groupNames == null)
- throw new NoSuchElementException("no group names defined")
- else {
- val index = groupNames.get(id)
- if (index == None)
- throw new NoSuchElementException("group name "+id+" not defined")
- else
- apply(index.get)
- }
-
- /** Returns the list of groups
- *
- * @return The groups
- */
- def getGroups: List[A] = groups
-
- /** Returns the list of group names
- *
- * @return The names
- */
- def getNames = groupNames
-
- override def toString(): String = groups(0).toString
-}
diff --git a/src/library/scala/util/matching/MatchableBigInt.scala b/src/library/scala/util/matching/MatchableBigInt.scala
deleted file mode 100644
index 23929ee47d..0000000000
--- a/src/library/scala/util/matching/MatchableBigInt.scala
+++ /dev/null
@@ -1,29 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2008, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.util.matching
-
-/** This class provides methods to do matching with
- * BitFields.
- *
- * @author Thibaud Hottelier
- * @version 1.0, 12/12/2007
- */
-private[matching] class MatchableBigInt(a: Array[Byte]) {
-
- /** Returns the first match of this array of Byte with the
- * provided BitField.
- *
- * @param f the BitField
- * @return the first match
- */
- def =~ (f: FixedBitField): Option[MatchData[BigInt]] = Some(f.parse(a))
-}
diff --git a/src/library/scala/util/matching/Regex.scala b/src/library/scala/util/matching/Regex.scala
index 32fc300bf1..1250b775ee 100644
--- a/src/library/scala/util/matching/Regex.scala
+++ b/src/library/scala/util/matching/Regex.scala
@@ -50,12 +50,12 @@ class Regex(regex: String, groupNames: String*) {
/** Return all matches of this regexp in given character sequence as an iterator
*/
- def findAllIn(source: CharSequence) = new Regex.MatchIterator(source, this, groupNames)
+ def findAllIn(source: java.lang.CharSequence) = new Regex.MatchIterator(source, this, groupNames)
/** Return optionally first matching string of this regexp in given character sequence,
* None if it does not exist.
*/
- def findFirstIn(source: CharSequence): Option[String] = {
+ def findFirstIn(source: java.lang.CharSequence): Option[String] = {
val m = pattern.matcher(source)
if (m.find) Some(m.group) else None
}
@@ -63,7 +63,7 @@ class Regex(regex: String, groupNames: String*) {
/** Return optionally first match of this regexp in given character sequence,
* None if it does not exist.
*/
- def findFirstMatchIn(source: CharSequence): Option[Match] = {
+ def findFirstMatchIn(source: java.lang.CharSequence): Option[Match] = {
val m = pattern.matcher(source)
if (m.find) Some(new Match(source, m, groupNames)) else None
}
@@ -72,7 +72,7 @@ class Regex(regex: String, groupNames: String*) {
* given character sequence, or None if regexp matches no prefix
* of the character sequence.
*/
- def findPrefixOf(source: CharSequence): Option[String] = {
+ def findPrefixOf(source: java.lang.CharSequence): Option[String] = {
val m = pattern.matcher(source)
if (m.lookingAt) Some(m.group) else None
}
@@ -81,7 +81,7 @@ class Regex(regex: String, groupNames: String*) {
* given character sequence, or None if regexp matches no prefix
* of the character sequence.
*/
- def findPrefixMatchOf(source: CharSequence): Option[Match] = {
+ def findPrefixMatchOf(source: java.lang.CharSequence): Option[Match] = {
val m = pattern.matcher(source)
if (m.lookingAt) Some(new Match(source, m, groupNames)) else None
}
@@ -92,7 +92,7 @@ class Regex(regex: String, groupNames: String*) {
* @param replacement The string that will replace each match
* @return The resulting string
*/
- def replaceAllIn(target: CharSequence, replacement: String): String = {
+ def replaceAllIn(target: java.lang.CharSequence, replacement: String): String = {
val m = pattern.matcher(target)
m.replaceAll(replacement)
}
@@ -103,7 +103,7 @@ class Regex(regex: String, groupNames: String*) {
* @param replacement The string that will replace the match
* @return The resulting string
*/
- def replaceFirstIn(target: CharSequence, replacement: String): String = {
+ def replaceFirstIn(target: java.lang.CharSequence, replacement: String): String = {
val m = pattern.matcher(target)
m.replaceFirst(replacement)
}
@@ -127,7 +127,7 @@ object Regex {
trait MatchData {
/** The source from where the match originated */
- val source: CharSequence
+ val source: java.lang.CharSequence
/** The names of the groups, or some empty sequence if one defined */
val groupNames: Seq[String]
@@ -157,16 +157,16 @@ object Regex {
def subgroups: List[String] = (1 to groupCount).toList map group
/** The char sequence before first character of match */
- def before: CharSequence = source.subSequence(0, start)
+ def before: java.lang.CharSequence = source.subSequence(0, start)
/** The char sequence before first character of match in group <code>i</code> */
- def before(i: Int): CharSequence = source.subSequence(0, start(i))
+ def before(i: Int): java.lang.CharSequence = source.subSequence(0, start(i))
/** Returns char sequence after last character of match */
- def after: CharSequence = source.subSequence(end)
+ def after: java.lang.CharSequence = source.subSequence(end, source.length)
/** The char sequence after last character of match in group <code>i</code> */
- def after(i: Int): CharSequence = source.subSequence(end(i))
+ def after(i: Int): java.lang.CharSequence = source.subSequence(end(i), source.length)
private lazy val nameToIndex: Map[String, Int] = Map() ++ ("" :: groupNames.toList).zipWithIndex
@@ -189,7 +189,7 @@ object Regex {
/** A case class for a succesful match.
*/
- class Match(val source: CharSequence,
+ class Match(val source: java.lang.CharSequence,
matcher: Matcher,
val groupNames: Seq[String]) extends MatchData {
@@ -226,7 +226,7 @@ object Regex {
/** A class to step through a sequence of regex matches
*/
- class MatchIterator(val source: CharSequence, val regex: Regex, val groupNames: Seq[String])
+ class MatchIterator(val source: java.lang.CharSequence, val regex: Regex, val groupNames: Seq[String])
extends Iterator[String] with MatchData { self =>
private val matcher = regex.pattern.matcher(source)
diff --git a/src/library/scala/util/matching/TaintedInt.scala b/src/library/scala/util/matching/TaintedInt.scala
deleted file mode 100644
index 0b4b8aa047..0000000000
--- a/src/library/scala/util/matching/TaintedInt.scala
+++ /dev/null
@@ -1,58 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2008, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.util.matching
-
-/** This is a wrapper around integer. Used only by BitFields,
- * it makes it possible to differentiate fixed-size fields from
- * variable-size ones.
- *
- * @author Thibaud Hottelier
- * @version 1.0, 15/12/2007
- *
- * @param x the wrapped integer
- */
-private[matching] class TaintedInt(x: Int) {
-
- /** Converts to Int
- *
- * @return The wrapped integer
- */
- def toInt = x
-
- /** Adds two TaintedInts
- *
- * @param y The second operand
- * @return The sum
- */
- def + (y: TaintedInt) = new TaintedInt(x + y.toInt)
-
- /** Subtracts two TaintedInts
- *
- * @param y The second operand
- * @return The difference
- */
- def - (y: TaintedInt) = new TaintedInt(x - y.toInt)
-
- /** Multiplies two TaintedInts
- *
- * @param y The second operand
- * @return The product
- */
- def * (y: TaintedInt) = new TaintedInt(x * y.toInt)
-
- /** Divides two TaintedInts
- *
- * @param y The second operand
- * @return The quotient
- */
- def / (y: TaintedInt) = new TaintedInt(x / y.toInt)
-}
diff --git a/src/library/scala/util/parsing/combinator/lexical/Scanners.scala b/src/library/scala/util/parsing/combinator/lexical/Scanners.scala
index dc841dba99..ea796dbe72 100644
--- a/src/library/scala/util/parsing/combinator/lexical/Scanners.scala
+++ b/src/library/scala/util/parsing/combinator/lexical/Scanners.scala
@@ -66,7 +66,7 @@ trait Scanners extends Parsers {
}
private def skip(in: Reader[Char]) = if (in.atEnd) in else in.rest
- override def source: CharSequence = in.source
+ override def source: java.lang.CharSequence = in.source
override def offset: Int = in.offset
def first = tok
def rest = new Scanner(rest2)
diff --git a/src/library/scala/util/parsing/combinatorold/lexical/Scanners.scala b/src/library/scala/util/parsing/combinatorold/lexical/Scanners.scala
index 15e9542bb5..a7292d1edb 100644
--- a/src/library/scala/util/parsing/combinatorold/lexical/Scanners.scala
+++ b/src/library/scala/util/parsing/combinatorold/lexical/Scanners.scala
@@ -66,7 +66,7 @@ trait Scanners extends Parsers {
}
private def skip(in: Reader[Char]) = if (in.atEnd) in else in.rest
- override def source: CharSequence = in.source
+ override def source: java.lang.CharSequence = in.source
override def offset: Int = in.offset
def first = tok
def rest = new Scanner(rest2)
diff --git a/src/library/scala/util/parsing/input/OffsetPosition.scala b/src/library/scala/util/parsing/input/OffsetPosition.scala
index 6bbc6fdcac..a5ceb01ebe 100644
--- a/src/library/scala/util/parsing/input/OffsetPosition.scala
+++ b/src/library/scala/util/parsing/input/OffsetPosition.scala
@@ -18,7 +18,7 @@ import collection.mutable.ArrayBuffer
*
* @author Martin Odersky
*/
-case class OffsetPosition(source: CharSequence, offset: Int) extends Position {
+case class OffsetPosition(source: java.lang.CharSequence, offset: Int) extends Position {
/** An index that contains all line starts, including first line, and eof */
private lazy val index: Array[Int] = {