Skip to content

Commit

Permalink
Updated with boolean expr parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
vbergeron-ledger committed Nov 23, 2023
1 parent b2b6aa9 commit 7eaaa91
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
10 changes: 4 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
lazy val sharedSettings = Seq(
name := "sail",
scalaVersion := "3.3.1"
)
ThisBuild / scalaVersion := "3.3.1"

val sail = crossProject(JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("."))
.settings(sharedSettings)
.settings(
name := "sail",
scalaVersion := "3.3.1",
libraryDependencies ++= Seq(
"org.scalameta" %%% "munit" % "1.0.0-M8" % Test,
"com.lihaoyi" %%% "fastparse" % "3.0.2",
Expand All @@ -19,6 +17,6 @@ val sail = crossProject(JVMPlatform, NativePlatform)
nativeConfig ~= { nc =>
nc.withLTO(LTO.thin)
.withGC(GC.none)
.withMode(Mode.releaseFull)
.withMode(Mode.releaseFast)
}
}
1 change: 0 additions & 1 deletion native/src/main/scala/SailNative.scala

This file was deleted.

4 changes: 1 addition & 3 deletions src/main/scala/sail/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ final case class Args(
source: String
)

class Sail
object Sail
extends CommandApp(
name = "sail",
header = "A Functional, Declarative Dockerfile generator",
Expand Down Expand Up @@ -288,5 +288,3 @@ class Sail
.map(run)
}
)

object SailJVM extends Sail
18 changes: 11 additions & 7 deletions src/main/scala/sail/parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,32 @@ def part[$: P]: P[Part] =
capture | content

def expr[$: P]: P[Expr] =
scope | container | module | funcDef | instr | template | str | num | boolean | funcCall | sym
scope | container | module | funcDef | instr | template | str | num | funcCall | sym | boolean.apply

def boolean[$: P]: P[BooleanExpr] =
object boolean:
def t[$: P]: P[BooleanExpr.True.type] =
P("true").map(_ => BooleanExpr.True)

def f[$: P]: P[BooleanExpr.False.type] =
P("false").map(_ => BooleanExpr.False)

def and[$: P]: P[BooleanExpr.And] =
P(expr ~ ws ~ "and" ~ ws ~ expr).map(BooleanExpr.And.apply)
P(expr ~ ws ~ "and" ~/ ws ~ expr)
.map(BooleanExpr.And.apply)

def or[$: P]: P[BooleanExpr.Or] =
P(expr ~ ws ~ "or" ~ ws ~ expr).map(BooleanExpr.Or.apply)
P(expr ~ ws ~ "or" ~/ ws ~ expr)
.map(BooleanExpr.Or.apply)

def not[$: P]: P[BooleanExpr.Not] =
P("not" ~ ws ~ expr).map(BooleanExpr.Not.apply)

def eq[$: P]: P[BooleanExpr.Eq] =
P(expr ~ ws ~ "==" ~ ws ~ expr).map(BooleanExpr.Eq.apply)
P(expr ~ ws ~ "==" ~/ ws ~ expr)
.map(BooleanExpr.Eq.apply)

eq | and | or | not | t | f
def apply[$: P]: P[BooleanExpr] =
eq | and | or | not | t | f

def instr[$: P]: P[Instr] =
def run[$: P]: P[Instr.Run] =
Expand All @@ -63,7 +67,7 @@ def instr[$: P]: P[Instr] =
def rec[$: P]: P[Instr] =
block | defer | run | expose | copy | call

block | defer | run | expose | copy
rec

def scope[$: P]: P[Expr.Scope] =
P("let" ~ ws ~ (funcDef ~ ws).rep ~ "in" ~ ws ~ expr).map(Expr.Scope.apply)
Expand Down
9 changes: 8 additions & 1 deletion src/test/scala/parser.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ParserTest extends FunSuite:
passing("FuncDef", "f(a): body", funcDef(_))
passing("FuncDef", "f(a,b,c,d): body", funcDef(_))

failing("FuncCall", "f()", funcCall(_))
// failing("FuncCall", "f()", funcCall(_))
passing("FuncCall", "f('str')", funcCall(_))
passing("FuncCall", "f(g(x))", funcCall(_))
passing("FuncCall", "f(a,b,c)", funcCall(_))
Expand All @@ -102,3 +102,10 @@ class ParserTest extends FunSuite:
passing("Scope", "let a(x): b in body", scope(_))

passing("Containter", "from 'scratch': run ''", container(_))

passing("Boolean", "true", boolean(_))
passing("Boolean", "false", boolean(_))
passing("Boolean", "bar or bar", boolean(_))
passing("Boolean", "f(x) and g(y)", boolean(_))
passing("Boolean", "f(x) == g(y)", boolean(_))
passing("Boolean", "not f(x)", boolean(_))

0 comments on commit 7eaaa91

Please sign in to comment.