summaryrefslogtreecommitdiff
path: root/src/jvm14-library
diff options
context:
space:
mode:
authorAntonio Cunei <antonio.cunei@epfl.ch>2009-05-15 13:00:12 +0000
committerAntonio Cunei <antonio.cunei@epfl.ch>2009-05-15 13:00:12 +0000
commit78265a6b80e7f5ce8bf187e16eae8b3500da055d (patch)
tree38d6ce3ee5b1bfed18a7792549f1d1af423598b1 /src/jvm14-library
parent2670b004c77ec6d02ba8909103bce79c2df6065f (diff)
downloadscala-78265a6b80e7f5ce8bf187e16eae8b3500da055d.tar.gz
scala-78265a6b80e7f5ce8bf187e16eae8b3500da055d.tar.bz2
scala-78265a6b80e7f5ce8bf187e16eae8b3500da055d.zip
Removed further 1.4 vestiges.
Diffstat (limited to 'src/jvm14-library')
-rw-r--r--src/jvm14-library/scala/BigDecimal.scala269
-rw-r--r--src/jvm14-library/scala/runtime/RichString.scala266
-rw-r--r--src/jvm14-library/scala/util/parsing/json/JSON.scala95
-rw-r--r--src/jvm14-library/scala/util/parsing/json/Parser.scala50
4 files changed, 0 insertions, 680 deletions
diff --git a/src/jvm14-library/scala/BigDecimal.scala b/src/jvm14-library/scala/BigDecimal.scala
deleted file mode 100644
index 0c9fd0f5fd..0000000000
--- a/src/jvm14-library/scala/BigDecimal.scala
+++ /dev/null
@@ -1,269 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: BigDecimal.scala 15937 2008-08-26 13:48:19Z michelou $
-
-package scala
-
-import java.math.{BigDecimal => BigDec}
-
-/**
- * @author Stephane Micheloud
- * @version 1.0
- */
-object BigDecimal {
-
- @serializable
- object RoundingMode extends Enumeration {
- type RoundingMode = Value
- val ROUND_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR, ROUND_HALF_UP,
- ROUND_HALF_DOWN, ROUND_HALF_EVEN, ROUND_UNNECESSARY = Value
- }
-
- private val minCached = -512
- private val maxCached = 512
- private lazy val cache = new Array[BigDecimal](maxCached - minCached + 1)
-
- /** Constructs a <code>BigDecimal</code> whose value is equal to that of the
- * specified <code>Integer</code> value.
- *
- * @param i the specified integer value
- * @return the constructed <code>BigDecimal</code>
- */
- def apply(i: Int): BigDecimal =
- if (minCached <= i && i <= maxCached) {
- val offset = i - minCached
- var n = cache(offset)
- if (n eq null) { n = new BigDecimal(BigDec.valueOf(i)); cache(offset) = n }
- n
- } else new BigDecimal(BigDec.valueOf(i))
-
- /** Constructs a <code>BigDecimal</code> whose value is equal to that of the
- * specified long value.
- *
- * @param l the specified long value
- * @return the constructed <code>BigDecimal</code>
- */
- def apply(l: Long): BigDecimal =
- if (minCached <= l && l <= maxCached) apply(l.toInt)
- else new BigDecimal(BigDec.valueOf(l))
-
- /** Constructs a <code>BigDecimal</code> whose value is equal to that of the
- * specified double value.
- *
- * @param d the specified <code>Double</code> value
- * @return the constructed <code>BigDecimal</code>
- */
- def apply(d: Double): BigDecimal =
- new BigDecimal(new BigDec(d))
-
- /** Translates a character array representation of a <code>BigDecimal</code>
- * into a <code>BigDecimal</code>.
- */
- def apply(x: Array[Char]): BigDecimal =
- new BigDecimal(new BigDec(x.toString))
-
- /** Translates the decimal String representation of a <code>BigDecimal</code>
- * into a <code>BigDecimal</code>.
- */
- def apply(x: String): BigDecimal =
- new BigDecimal(new BigDec(x))
-
- /** Constructs a <code>BigDecimal</code> whose value is equal to that of the
- * specified <code>BigInt</code> value.
- *
- * @param x the specified <code>BigInt</code> value
- * @return the constructed <code>BigDecimal</code>
- */
- def apply(x: BigInt): BigDecimal =
- new BigDecimal(new BigDec(x.bigInteger))
-
- /** Implicit conversion from <code>Int</code> to <code>BigDecimal</code>. */
- implicit def int2bigDecimal(i: Int): BigDecimal = apply(i)
-
- /** Implicit conversion from <code>Long</code> to <code>BigDecimal</code>. */
- implicit def long2bigDecimal(l: Long): BigDecimal = apply(l)
-
- /** Implicit conversion from <code>Double</code> to <code>BigDecimal</code>. */
- implicit def double2bigDecimal(d: Double): BigDecimal = apply(d)
-
- /** Implicit conversion from BigDecimal to <code>Ordered</code>. */
- implicit def bigDecimal2ordered(x: BigDecimal): Ordered[BigDecimal] =
- new Ordered[BigDecimal] with Proxy {
- def self: Any = x
- def compare(y: BigDecimal): Int = x.bigDecimal.compareTo(y.bigDecimal)
- }
-}
-
-/**
- * @author Stephane Micheloud
- * @version 1.0
- */
-@serializable
-class BigDecimal(val bigDecimal: BigDec) extends java.lang.Number {
- import BigDecimal.RoundingMode._
-
- /** Returns the hash code for this BigDecimal. */
- override def hashCode(): Int = this.bigDecimal.hashCode()
-
- /** Compares this BigDecimal with the specified value for equality.
- */
- override def equals(that: Any): Boolean = that match {
- case that: BigDecimal => this equals that
- case that: java.lang.Double => this.bigDecimal.doubleValue == that.doubleValue
- case that: java.lang.Float => this.bigDecimal.floatValue == that.floatValue
- case that: java.lang.Number => this equals BigDecimal(that.longValue)
- case that: java.lang.Character => this equals BigDecimal(that.charValue.asInstanceOf[Int])
- case _ => false
- }
-
- /** Compares this BigDecimal with the specified BigDecimal for equality.
- */
- def equals (that: BigDecimal): Boolean =
- this.bigDecimal.compareTo(that.bigDecimal) == 0
-
- /** Compares this BigDecimal with the specified BigDecimal
- */
- def compare (that: BigDecimal): Int = this.bigDecimal.compareTo(that.bigDecimal)
-
- /** Less-than-or-equals comparison of BigDecimals
- */
- def <= (that: BigDecimal): Boolean = this.bigDecimal.compareTo(that.bigDecimal) <= 0
-
- /** Greater-than-or-equals comparison of BigDecimals
- */
- def >= (that: BigDecimal): Boolean = this.bigDecimal.compareTo(that.bigDecimal) >= 0
-
- /** Less-than of BigDecimals
- */
- def < (that: BigDecimal): Boolean = this.bigDecimal.compareTo(that.bigDecimal) < 0
-
- /** Greater-than comparison of BigDecimals
- */
- def > (that: BigDecimal): Boolean = this.bigDecimal.compareTo(that.bigDecimal) > 0
-
- /** Addition of BigDecimals
- */
- def + (that: BigDecimal): BigDecimal =
- new BigDecimal(this.bigDecimal.add(that.bigDecimal))
-
- /** Subtraction of BigDecimals
- */
- def - (that: BigDecimal): BigDecimal =
- new BigDecimal(this.bigDecimal.subtract(that.bigDecimal))
-
- /** Multiplication of BigDecimals
- */
- def * (that: BigDecimal): BigDecimal =
- new BigDecimal(this.bigDecimal.multiply(that.bigDecimal))
-
- /** Division of BigDecimals. Default rounding mode is <code>ROUND_HALF_UP</code>
- * (same value as <code>MathContext.DEFAULT_ROUNDINGMODE</code> (private)
- * in Java 1.5 or newer).
- */
- def / (that: BigDecimal): BigDecimal =
- new BigDecimal(this.bigDecimal.divide(that.bigDecimal, BigDec.ROUND_HALF_UP))
-
- /** Returns the minimum of this and that
- */
- def min (that: BigDecimal): BigDecimal =
- new BigDecimal(this.bigDecimal.min(that.bigDecimal))
-
- /** Returns the maximum of this and that
- */
- def max (that: BigDecimal): BigDecimal =
- new BigDecimal(this.bigDecimal.max(that.bigDecimal))
-
- /** Returns a BigDecimal whose value is the negation of this BigDecimal
- */
- def unary_- : BigDecimal = new BigDecimal(this.bigDecimal.negate())
-
- /** Returns the absolute value of this BigDecimal
- */
- def abs: BigDecimal = new BigDecimal(this.bigDecimal.abs())
-
- /** Returns the sign of this BigDecimal, i.e.
- * -1 if it is less than 0,
- * +1 if it is greater than 0
- * 0 if it is equal to 0
- */
- def signum: Int = this.bigDecimal.signum()
-
- /** Returns the scale of this <code>BigDecimal</code>.
- */
- def scale: Int = this.bigDecimal.scale()
-
- /** Returns a <code>BigDecimal</code> whose scale is the specified value, and whose value is
- * numerically equal to this BigDecimal's.
- */
- def setScale(scale: Int): BigDecimal =
- new BigDecimal(this.bigDecimal setScale scale)
-
- def setScale(scale: Int, mode: RoundingMode): BigDecimal =
- new BigDecimal(this.bigDecimal.setScale(scale, mode.id))
-
- /** Converts this BigDecimal to a <tt>byte</tt>.
- * If the BigDecimal is too big to fit in a byte, only the low-order 8 bits are returned.
- * Note that this conversion can lose information about the overall magnitude of the
- * BigDecimal value as well as return a result with the opposite sign.
- */
- override def byteValue = intValue.toByte
-
- /** Converts this BigDecimal to a <tt>short</tt>.
- * If the BigDecimal is too big to fit in a byte, only the low-order 16 bits are returned.
- * Note that this conversion can lose information about the overall magnitude of the
- * BigDecimal value as well as return a result with the opposite sign.
- */
- override def shortValue = intValue.toShort
-
- /** Converts this BigDecimal to a <tt>char</tt>.
- * If the BigDecimal is too big to fit in a char, only the low-order 16 bits are returned.
- * Note that this conversion can lose information about the overall magnitude of the
- * BigDecimal value and that it always returns a positive result.
- */
- def charValue = intValue.toChar
-
- /** Converts this BigDecimal to an <tt>int</tt>.
- * If the BigDecimal is too big to fit in a char, only the low-order 32 bits
- * are returned. Note that this conversion can lose information about the
- * overall magnitude of the BigDecimal value as well as return a result with
- * the opposite sign.
- */
- def intValue = this.bigDecimal.intValue
-
- /** Converts this BigDecimal to a <tt>Long</tt>.
- * If the BigDecimal is too big to fit in a char, only the low-order 64 bits
- * are returned. Note that this conversion can lose information about the
- * overall magnitude of the BigDecimal value as well as return a result with
- * the opposite sign.
- */
- def longValue = this.bigDecimal.longValue
-
- /** Converts this BigDecimal to a <tt>float</tt>.
- * if this BigDecimal has too great a magnitude to represent as a float,
- * it will be converted to <code>Float.NEGATIVE_INFINITY</code> or
- * <code>Float.POSITIVE_INFINITY</code> as appropriate.
- */
- def floatValue = this.bigDecimal.floatValue
-
- /** Converts this BigDecimal to a <tt>Double</tt>.
- * if this BigDecimal has too great a magnitude to represent as a float,
- * it will be converted to <code>Float.NEGATIVE_INFINITY</code> or
- * <code>Float.POSITIVE_INFINITY</code> as appropriate.
- */
- def doubleValue = this.bigDecimal.doubleValue
-
- /** Converts this <code>BigDecimal</code> to a BigInteger.
- */
- def toBigInt(): BigInt = new BigInt(this.bigDecimal.toBigInteger())
-
- /** Returns the decimal String representation of this BigDecimal.
- */
- override def toString(): String = this.bigDecimal.toString()
-
-}
diff --git a/src/jvm14-library/scala/runtime/RichString.scala b/src/jvm14-library/scala/runtime/RichString.scala
deleted file mode 100644
index ada259931d..0000000000
--- a/src/jvm14-library/scala/runtime/RichString.scala
+++ /dev/null
@@ -1,266 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.runtime
-
-import Predef._
-import scala.util.matching.Regex
-
-final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char] with Ordered[String] {
- import RichString._
- override def apply(n: Int) = self charAt n
- override def length = self.length
- override def toString = self
- override def mkString = self
-
- override def slice(from: Int, until: Int): RichString = {
- val len = self.length
- new RichString(
- if (from >= until || from >= len)
- ""
- else {
- val from0 = if (from < 0) 0 else from
- val until0 = if (until > len) len else until
- self.substring(from0, until0)
- }
- )
- }
-
- //override def ++ [B >: A](that: Iterable[B]): Seq[B] = {
- override def ++[B >: Char](that: Iterable[B]): RandomAccessSeq[B] = that match {
- case that: RichString => new RichString(self + that.self)
- case that => super.++(that)
- }
-
- override def take(until: Int): RichString = slice(0, until)
-
- override def drop(from: Int): RichString = slice(from, self.length)
-
- override def startsWith[B](that: Seq[B]) = that match {
- case that: RichString => self startsWith that.self
- case that => super.startsWith(that)
- }
-
- override def endsWith[B](that: Seq[B]) = that match {
- case that: RichString => self endsWith that.self
- case that => super.endsWith(that)
- }
-
- override def indexOf[B](that: Seq[B]) = that match {
- case that: RichString => self indexOf that.self
- case that => super.indexOf(that)
- }
-
- override def containsSlice[B](that: Seq[B]) = that match {
- case that: RichString => self contains that.self
- case that => super.containsSlice(that)
- }
-
- def contains(arg: String) : Boolean = {
- self.matches(""".*\Q"""+arg+"""\E.*""")
- }
-
- override def reverse: RichString = {
- val buf = new StringBuilder
- var i = self.length - 1
- while (i >= 0) {
- buf append (self charAt i)
- i -= 1
- }
- new RichString(buf.toString)
- }
-
- /** return n times the current string
- */
- def * (n: Int): String = {
- val buf = new StringBuilder
- for (i <- 0 until n) buf append self
- buf.toString
- }
-
- override def compare(other: String) = self compareTo other
-
- private def isLineBreak(c: Char) = c == LF || c == FF
-
- /** <p>
- * Strip trailing line end character from this string if it has one.
- * A line end character is one of
- * </p>
- * <ul style="list-style-type: none;">
- * <li>LF - line feed (0x0A hex)</li>
- * <li>FF - form feed (0x0C hex)</li>
- * </ul>
- * <p>
- * If a line feed character LF is preceded by a carriage return CR
- * (0x0D hex), the CR character is also stripped (Windows convention).
- * </p>
- */
- def stripLineEnd: String = {
- val len = self.length
- if (len == 0) self
- else {
- val last = apply(len - 1)
- if (isLineBreak(last))
- self.substring(0, if (last == LF && len >= 2 && apply(len - 2) == CR) len - 2 else len - 1)
- else
- self
- }
- }
-
- /** <p>
- * Return all lines in this string in an iterator, including trailing
- * line end characters.
- * </p>
- * <p>
- * The number of strings returned is one greater than the number of line
- * end characters in this string. For an empty string, a single empty
- * line is returned. A line end character is one of
- * </p>
- * <ul style="list-style-type: none;">
- * <li>LF - line feed (0x0A hex)</li>
- * <li>FF - form feed (0x0C hex)</li>
- * </ul>
- */
- def linesWithSeparators = new Iterator[String] {
- val len = self.length
- var index = 0
- def hasNext: Boolean = index < len
- def next(): String = {
- if (index >= len) throw new NoSuchElementException("next on empty iterator")
- val start = index
- while (index < len && !isLineBreak(apply(index))) index += 1
- index += 1
- self.substring(start, index min len)
- }
- }
-
- /** Return all lines in this string in an iterator, excluding trailing line
- * end characters, i.e. apply <code>.stripLineEnd</code> to all lines
- * returned by <code>linesWithSeparators</code>.
- */
- def lines: Iterator[String] =
- linesWithSeparators map (line => new RichString(line).stripLineEnd)
-
- /** Returns this string with first character converted to upper case */
- def capitalize: String =
- if (self == null) null
- else if (self.length == 0) ""
- else {
- val chars = self.toCharArray
- chars(0) = chars(0).toUpperCase
- new String(chars)
- }
-
- /** <p>
- * For every line in this string:
- * </p>
- * <blockquote>
- * Strip a leading prefix consisting of blanks or control characters
- * followed by <code>marginChar</code> from the line.
- * </blockquote>
- */
- def stripMargin(marginChar: Char): String = {
- val buf = new StringBuilder
- for (line <- linesWithSeparators) {
- val len = line.length
- var index = 0
- while (index < len && line.charAt(index) <= ' ') index += 1
- buf append
- (if (index < len && line.charAt(index) == marginChar) line.substring(index + 1) else line)
- }
- buf.toString
- }
-
- /** <p>
- * For every line in this string:
- * </p>
- * <blockquote>
- * Strip a leading prefix consisting of blanks or control characters
- * followed by <code>|</code> from the line.
- * </blockquote>
- */
- def stripMargin: String = stripMargin('|')
-
- // NB. "\\Q" + '\\' + "\\E" works on Java 1.5 and newer, but not on Java 1.4
- private def escape(ch: Char): String = ch match {
- case '\\' => "\\\\"
- case _ => "\\Q"+ch+"\\E"
- }
-
- @throws(classOf[java.util.regex.PatternSyntaxException])
- def split(separator: Char): Array[String] = self.split(escape(separator))
-
- @throws(classOf[java.util.regex.PatternSyntaxException])
- def split(separators: Array[Char]): Array[String] = {
- val re = separators.foldLeft("[")(_+escape(_)) + "]"
- self.split(re)
- }
-
- /** You can follow a string with `.r', turning
- * it into a Regex. E.g.
- *
- * """A\w*""".r is the regular expression for identifiers starting with `A'.
- */
- def r: Regex = new Regex(self)
-
- def toBoolean: Boolean = parseBoolean(self)
- def toByte: Byte = java.lang.Byte.parseByte(self)
- def toShort: Short = java.lang.Short.parseShort(self)
- def toInt: Int = java.lang.Integer.parseInt(self)
- def toLong: Long = java.lang.Long.parseLong(self)
- def toFloat: Float = java.lang.Float.parseFloat(self)
- def toDouble: Double = java.lang.Double.parseDouble(self)
-
- def toArray: Array[Char] = {
- val result = new Array[Char](length)
- self.getChars(0, length, result, 0)
- result
- }
-
-
- /** <p>
- * Uses the underlying string as a pattern (in a fashion similar to
- * printf in C), and uses the supplied arguments to fill in the
- * holes. Only works on Java 1.5 or higher!
- * </p>
- * <p>
- * The interpretation of the formatting patterns is described in
- * <a href="" target="contentFrame" class="java/util/Formatter">
- * <code>java.util.Formatter</code></a>.
- * </p>
- *
- * @param args the arguments used to instantiating the pattern.
- * @throws java.lang.IllegalArgumentException
- */
- def format(args : Any*) : String = {
- val m = classOf[String].getDeclaredMethod("format", classOf[String], classOf[Array[Object]])
- m.invoke(null, self,
- args.asInstanceOf[scala.runtime.BoxedObjectArray].
- unbox(args.getClass).asInstanceOf[Array[Object]]).asInstanceOf[String]
- }
-}
-
-object RichString {
- // just statics for rich string.
- private final val LF: Char = 0x0A
- private final val FF: Char = 0x0C
- private final val CR: Char = 0x0D
- private final val SU: Char = 0x1A
-
- private def parseBoolean(s: String): Boolean =
- if (s != null) s.toLowerCase match {
- case "true" => true
- case "false" => false
- case _ => throw new NumberFormatException("For input string: \""+s+"\"")
- }
- else
- throw new NumberFormatException("For input string: \"null\"")
-}
diff --git a/src/jvm14-library/scala/util/parsing/json/JSON.scala b/src/jvm14-library/scala/util/parsing/json/JSON.scala
deleted file mode 100644
index b03149cde1..0000000000
--- a/src/jvm14-library/scala/util/parsing/json/JSON.scala
+++ /dev/null
@@ -1,95 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: JSON.scala 15746 2008-08-11 17:33:54Z dchenbecker $
-
-
-package scala.util.parsing.json
-
-/**
- * This object provides a simple interface to the JSON parser class. The default conversion
- * for numerics is into a double. If you wish to override this behavior at the global level,
- * you can set the globalNumberParser property to your own (String => Any) function. If you only
- * want to override at the per-thread level then you can set the perThreadNumberParser property to your
- * function. For example:
- *
- * <pre>
- * val myConversionFunc = {input : String => BigDecimal(input)}
- *
- * // Global override
- * JSON.globalNumberParser = myConversionFunc
- *
- * // Per-thread override
- * JSON.perThreadNumberParser = myConversionFunc
- * </pre>
- *
- * @author Derek Chen-Becker <"java"+@+"chen-becker"+"."+"org">
- */
-object JSON extends Parser {
-
- /**
- * Parse the given JSON string and return a list of elements. If the
- * string is a JSON object it will be a list of pairs. If it's a JSON
- * array it will be be a list of individual elements.
- *
- * @param input the given JSON string.
- * @return an optional list of of elements.
- */
- def parse(input: String): Option[List[Any]] =
- phrase(root)(new lexical.Scanner(input)) match {
- case Success(result, _) => Some(result)
- case _ => None
- }
-
- /**
- * Parse the given JSON string and return either a <code>List[Any]</code>
- * if the JSON string specifies an <code>Array</code>, or a
- * <code>Map[String,Any]</code> if the JSON string specifies an object.
- *
- * @param input the given JSON string.
- * @return an optional list or map.
- */
- def parseFull(input: String): Option[Any] =
- parse(input) match {
- case Some(data) => Some(resolveType(data))
- case None => None
- }
-
- /**
- * A utility method to resolve a parsed JSON list into objects or
- * arrays. See the parse method for details.
- */
- def resolveType(input: List[_]): Any = {
- var objMap = Map[String, Any]()
-
- if (input.forall {
- case (key: String, value: List[_]) =>
- objMap += (key -> resolveType(value))
- true
- case (key : String, value : Any) =>
- objMap += (key -> value)
- true
- case _ => false
- }) objMap
- else
- input
- }
-
- /**
- * The global (VM) default function for converting a string to a numeric value.
- */
- def globalNumberParser_=(f: NumericParser) { defaultNumberParser = f }
- def globalNumberParser : NumericParser = defaultNumberParser
-
- /**
- * Defines the function used to convert a numeric string literal into a numeric format on a per-thread
- * basis. Use globalNumberParser for a global override
- */
- def perThreadNumberParser_=(f : NumericParser) { numberParser.set(f) }
- def perThreadNumberParser : NumericParser = numberParser.get().asInstanceOf[NumericParser] // cast for jvm 1.4
-}
diff --git a/src/jvm14-library/scala/util/parsing/json/Parser.scala b/src/jvm14-library/scala/util/parsing/json/Parser.scala
deleted file mode 100644
index 1f024d16ea..0000000000
--- a/src/jvm14-library/scala/util/parsing/json/Parser.scala
+++ /dev/null
@@ -1,50 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: Parser.scala 15746 2008-08-11 17:33:54Z dchenbecker $
-
-
-package scala.util.parsing.json
-
-import scala.util.parsing.combinator._
-import scala.util.parsing.combinator.syntactical._
-import scala.util.parsing.combinator.lexical._
-
-/**
- * @author Derek Chen-Becker <"java"+@+"chen-becker"+"."+"org">
- */
-class Parser extends StdTokenParsers with ImplicitConversions {
- // Fill in abstract defs
- type Tokens = Lexer
- val lexical = new Tokens
-
- // Configure lexical parsing
- lexical.reserved ++= List("true", "false", "null")
- lexical.delimiters ++= List("{", "}", "[", "]", ":", ",")
-
- /** Type signature for functions that can parse numeric literals */
- type NumericParser = String => Any
-
- // Global default number parsing function
- protected var defaultNumberParser : NumericParser = {_.toDouble}
-
- // Per-thread default number parsing function
- protected val numberParser = new ThreadLocal[NumericParser]() {
- override def initialValue() = defaultNumberParser
- }
-
- // Define the grammar
- def root = jsonObj | jsonArray
- def jsonObj = "{" ~> repsep(objEntry, ",") <~ "}"
- def jsonArray = "[" ~> repsep(value, ",") <~ "]"
- def objEntry = stringVal ~ (":" ~> value) ^^ { case x ~ y => (x, y) }
- def value: Parser[Any] = (jsonObj | jsonArray | number | "true" ^^^ true | "false" ^^^ false | "null" ^^^ null | stringVal)
- def stringVal = accept("string", { case lexical.StringLit(n) => n} )
- def number = accept("number", { case lexical.NumericLit(n) => numberParser.get.asInstanceOf[NumericParser].apply(n)} ) // cast for jvm 1.4
-}
-