diff --git a/src/main/scala/satify/Main.scala b/src/main/scala/satify/Main.scala index 4b7263a5..23deaff7 100644 --- a/src/main/scala/satify/Main.scala +++ b/src/main/scala/satify/Main.scala @@ -2,6 +2,7 @@ package satify import satify.Architecture.MVU import satify.Main.model +import satify.dsl.Reflection.startRepl import satify.view.Constants.windowSize import satify.view.GUI.* import satify.view.Reactions.* @@ -12,6 +13,7 @@ import scala.swing.{Dimension, FileChooser, MainFrame, Swing} /** Entry point of the application. */ object Main extends App with MVU: + startRepl() new MainFrame: title = "Satify SAT Solver" diff --git a/src/main/scala/satify/dsl/Reflection.scala b/src/main/scala/satify/dsl/Reflection.scala index d67b1f8e..d11b070c 100644 --- a/src/main/scala/satify/dsl/Reflection.scala +++ b/src/main/scala/satify/dsl/Reflection.scala @@ -3,6 +3,8 @@ package satify.dsl import satify.model.expression.Expression import satify.model.expression.Expression.Symbol +import java.util.concurrent.Executors + object Reflection: private val excludedWords = getDSLKeywords.mkString("|") @@ -19,17 +21,16 @@ object Reflection: * @param input the input to process * @return the processed input */ - def processInput(input: String): String = - // TODO: link these operators to the ones in the DSL - // regExp to match all words that are not operators - input - .replaceAll(regexPattern, "\"$1\"") - .replaceAll("\n", " ") - - /** Reflects the input to the REPL returning an Expression + def processInput(input: String): String = input + .replaceAll(regexPattern, "\"$1\"") + .replaceAll("\n", " ") + + /** Reflects the input to the REPL returning an Expression. + * If the REPL is not started yet, waits until it is started. * @param input the input to evaluate * @return the [[Expression]] * @throws IllegalArgumentException if the input is malformed + * @see [[startRepl]] */ def reflect(input: String): Expression = if input.matches(regexPattern) then Symbol(input) @@ -44,3 +45,10 @@ object Reflection: println(code) try dotty.tools.repl.ScriptEngine().eval(imports + code).asInstanceOf[Expression] catch case e: Exception => throw new IllegalArgumentException(e.getMessage) + + /** Starts the REPL in a separate thread + * When the REPL is started, the a promise is completed permitting to call [[reflect]] method. + */ + def startRepl(): Unit = Executors + .newSingleThreadExecutor() + .execute(() => dotty.tools.repl.ScriptEngine().eval("println()")) diff --git a/src/test/scala/satify/update/ConvertUpdateTest.scala b/src/test/scala/satify/update/ConvertUpdateTest.scala index 9f30470c..f984993f 100644 --- a/src/test/scala/satify/update/ConvertUpdateTest.scala +++ b/src/test/scala/satify/update/ConvertUpdateTest.scala @@ -5,7 +5,6 @@ import org.scalatest.matchers.should.Matchers import satify.model.State import satify.update.Message.* import satify.update.Update.update -import satify.view.GUI.inputTextArea class ConvertUpdateTest extends AnyFlatSpec with Matchers: