Started work on parser, submit works correctly

This commit is contained in:
Aaro Koivukangas
2026-02-09 19:13:48 +02:00
parent 0819bdd926
commit fb997bcc91
6 changed files with 34 additions and 7 deletions
+16
View File
@@ -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"]
+1
View File
@@ -0,0 +1 @@
target
+2
View File
@@ -6,6 +6,8 @@ lazy val root = project
name := "compiler", name := "compiler",
version := "0.1.0-SNAPSHOT", version := "0.1.0-SNAPSHOT",
mainClass := Some("compiler.main"),
scalaVersion := scala3Version, scalaVersion := scala3Version,
libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"org.scalameta" %% "munit" % "1.0.0" % Test, "org.scalameta" %% "munit" % "1.0.0" % Test,
+5
View File
@@ -1,2 +1,7 @@
// In project/plugins.sbt. Note, does not support sbt 0.13, only sbt 1.x. // In project/plugins.sbt. Note, does not support sbt 0.13, only sbt 1.x.
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6") 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")
+5 -2
View File
@@ -10,7 +10,7 @@ import compiler.Tokenizer._
import compiler.Parser._ import compiler.Parser._
@main def hello(): Unit = @main def main(): Unit =
println("Hello world!") println("Hello world!")
println(msg) println(msg)
run_server() run_server()
@@ -44,8 +44,11 @@ def run_server(): Unit =
case _ => s"{\"error\": \"Incorrect json request body\"}" case _ => s"{\"error\": \"Incorrect json request body\"}"
} }
println(s"Responding with: ${response}")
// Send response to the client // Send response to the client
out.println(response); out.println(response)
out.close()
def compile(source: String): String = def compile(source: String): String =
val tokens = Tokenizer.tokenize(source) val tokens = Tokenizer.tokenize(source)
+5 -5
View File
@@ -4,15 +4,15 @@ import scala.util.{Try, Success, Failure}
import compiler.Tokenizer.{Token, TokenType} 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"${this.getClass.getName.stripPrefix("compiler.Parser.")}($this)"
override def toString() = s"Expression(TODO)" override def toString() = s"Expression(TODO)"
class Literal(value: Int | Boolean) extends Expression case class Literal(value: Int | Boolean) extends Expression
class Identifier(name: String) extends Expression case class Identifier(name: String) extends Expression
class BinaryOperator(left: Expression, operator: String, right: Expression) extends Expression case class BinaryOperator(left: Expression, operator: String, right: Expression) extends Expression
class Other() extends Expression case class Other() extends Expression
class Parser(tokens: List[Token]): class Parser(tokens: List[Token]):
// Keeps track of current token, index to tokens: List[Token] // Keeps track of current token, index to tokens: List[Token]