summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-06-07 14:40:56 +0000
committerPaul Phillips <paulp@improving.org>2009-06-07 14:40:56 +0000
commit8e8beb0cdc6c929341c94d742f8fc0e53352f0bb (patch)
tree40cc7356e8a0667e7827605e13785ef2175bace2
parentbd7bd8fb2719fd00401d8abaf07afa8f002c90a2 (diff)
downloadscala-8e8beb0cdc6c929341c94d742f8fc0e53352f0bb.tar.gz
scala-8e8beb0cdc6c929341c94d742f8fc0e53352f0bb.tar.bz2
scala-8e8beb0cdc6c929341c94d742f8fc0e53352f0bb.zip
Fix for #1993.
-rw-r--r--src/library/scala/util/parsing/combinator/lexical/StdLexical.scala26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/library/scala/util/parsing/combinator/lexical/StdLexical.scala b/src/library/scala/util/parsing/combinator/lexical/StdLexical.scala
index 2489c623e9..9cacf37ca2 100644
--- a/src/library/scala/util/parsing/combinator/lexical/StdLexical.scala
+++ b/src/library/scala/util/parsing/combinator/lexical/StdLexical.scala
@@ -71,23 +71,19 @@ class StdLexical extends Lexical with StdTokens {
protected def processIdent(name: String) =
if (reserved contains name) Keyword(name) else Identifier(name)
- private var _delim: Parser[Token] = null
- protected def delim: Parser[Token] = {
- if (_delim eq null) { // construct parser for delimiters by |'ing together the parsers for the individual delimiters,
- // starting with the longest one (hence the sort + reverse) -- otherwise a delimiter D will never be matched if
- // there is another delimiter that is a prefix of D
- def parseDelim(s: String): Parser[Token] = accept(s.toList) ^^ { x => Keyword(s) }
-
- val d = new Array[String](delimiters.size)
- delimiters.copyToArray(d,0)
- scala.util.Sorting.quickSort(d)
- _delim = d.toList.reverse.map(parseDelim).reduceRight[Parser[Token]](_ | _) // no offence :-)
- }
-
- _delim
+ private lazy val _delim: Parser[Token] = {
+ // construct parser for delimiters by |'ing together the parsers for the individual delimiters,
+ // starting with the longest one -- otherwise a delimiter D will never be matched if there is
+ // another delimiter that is a prefix of D
+ def parseDelim(s: String): Parser[Token] = accept(s.toList) ^^ { x => Keyword(s) }
+
+ val d = new Array[String](delimiters.size)
+ delimiters.copyToArray(d, 0)
+ scala.util.Sorting.quickSort(d)
+ (d.toList map parseDelim).foldRight(failure("no matching delimiter"): Parser[Token])((x, y) => y | x)
}
+ protected def delim: Parser[Token] = _delim
private def lift[T](f: String => T)(xs: List[Char]): T = f(xs.mkString("", "", ""))
-
private def lift2[T](f: String => T)(p: ~[Char, List[Char]]): T = lift(f)(p._1 :: p._2)
}