Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version = "3.5.3"

runner.dialect = scala213
runner.dialect = scala3

preset=IntelliJ
project.excludeFilters = ["metals.sbt"]
Expand Down
59 changes: 31 additions & 28 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject

import scala.sys.process._

val scalaVersion2 = "2.13.10"
// val scalaVersion3 = "3.2.1"
// val scalaVersion2 = "2.13.10"
val scalaVersion3 = "3.2.1"

lazy val commonSettings = Seq(
organization := "com.ibm.cloud.diesel",
scalaVersion := scalaVersion2,
scalaVersion := scalaVersion3,
versionScheme := Some("semver-spec"),
description := "Diesel is a library for creating and using languages easily."
)
Expand Down Expand Up @@ -55,14 +55,18 @@ lazy val root = project

lazy val sharedSettings_scalac = Seq(
scalacOptions ++= Seq(
// "-source:3.0-migration",
"-source:3.0",
"-new-syntax",
"-rewrite",
"-unchecked",
"-deprecation",
"-feature",
"-Xfatal-warnings",
"-Wconf:cat=deprecation:i",
"-language:existentials",
"-Wunused:imports",
"-Ytasty-reader"
// "-Wconf:cat=deprecation:i",
"-language:existentials"
// "-Wunused:imports",
// "-Ytasty-reader"
)
)

Expand All @@ -77,28 +81,28 @@ lazy val sharedSettings_test = Seq(
)

lazy val sharedSettings_lint = Seq(
addCompilerPlugin(scalafixSemanticdb),
ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value),
ThisBuild / semanticdbEnabled := true,
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision
// addCompilerPlugin(scalafixSemanticdb),
// ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value),
ThisBuild / semanticdbEnabled := true
// ThisBuild / semanticdbVersion := scalafixSemanticdb.revision
)

lazy val sharedJsSettings = Seq(
scalacOptions += {
val branch =
if (version.value.endsWith("SNAPSHOT")) {
"develop"
} else {
version.value
}
val local: String = baseDirectory.value.getParentFile.getParentFile.toURI.toString
val remote = s"https://raw.github.ibm.com/IBM/diesel-core/$branch/"
println(s"sourceURIs : \nLOCAL:$local\nREMOTE:$remote")
s"-P:scalajs:mapSourceURI:$local->$remote"
},
// scalacOptions += {
// val branch =
// if (version.value.endsWith("SNAPSHOT")) {
// "develop"
// } else {
// version.value
// }
// val local: String = baseDirectory.value.getParentFile.getParentFile.toURI.toString
// val remote = s"https://raw.github.ibm.com/diesel/diesel/$branch/"
// println(s"sourceURIs : \nLOCAL:$local\nREMOTE:$remote")
// s"-P:scalajs:mapSourceURI:$local->$remote"
// }
// for dependency: pine
libraryDependencies := libraryDependencies.value.filterNot(_.name == "scalajs-compiler"),
addCompilerPlugin("org.scala-js" % "scalajs-compiler" % scalaJSVersion cross CrossVersion.patch)
// libraryDependencies := libraryDependencies.value.filterNot(_.name == "scalajs-compiler"),
// addCompilerPlugin("org.scala-js" % "scalajs-compiler" % scalaJSVersion cross CrossVersion.patch)
)

