Start making the DSLParser code readable
authorGeorgios Gousios <gousiosg@gmail.com>
Thu, 10 Nov 2011 08:44:28 +0000 (10:44 +0200)
committerGeorgios Gousios <gousiosg@gmail.com>
Thu, 10 Nov 2011 08:45:33 +0000 (10:45 +0200)
logic/src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/DSL.scala
logic/src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/Vocabulary.scala [new file with mode: 0644]
logic/src/test/resources/policy.yaml
logic/src/test/scala/gr/grnet/aquarium/logic/test/DSLTest.scala

index e90ad54..80aeefe 100644 (file)
@@ -5,6 +5,8 @@ import com.kenai.crontabparser.impl.CronTabParserBridge
 import java.io.{InputStreamReader, InputStream}
 import gr.grnet.aquarium.util.Loggable
 import gr.grnet.aquarium.util.yaml._
+import org.yaml.snakeyaml.Yaml
+import java.lang.StringBuffer
 import java.util.Date
 
 /**
@@ -12,26 +14,8 @@ import java.util.Date
  *
  * @author Georgios Gousios <gousiosg@gmail.com>
  */
-object DSL extends Loggable {
 
-  private object Vocabulary {
-    val creditpolicy = "creditpolicy"
-    val resources = "resources"
-    val policies = "policies"
-    val policy = "policy"
-    val pricelists = "pricelists"
-    val pricelist = "pricelist"
-    val agreements = "agreements"
-    val agreement = "agreement"
-    val name = "name"
-    val overrides = "overrides"
-    val effective = "effective"
-    val from = "from"
-    val to = "to"
-    val repeat = "repeat"
-    val start = "start"
-    val end = "end"
-  }
+object DSL extends Loggable {
 
   private val emptyPolicy = DSLPolicy("", None, Map(),
     DSLTimeFrame(new Date(0), None, Option(List())))
@@ -458,6 +442,11 @@ object DSL extends Loggable {
   }
 }
 
+sealed abstract class DSLTreeNode {
+  abstract def toYaml() : String
+  abstract def children() : List[DSLTreeNode]
+}
+
 case class DSLCreditPolicy (
   policies: List[DSLPolicy],
   pricelists: List[DSLPriceList],
diff --git a/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/Vocabulary.scala b/logic/src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/Vocabulary.scala
new file mode 100644 (file)
index 0000000..48f87cc
--- /dev/null
@@ -0,0 +1,20 @@
+package gr.grnet.aquarium.logic.accounting.dsl
+
+object Vocabulary {
+  val creditpolicy = "creditpolicy"
+  val resources = "resources"
+  val policies = "policies"
+  val policy = "policy"
+  val pricelists = "pricelists"
+  val pricelist = "pricelist"
+  val agreements = "agreements"
+  val agreement = "agreement"
+  val name = "name"
+  val overrides = "overrides"
+  val effective = "effective"
+  val from = "from"
+  val to = "to"
+  val repeat = "repeat"
+  val start = "start"
+  val end = "end"
+}
index de5d6c3..accfc01 100644 (file)
@@ -38,7 +38,7 @@ creditpolicy:
       diskspace: 0.05
       effective:
         from: 0
-    - pricelist:
+    - pricelist: 
       name: everyTue2
       bandwidthup: 0.01
       bandwidthdown: 0.02
index a9a787a..f8494f8 100644 (file)
@@ -113,6 +113,13 @@ class DSLTest {
     assertThrows(DSL.parseCronString(input))
   }
 
+  @Test
+  def testSerialization = {
+    before
+    val a = creditpolicy.toYaml()
+    println(a)
+  }
+
   def assertThrows(f: => Unit) = {
     try {
       f