summaryrefslogtreecommitdiff
path: root/test/files/presentation/akka/src/akka/config/ConfigParser.scala
diff options
context:
space:
mode:
authorMicro Dotta <mirco.dotta@gmail.com>2011-08-17 13:32:25 +0000
committerMicro Dotta <mirco.dotta@gmail.com>2011-08-17 13:32:25 +0000
commit6ba1b9f3c974351e826485ca9c41df732c6de15a (patch)
tree25c08330ac9c176353cc98f6a3f6cbd0c541d07d /test/files/presentation/akka/src/akka/config/ConfigParser.scala
parent044099d4f1677425719ea8cad8c946dab8b5c2d9 (diff)
downloadscala-6ba1b9f3c974351e826485ca9c41df732c6de15a.tar.gz
scala-6ba1b9f3c974351e826485ca9c41df732c6de15a.tar.bz2
scala-6ba1b9f3c974351e826485ca9c41df732c6de15a.zip
Major rewrite of the testing infrastructure for...
Major rewrite of the testing infrastructure for the presentation compiler. Added several new tests that will be part of the nightly build. Once the move to SBT is completed I will look into how to extract the test infrastructure (as it should really not be living in the compiler codebase). Review by dragos
Diffstat (limited to 'test/files/presentation/akka/src/akka/config/ConfigParser.scala')
-rw-r--r--test/files/presentation/akka/src/akka/config/ConfigParser.scala74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/files/presentation/akka/src/akka/config/ConfigParser.scala b/test/files/presentation/akka/src/akka/config/ConfigParser.scala
new file mode 100644
index 0000000000..73fac5e31b
--- /dev/null
+++ b/test/files/presentation/akka/src/akka/config/ConfigParser.scala
@@ -0,0 +1,74 @@
+/**
+ * Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
+ *
+ * Based on Configgy by Robey Pointer.
+ * Copyright 2009 Robey Pointer <robeypointer@gmail.com>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ */
+
+package akka.config
+
+import scala.collection.mutable
+import scala.util.parsing.combinator._
+
+class ConfigParser(var prefix: String = "", map: mutable.Map[String, Any] = mutable.Map.empty[String, Any], importer: Importer) extends RegexParsers {
+ val sections = mutable.Stack[String]()
+
+ def createPrefix = {
+ prefix = if (sections.isEmpty) "" else sections.toList.reverse.mkString("", ".", ".")
+ }
+
+ override val whiteSpace = """(\s+|#[^\n]*\n)+""".r
+
+ // tokens
+
+ val numberToken: Parser[String] = """-?\d+(\.\d+)?""".r
+ val stringToken: Parser[String] = ("\"" + """([^\\\"]|\\[^ux]|\\\n|\\u[0-9a-fA-F]{4}|\\x[0-9a-fA-F]{2})*""" + "\"").r
+ val booleanToken: Parser[String] = "(true|on|false|off)".r
+ val identToken: Parser[String] = """([\da-zA-Z_][-\w]*)(\.[a-zA-Z_][-\w]*)*""".r
+ val assignToken: Parser[String] = "=".r
+ val sectionToken: Parser[String] = """[a-zA-Z][-\w]*""".r
+
+ // values
+
+ def value: Parser[Any] = number | string | list | boolean
+ def number = numberToken
+ def string = stringToken ^^ { s => s.substring(1, s.length - 1) }
+ def list = "[" ~> repsep(string | numberToken, opt(",")) <~ (opt(",") ~ "]")
+ def boolean = booleanToken
+
+ // parser
+
+ def root = rep(includeFile | assignment | sectionOpen | sectionClose)
+
+ def includeFile = "include" ~> string ^^ {
+ case filename: String =>
+ new ConfigParser(prefix, map, importer) parse importer.importFile(filename)
+ }
+
+ def assignment = identToken ~ assignToken ~ value ^^ {
+ case k ~ a ~ v => map(prefix + k) = v
+ }
+
+ def sectionOpen = sectionToken <~ "{" ^^ { name =>
+ sections push name
+ createPrefix
+ }
+
+ def sectionClose = "}" ^^ { _ =>
+ if (sections.isEmpty) {
+ failure("dangling close tag")
+ } else {
+ sections.pop
+ createPrefix
+ }
+ }
+
+ def parse(in: String): Map[String, Any] = {
+ parseAll(root, in) match {
+ case Success(result, _) => map.toMap
+ case x@Failure(msg, _) => throw new ConfigurationException(x.toString)
+ case x@Error(msg, _) => throw new ConfigurationException(x.toString)
+ }
+ }
+}