Created
August 17, 2015 04:10
-
-
Save jacobappleton/b5d40e1d1f54be4134b9 to your computer and use it in GitHub Desktop.
An Akka actor to handle Regex pattern parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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