lazy val diesel = crossProject(JSPlatform, JVMPlatform)
Expand All @@ -115,9 +119,8 @@ lazy val diesel = crossProject(JSPlatform, JVMPlatform)
.settings(sharedSettings_scalac)
.settings(
libraryDependencies ++= Seq(
"com.ibm.cloud.diesel" %%% "diesel-i18n" % Dependencies.dieselI18nVersion,
scalaOrganization.value % "scala-reflect" % scalaVersion.value,
"org.scalameta" %%% "munit" % "1.0.0-M7" % Test
"com.ibm.cloud.diesel" %%% "diesel-i18n" % Dependencies.dieselI18nVersion cross (CrossVersion.for3Use2_13),
"org.scalameta" %%% "munit" % "1.0.0-M7" % Test
)
)
.settings(sharedSettings_test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ object Evaluator {

object EBool {
def apply(b: Boolean): EBool =
if (b)
if b then
ETrue
else
EFalse
Expand Down Expand Up @@ -129,7 +129,7 @@ object Evaluator {
val variablesToDeclare = args match {
case Left(positional) =>
// arg count must match
if (positional.size != definition.params.size) {
if positional.size != definition.params.size then {
throw new UnsupportedOperationException("invalid arg list")
} else {
definition.params.map(_.n.s).zip(positional)
Expand Down Expand Up @@ -207,7 +207,7 @@ object Evaluator {
???
case TEIf(IfExpression(cond, thenExpr, elseExpr)) =>
val c = eval(cond)
if (c.isTruthy)
if c.isTruthy then
eval(thenExpr)
else
eval(elseExpr)
Expand Down Expand Up @@ -361,7 +361,7 @@ object Evaluator {
case SLString(l) =>
EStr(l.v)
case SLBool(l) =>
if (l.v) ETrue else EFalse
if l.v then ETrue else EFalse
case SLDateTime(l) =>
???
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class Feel extends Dsl with Identifiers with DynamicLexer {
// regex matches : check in scope/keywords
var i = 1
var m: Option[String] = None
while (i <= str.length()) {
while i <= str.length() do {
val s = str.substring(0, i)
if (scope.contains(s) || keywords.contains(s)) {
if scope.contains(s) || keywords.contains(s) then {
m = Some(s)
}
i = i + 1
Expand All @@ -46,7 +46,7 @@ class Feel extends Dsl with Identifiers with DynamicLexer {
case None =>
val i = str.indexOf(" in")
val r =
if (i != -1) {
if i != -1 then {
str.substring(0, i)
} else {
str
Expand Down Expand Up @@ -86,7 +86,7 @@ class Feel extends Dsl with Identifiers with DynamicLexer {
case Some(x) =>
val i = x.indexOf(" in")
val r =
if (i != -1) {
if i != -1 then {
x.substring(0, i)
} else {
x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ object Glsl extends Dsl with Identifiers with Comments {
}

val s_primary_expression_3: Instance[PrimaryExpression] =
instance(primary_expression)("true") map { c: Context =>
instance(primary_expression)("true") map { (c: Context) =>
c.setStyle(Keyword)
PrimBoolConstant(true)
}

val s_primary_expression_4: Instance[PrimaryExpression] =
instance(primary_expression)("false") map { c: Context =>
instance(primary_expression)("false") map { (c: Context) =>
c.setStyle(Keyword)
PrimBoolConstant(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ case class ENum(v: Double) extends EValue {
}

override def dash(): EValue = {
ENum(if (v == 0) 0 else -v)
ENum(if v == 0 then 0 else -v)
}
}

Expand All @@ -109,10 +109,10 @@ object Vec {

def mkValues(nbComponents: Int, values: Array[Double]): Array[Double] = {
val buf: mutable.ArrayBuffer[Double] = mutable.ArrayBuffer()
for (i <- 0 until nbComponents) {
for i <- 0 until nbComponents do {
buf.append(
values(
if (values.length < nbComponents) {
if values.length < nbComponents then {
0
} else {
i
Expand Down Expand Up @@ -222,8 +222,8 @@ trait Vec extends EValue {
val thisValues = values
val otherValues = vec.values
val newVals = mutable.ArrayBuffer[Double]()
for (i <- thisValues.indices) {
if (i < otherValues.length) {
for i <- thisValues.indices do {
if i < otherValues.length then {
newVals.append(f(values(i), otherValues(i)))
} else {
newVals.append(values(i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ case class GlslFunc(args: Seq[GlslArg], body: Option[StatementList]) extends Fun
.map(statements => {
// create a new scope and add all arguments into it
val s = scope.push()
for ((arg, argIndex) <- args.zipWithIndex) {
for (arg, argIndex) <- args.zipWithIndex do {
val argVal = arguments(argIndex) match {
case ERef(name) =>
scope.find(name).get
Expand All @@ -47,8 +47,8 @@ case class GlslFunc(args: Seq[GlslArg], body: Option[StatementList]) extends Fun

// post-process out args by setting their
// values in the parent scope
for ((arg, argIndex) <- args.zipWithIndex) {
if (arg.isOut) {
for (arg, argIndex) <- args.zipWithIndex do {
if arg.isOut then {
arguments(argIndex) match {
case ERef(parentScopeVarName) =>
// it's a ref : update in the parent scope...
Expand Down Expand Up @@ -97,7 +97,7 @@ object BuiltInFunction {
}

def myCos: BuiltInFunction = BuiltInFunction((scope, exprs) => {
if (exprs.length == 1) {
if exprs.length == 1 then {
exprs(0) match {
case ERef(name) =>
val v = scope.find(name).get
Expand All @@ -112,11 +112,11 @@ object BuiltInFunction {
})

def myDot(values: Array[Double], values2: Array[Double]): EValue = {
if (values.length != values2.length) {
if values.length != values2.length then {
throw new IllegalArgumentException("dot product must have arrays of same length")
}
var p: Double = 0
for (i <- values.indices) {
for i <- values.indices do {
p = p + values(i) * values2(i)
}
num(p)
Expand All @@ -128,7 +128,7 @@ object BuiltInFunction {
"vec4" -> vecN(4),
"cos" -> myCos,
"dot" -> BuiltInFunction((scope, exprs) => {
if (exprs.length != 2) {
if exprs.length != 2 then {
throw new IllegalArgumentException("dot() needs 2 args")
}
myDot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class GlslEval(var scope: Scope) {

def eval(e: ConditionalExpression): Expr = {
val r = eval(e.e)
if (e.rest.isDefined) {
if e.rest.isDefined then {
throw new RuntimeException("TODO")
}
r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class Scope(
def getFunctions: Map[String, Func] = functions.toMap

def setValue(name: String, value: EValue): Unit = {
if (variables.contains(name)) {
if variables.contains(name) then {
variables(name) = value
} else {
if (parent.isDefined) {
if parent.isDefined then {
parent.get.setValue(name, value)
} else {
throw new IllegalStateException(s"trying to set value of undeclared ${name}")
Expand All @@ -74,7 +74,7 @@ object Scope {

def initial(): Scope = {
val s = new Scope()
for (f <- BuiltInFunction.builtInFunctions) {
for f <- BuiltInFunction.builtInFunctions do {
s.declare(f._1, f._2)
}
s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ case class JsModelDecl(root: Root, types: Seq[TypeDefinition] = Seq()) {

def format: String =
s"""root : ${formatTypeRef(root.rootType)}""" +
(if (types.isEmpty) "" else "\n\n") +
(if types.isEmpty then "" else "\n\n") +
types.zipWithIndex.map(x =>
formatTypeDefinition(x._1) + (if (x._2 < types.length - 1) "\n\n" else "")
formatTypeDefinition(x._1) + (if x._2 < types.length - 1 then "\n\n" else "")
).mkString

private def formatDiscriminator(discriminator: Discriminator): String =
Expand All @@ -100,7 +100,7 @@ case class JsModelDecl(root: Root, types: Seq[TypeDefinition] = Seq()) {
formatDiscriminator
).getOrElse("") + " {\n" +
attributes.map(a =>
s" ${a.name}${if (a.optional) "?" else ""} : ${formatTypeRef(a.declaredType)}"
s" ${a.name}${if a.optional then "?" else ""} : ${formatTypeRef(a.declaredType)}"
).mkString(
"\n"
) +
Expand All @@ -109,7 +109,7 @@ case class JsModelDecl(root: Root, types: Seq[TypeDefinition] = Seq()) {
s"domain ${name} [\n" +
values.zipWithIndex.map {
case (v, i) =>
s""" "${v}"${if (i < values.size - 1) ",\n" else ""}"""
s""" "${v}"${if i < values.size - 1 then ",\n" else ""}"""
}.mkString +
"\n]"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ object GenericTreeUtil {
}

def debugTraceValue[T](title: String): T => T = { v =>
println(title, v)
println(s"$title $v")
v
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ case object BmdDsl extends Dsl with Identifiers with Comments { // with DynamicL
val sExtendsDeclaration: Syntax[CustomType] = syntax(
sSymbolRef map {
case (ctx, isA) =>
if (isA.text == "concept") {
if isA.text == "concept" then {
ctx.abort()
}
CustomType(Offsets(isA.offset, isA.length), isA.text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ case object JsModelDsl extends Dsl with Identifiers with Comments with DynamicLe
proposals.flatMap { p =>
p.element match {
case Some(DslSyntax(syntax)) =>
if (syntax.name == sCustomRef.name) {
if syntax.name == sCustomRef.name then {
// pediction for a custom ref : list what we have !
model.types.map(td => CompletionProposal(p.element, td.name))
} else if (syntax.name == sSuperClassName.name) {
} else if syntax.name == sSuperClassName.name then {
val classDeclNode =
node.flatMap(_.findFirstParent(_.value.isInstanceOf[ClassDeclaration]))
classDeclNode
Expand All @@ -183,9 +183,9 @@ case object JsModelDsl extends Dsl with Identifiers with Comments with DynamicLe
.map(CompletionProposal(p.element, _))
}
.getOrElse(Seq.empty)
} else if (
} else if
syntax.name == sAttrName.name || syntax.name == sClassName.name || syntax.name == sDomainName.name
) {
then {
Seq()
} else {
Seq(p)
Expand Down
Loading