Skip to content

Instantly share code, notes, and snippets.

@jacobappleton
Created August 17, 2015 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobappleton/b5d40e1d1f54be4134b9 to your computer and use it in GitHub Desktop.
Save jacobappleton/b5d40e1d1f54be4134b9 to your computer and use it in GitHub Desktop.
An Akka actor to handle Regex pattern parsing
package io.jacobappleton.compilers.server.workers
import akka.actor.{Actor, ActorLogging}
import io.jacobappleton.compilers.automata.DFAPrinter
import io.jacobappleton.compilers.regex.Regex
import io.jacobappleton.compilers.server.workers.RegexWorkerActor.RegexResponse
import spray.json.DefaultJsonProtocol
class RegexWorkerActor extends Actor with ActorLogging {
def receive = {
case s: String =>
log.info(s"Parsing Regex pattern: $s")
val printer = new DFAPrinter(new Regex(s).toNFA().toDFA())
sender ! RegexResponse(printer.printGraph(), printer.toTable())
}
}
object RegexWorkerActor {
case class RegexResponse (graph: String, table: String)
}
object RegexWorkerJsonProtocol extends DefaultJsonProtocol {
implicit val RegexResponseFormat = jsonFormat2(RegexResponse)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment