This file contains hidden or 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
| pathPrefix("api") { | |
| path("regex") { | |
| post { | |
| entity(as[String]) { pattern => | |
| complete { | |
| (regexWorker ? pattern).mapTo[RegexResponse] | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or 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
| pathPrefix("app") { | |
| pathPrefix("assets") { | |
| getFromResourceDirectory("web/assets/") | |
| } ~ { | |
| getFromResource("web/index.html") | |
| } | |
| } |
This file contains hidden or 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
| path("") { | |
| redirect("http://www.jacobappleton.io", StatusCodes.PermanentRedirect) | |
| } |
This file contains hidden or 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
| val compilerRoute : Route = | |
| path("") { | |
| redirect("http://www.jacobappleton.io", StatusCodes.PermanentRedirect) | |
| } ~ | |
| pathPrefix("app") { | |
| pathPrefix("assets") { | |
| getFromResourceDirectory("web/assets/") | |
| } ~ { | |
| getFromResource("web/index.html") | |
| } |
This file contains hidden or 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
| def matchTest(x: Int): String = x match { | |
| case 1 => "one" | |
| case 2 => "two" | |
| case _ => "many" | |
| } |
This file contains hidden or 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 = { |
This file contains hidden or 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
| it should "handle nested parentheses" in { | |
| val nfa = new Regex("j.a.((c|x)|(k|y)).o.b").toNFA() | |
| val printer = new NFAPrinter(nfa) | |
| val expectedTable = | |
| "| | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | ε |\n" + | |
| "|--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |\n" + | |
| "| 0 | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } |\n" + | |
| "| 1 | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { 2 } | { 0 } | { 0 } | { 0 } | { 0 } | { 0 } | { |
This file contains hidden or 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
| it should "handle single parentheses" in { | |
| val nonParensNfa = new Regex("a.b|c.d").toNFA() | |
| val parensNfa = new Regex("a.(b|c).d").toNFA() | |
| val nonParensPrinter = new NFAPrinter(nonParensNfa) | |
| val parensPrinter = new NFAPrinter(parensNfa) | |
| val expectedTableNonParens = | |
| "| | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | ε |\n" + | |
| "|--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |--- |\n" + |
This file contains hidden or 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.regex | |
| import org.scalatest.FlatSpec | |
| import scala.language.postfixOps | |
| class ShuntingYardTests extends FlatSpec { | |
| it should "when given the Regex a.b|c.d the output should be ab.cd.|" in { | |
| val parser = new ShuntingYard(Map('|' -> 0, '.' -> 1, '*' -> 2)) | |
| assert(parser.toPostfix("a.b|c.d") == "ab.cd.|") | |
| } |
This file contains hidden or 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.regex | |
| class ShuntingYard(val operatorPrecedence: Map[Char, Int]) { | |
| def toPostfix(s: String): String = toPostfix(s, "", "") | |
| def isOperator(x: Char) = operatorPrecedence.contains(x) | |
| def hasLowerPrecedence(a: Char, b: Char) = operatorPrecedence(a) <= operatorPrecedence(b) |