Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jhkolb committed Jul 21, 2016
0 parents commit a1b7ba2
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.swp
frontend/target
frontend/.idea
frontend/project
7 changes: 7 additions & 0 deletions frontend/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name := "frontend"

version := "1.0"

scalaVersion := "2.11.8"

libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.4"
35 changes: 35 additions & 0 deletions frontend/src/main/scala/edu/berkeley/cs/sdb/ConfigParser.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package edu.berkeley.cs.sdb

import scala.util.parsing.combinator._

class ConfigParser extends JavaTokenParsers {
def path: Parser[String] = """/?([a-zA-z\._\-]+/)*[a-zA-z\._\-]+""".r
def entity = "entity" ~> path


def URI: Parser[String] = """([a-zA-z\._\-]/)*[a-zA-Z\._\-](/\* | /\+)?""".r
def spawnpointList: Parser[Seq[String]] = "spawnpoints" ~> "{" ~> rep1sep(URI, ",") <~ "}"


def value: Parser[Any] = stringLiteral |
wholeNumber ^^ (_.toInt) |
floatingPointNumber ^^ (_.toDouble)

def valueSequence: Parser[Seq[Any]] = "[" ~> rep1sep(value, ",") <~ "]"

def parameter: Parser[(String, Any)] = ident ~ ":" ~ (ident | value | valueSequence) ^^ { case k ~ ":" ~ v => (k,v) }

def parameterSequence: Parser[Seq[(String, Any)]] = "{" ~> repsep(parameter, ",") <~ "}"

def spawnpointSpec: Parser[Either[String, Seq[(String, Any)]]] =
"on" ~> (ident | stringLiteral) ^^ (Left(_))
"where" ~> parameterSequence ^^ (Right(_))

def serviceDeployment: Parser[Service] = "deploy" ~ path ~ "as" ~ ident ~ "with" ~ parameterSequence ~ spawnpointSpec ^^
{ case "deploy" ~ imgName ~ "as" ~ svcName ~ "with" ~ params ~ spec => Service(svcName, imgName, params, spec) }

def svcGraph: Parser[Seq[(String, String)]] = repsep(ident, "->") ^^ (_.sliding(2).map { case Seq(x, y) => (x, y) }.toSeq)

def deployment: Parser[Deployment] = entity ~ spawnpointList ~ rep(serviceDeployment) ~ rep(svcGraph) ^^
{ case ent ~ spawnpoints ~ svcs ~ connList => Deployment(ent, spawnpoints, svcs, connList.flatten) }
}
4 changes: 4 additions & 0 deletions frontend/src/main/scala/edu/berkeley/cs/sdb/Deployment.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package edu.berkeley.cs.sdb

case class Deployment(entity: String, spawnPointUris: Seq[String], services: Seq[Service],
topology: Seq[(String, String)])
4 changes: 4 additions & 0 deletions frontend/src/main/scala/edu/berkeley/cs/sdb/Service.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package edu.berkeley.cs.sdb

case class Service(name: String, imageName: String, params: Seq[(String, Any)],
spawnpointSpec: Either[String, Seq[(String, Any)]])

0 comments on commit a1b7ba2

Please sign in to comment.