From fb997bcc91f37553e4f04e7e297ac17001eb2542 Mon Sep 17 00:00:00 2001 From: Aaro Koivukangas Date: Mon, 9 Feb 2026 19:13:48 +0200 Subject: [PATCH] Started work on parser, submit works correctly --- Dockerfile | 16 ++++++++++++++++ compiler/.dockerignore | 1 + compiler/build.sbt | 2 ++ compiler/project/plugins.sbt | 5 +++++ compiler/src/main/scala/Main.scala | 7 +++++-- compiler/src/main/scala/Parser.scala | 10 +++++----- 6 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 Dockerfile create mode 100644 compiler/.dockerignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ecd218f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM sbtscala/scala-sbt:eclipse-temurin-alpine-21.0.8_9_1.12.1_3.8.1 AS builder + +WORKDIR /usr/src +COPY . . + +WORKDIR /usr/src/compiler + +RUN sbt clean assembly + +FROM eclipse-temurin:21 + +WORKDIR /usr/src +COPY --from=builder /usr/src/compiler/target/scala-3.8.1/compiler-assembly-0.1.0-SNAPSHOT.jar compiler.jar +COPY ./compiler ./ + +CMD ["java", "-jar", "compiler.jar"] diff --git a/compiler/.dockerignore b/compiler/.dockerignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/compiler/.dockerignore @@ -0,0 +1 @@ +target diff --git a/compiler/build.sbt b/compiler/build.sbt index 7005a87..017b29c 100644 --- a/compiler/build.sbt +++ b/compiler/build.sbt @@ -6,6 +6,8 @@ lazy val root = project name := "compiler", version := "0.1.0-SNAPSHOT", + mainClass := Some("compiler.main"), + scalaVersion := scala3Version, libraryDependencies ++= Seq( "org.scalameta" %% "munit" % "1.0.0" % Test, diff --git a/compiler/project/plugins.sbt b/compiler/project/plugins.sbt index beb0aac..e2c364c 100644 --- a/compiler/project/plugins.sbt +++ b/compiler/project/plugins.sbt @@ -1,2 +1,7 @@ // In project/plugins.sbt. Note, does not support sbt 0.13, only sbt 1.x. addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6") + +// Source - https://stackoverflow.com/a/30576584 +// Posted by shutty, modified by community. See post 'Timeline' for change history +// Retrieved 2026-02-06, License - CC BY-SA 3.0 +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1") diff --git a/compiler/src/main/scala/Main.scala b/compiler/src/main/scala/Main.scala index d26efa1..d1c978e 100644 --- a/compiler/src/main/scala/Main.scala +++ b/compiler/src/main/scala/Main.scala @@ -10,7 +10,7 @@ import compiler.Tokenizer._ import compiler.Parser._ -@main def hello(): Unit = +@main def main(): Unit = println("Hello world!") println(msg) run_server() @@ -44,8 +44,11 @@ def run_server(): Unit = case _ => s"{\"error\": \"Incorrect json request body\"}" } + + println(s"Responding with: ${response}") // Send response to the client - out.println(response); + out.println(response) + out.close() def compile(source: String): String = val tokens = Tokenizer.tokenize(source) diff --git a/compiler/src/main/scala/Parser.scala b/compiler/src/main/scala/Parser.scala index 74fc7f5..7f9df10 100644 --- a/compiler/src/main/scala/Parser.scala +++ b/compiler/src/main/scala/Parser.scala @@ -4,15 +4,15 @@ import scala.util.{Try, Success, Failure} import compiler.Tokenizer.{Token, TokenType} -sealed trait Expression: +sealed abstract class Expression: //override def toString() = s"${this.getClass.getName.stripPrefix("compiler.Parser.")}($this)" override def toString() = s"Expression(TODO)" -class Literal(value: Int | Boolean) extends Expression -class Identifier(name: String) extends Expression -class BinaryOperator(left: Expression, operator: String, right: Expression) extends Expression -class Other() extends Expression +case class Literal(value: Int | Boolean) extends Expression +case class Identifier(name: String) extends Expression +case class BinaryOperator(left: Expression, operator: String, right: Expression) extends Expression +case class Other() extends Expression class Parser(tokens: List[Token]): // Keeps track of current token, index to tokens: List[Token]