diff --git a/build.sc b/build.sc index f3ecb8dc..020aab64 100644 --- a/build.sc +++ b/build.sc @@ -1,7 +1,18 @@ import mill._, scalalib._, publish._ -val sjsonnetVersion = "0.1.3" +val sjsonnetVersion = "0.1.4" -trait SjsonnetJavaModule extends PublishModule{ +object sjsonnet extends Cross[SjsonnetModule]("2.12.8", "2.13.0") +class SjsonnetModule(val crossScalaVersion: String) extends CrossScalaModule with PublishModule { + def mainClass = Some("sjsonnet.SjsonnetMain") + def ivyDeps = Agg( + ivy"com.lihaoyi::fastparse:2.1.3", + ivy"com.lihaoyi::pprint:0.5.5", + ivy"com.lihaoyi::os-lib:0.3.0", + ivy"com.lihaoyi::ujson:0.7.5", + ivy"com.lihaoyi::scalatags:0.7.0", + ivy"com.github.scopt::scopt:3.7.1", + ivy"org.scala-lang.modules::scala-collection-compat:2.0.0" + ) def publishVersion = sjsonnetVersion def pomSettings = PomSettings( @@ -15,30 +26,13 @@ trait SjsonnetJavaModule extends PublishModule{ ) ) -} -trait SjsonnetScalaModule extends SjsonnetJavaModule with ScalaModule{ - def scalaVersion = "2.12.6" -// def compileIvyDeps = Agg(ivy"com.lihaoyi::acyclic:0.1.7") -// def scalacOptions = Seq("-P:acyclic:force") -// def scalacPluginIvyDeps = Agg(ivy"com.lihaoyi::acyclic:0.1.7") -} -object sjsonnet extends SjsonnetScalaModule{ - def mainClass = Some("sjsonnet.SjsonnetMain") - def ivyDeps = Agg( - ivy"com.lihaoyi::fastparse:2.0.5", - ivy"com.lihaoyi::pprint:0.5.3", - ivy"com.lihaoyi::os-lib:0.1.0", - ivy"com.lihaoyi::ujson:0.6.7", - ivy"com.lihaoyi::scalatags:0.6.7", - ivy"com.github.scopt::scopt:3.5.0" - ) object test extends Tests{ - def ivyDeps = Agg(ivy"com.lihaoyi::utest:0.6.4") + def ivyDeps = Agg(ivy"com.lihaoyi::utest:0.7.1") def testFrameworks = Seq("utest.runner.Framework") } - object client extends SjsonnetJavaModule { + object client extends JavaModule { def ivyDeps = Agg( ivy"org.scala-sbt.ipcsocket:ipcsocket:1.0.0".exclude( "net.java.dev.jna" -> "jna", @@ -51,9 +45,9 @@ object sjsonnet extends SjsonnetScalaModule{ } } - object server extends SjsonnetScalaModule{ - def scalaVersion = "2.12.6" - def moduleDeps = Seq(sjsonnet, client) + object server extends ScalaModule{ + def scalaVersion = crossScalaVersion + def moduleDeps = Seq(SjsonnetModule.this, client) def ivyDeps = Agg( ivy"org.scala-sbt.ipcsocket:ipcsocket:1.0.0".exclude( "net.java.dev.jna" -> "jna", diff --git a/mill b/mill new file mode 100755 index 00000000..e72881b9 --- /dev/null +++ b/mill @@ -0,0 +1,32 @@ +#!/usr/bin/env sh + +# This is a wrapper script, that automatically download mill from GitHub release pages +# You can give the required mill version with MILL_VERSION env variable +# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION +DEFAULT_MILL_VERSION=0.4.2 + +set -e + +if [ -z "$MILL_VERSION" ] ; then + MILL_VERSION=$DEFAULT_MILL_VERSION +fi + +MILL_DOWNLOAD_PATH="$HOME/.mill/download" +MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/$MILL_VERSION" + +if [ ! -x "$MILL_EXEC_PATH" ] ; then + mkdir -p $MILL_DOWNLOAD_PATH + DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download + MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/$MILL_VERSION" + curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL" + chmod +x "$DOWNLOAD_FILE" + mkdir -p "$MILL_DOWNLOAD_PATH" + mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH" + unset DOWNLOAD_FILE + unset MILL_DOWNLOAD_URL +fi + +unset MILL_DOWNLOAD_PATH +unset MILL_VERSION + +exec $MILL_EXEC_PATH "$@" diff --git a/readme.md b/readme.md index 23df0319..cc6476d8 100644 --- a/readme.md +++ b/readme.md @@ -156,13 +156,13 @@ mitigate the unfortunate JVM warmup overhead that adds ~1s to every invocation down to 0.2-0.3s. For the simple non-client-server executable, you can use ```bash -mill show sjsonnet.assembly +./mill show sjsonnet.assembly ``` To create the executable. For the client-server executable, you can use ```bash -mill show sjsonnet.server.assembly +./mill show sjsonnet.server.assembly ``` By default, the Sjsonnet background server lives in `~/.sjsonnet`, and lasts 5 diff --git a/sjsonnet/src/sjsonnet/Cli.scala b/sjsonnet/src/sjsonnet/Cli.scala index 094f04b3..80ca76e7 100644 --- a/sjsonnet/src/sjsonnet/Cli.scala +++ b/sjsonnet/src/sjsonnet/Cli.scala @@ -130,7 +130,7 @@ object Cli{ for(arg <- args) yield { showArg(arg).padTo(leftMargin, ' ').mkString + - arg.doc.lines.mkString("\n" + " " * leftMargin) + arg.doc.linesIterator.mkString("\n" + " " * leftMargin) } } def help(wd: os.Path) = { @@ -176,4 +176,4 @@ object Cli{ } rec(flatArgs, initial) } -} \ No newline at end of file +} diff --git a/sjsonnet/src/sjsonnet/Evaluator.scala b/sjsonnet/src/sjsonnet/Evaluator.scala index 78524b25..6634068f 100644 --- a/sjsonnet/src/sjsonnet/Evaluator.scala +++ b/sjsonnet/src/sjsonnet/Evaluator.scala @@ -1,6 +1,6 @@ package sjsonnet -import Expr._ +import Expr.{Error => _, _} import fastparse.Parsed import sjsonnet.Expr.Member.Visibility object Evaluator { diff --git a/sjsonnet/src/sjsonnet/Format.scala b/sjsonnet/src/sjsonnet/Format.scala index d5d6d26f..f2698329 100644 --- a/sjsonnet/src/sjsonnet/Format.scala +++ b/sjsonnet/src/sjsonnet/Format.scala @@ -40,7 +40,7 @@ object Format{ } - def plain[_: P] = P( CharsWhile(_ != '%', min = 0).! ) + def plain[_: P] = P( CharsWhile(_ != '%', 0).! ) def format[_: P] = P( plain ~ (("%" ~/ formatSpec) ~ plain).rep ~ End) diff --git a/sjsonnet/src/sjsonnet/Materializer.scala b/sjsonnet/src/sjsonnet/Materializer.scala index daaf0fd3..f89892b1 100644 --- a/sjsonnet/src/sjsonnet/Materializer.scala +++ b/sjsonnet/src/sjsonnet/Materializer.scala @@ -9,25 +9,25 @@ object Materializer { extVars: Map[String, ujson.Js], wd: os.Path): Js = try { v match { - case Val.True => Js.True - case Val.False => Js.False - case Val.Null => Js.Null - case Val.Num(n) => Js.Num(n) - case Val.Str(s) => Js.Str(s) - case Val.Arr(xs) => Js.Arr.from(xs.map(x => apply(x.force, extVars, wd))) + case Val.True => ujson.True + case Val.False => ujson.False + case Val.Null => ujson.Null + case Val.Num(n) => ujson.Num(n) + case Val.Str(s) => ujson.Str(s) + case Val.Arr(xs) => ujson.Arr.from(xs.map(x => apply(x.force, extVars, wd))) case obj: Val.Obj => def rec(x: Val.Obj): Unit = { x.triggerAsserts(obj) x.`super` match { case Some(s) => rec(s) - case None => Unit + case None => () } } rec(obj) - Js.Obj.from( + ujson.Obj.from( for { (k, hidden) <- obj.getVisibleKeys().toSeq.sortBy(_._1) if !hidden @@ -40,14 +40,14 @@ object Materializer { throw new DelegateError("Stackoverflow while materializing, possibly due to recursive value") } - def reverse(v: Js.Value): Val = v match{ - case Js.True => Val.True - case Js.False => Val.False - case Js.Null => Val.Null - case Js.Num(n) => Val.Num(n) - case Js.Str(s) => Val.Str(s) - case Js.Arr(xs) => Val.Arr(xs.map(x => Lazy(reverse(x)))) - case Js.Obj(xs) => Val.Obj( + def reverse(v: ujson.Value): Val = v match{ + case ujson.True => Val.True + case ujson.False => Val.False + case ujson.Null => Val.Null + case ujson.Num(n) => Val.Num(n) + case ujson.Str(s) => Val.Str(s) + case ujson.Arr(xs) => Val.Arr(xs.map(x => Lazy(reverse(x))).toSeq) + case ujson.Obj(xs) => Val.Obj( xs.map(x => (x._1, Val.Obj.Member(false, Visibility.Normal, (_: Val.Obj, _: Option[Val.Obj], _) => Lazy(reverse(x._2))))).toMap, _ => (), None @@ -55,13 +55,13 @@ object Materializer { } def toExpr(v: ujson.Js): Expr = v match{ - case ujson.Js.True => Expr.True(0) - case ujson.Js.False => Expr.False(0) - case ujson.Js.Null => Expr.Null(0) - case ujson.Js.Num(n) => Expr.Num(0, n) - case ujson.Js.Str(s) => Expr.Str(0, s) - case ujson.Js.Arr(xs) => Expr.Arr(0, xs.map(toExpr)) - case ujson.Js.Obj(kvs) => + case ujson.True => Expr.True(0) + case ujson.False => Expr.False(0) + case ujson.Null => Expr.Null(0) + case ujson.Num(n) => Expr.Num(0, n) + case ujson.Str(s) => Expr.Str(0, s) + case ujson.Arr(xs) => Expr.Arr(0, xs.map(toExpr).toSeq) + case ujson.Obj(kvs) => Expr.Obj(0, ObjBody.MemberList( for((k, v) <- kvs.toSeq) diff --git a/sjsonnet/src/sjsonnet/Renderer.scala b/sjsonnet/src/sjsonnet/Renderer.scala index f94bdc3d..9e0fef80 100644 --- a/sjsonnet/src/sjsonnet/Renderer.scala +++ b/sjsonnet/src/sjsonnet/Renderer.scala @@ -2,8 +2,8 @@ package sjsonnet import java.io.StringWriter import java.util.regex.Pattern -import ujson.{ArrVisitor, BaseRenderer, ObjVisitor} - +import upickle.core.{ArrVisitor, ObjVisitor} +import ujson.BaseRenderer class PythonRenderer(out: StringWriter = new java.io.StringWriter(), indent: Int = -1) extends BaseRenderer(out, indent){ @@ -46,7 +46,7 @@ class PythonRenderer(out: StringWriter = new java.io.StringWriter(), class Renderer(out: StringWriter = new java.io.StringWriter(), indent: Int = -1) extends BaseRenderer(out, indent){ var newlineBuffered = false - override def visitNumRaw(d: Double, index: Int) = { + override def visitFloat64(d: Double, index: Int) = { flushBuffer() RenderUtils.renderDouble(out, d) out @@ -70,7 +70,7 @@ class Renderer(out: StringWriter = new java.io.StringWriter(), newlineBuffered = false commaBuffered = false } - override def visitArray(index: Int) = new ArrVisitor[StringWriter, StringWriter] { + override def visitArray(length: Int, index: Int) = new ArrVisitor[StringWriter, StringWriter] { var empty = true flushBuffer() out.append('[') @@ -95,19 +95,17 @@ class Renderer(out: StringWriter = new java.io.StringWriter(), } } - override def visitObject(index: Int) = new ObjVisitor[StringWriter, StringWriter] { + override def visitObject(length: Int, index: Int) = new ObjVisitor[StringWriter, StringWriter] { var empty = true flushBuffer() out.append('{') newlineBuffered = true depth += 1 def subVisitor = Renderer.this - def visitKey(s: CharSequence, index: Int): Unit = { + def visitKey(index: Int) = Renderer.this + def visitKeyValue(v: Any): Unit = { empty = false flushBuffer() - - ujson.Renderer.escape(out, s, true) - out.append(colonSnippet) } def visitValue(v: StringWriter, index: Int): Unit = { @@ -156,7 +154,7 @@ class YamlRenderer(out: StringWriter = new java.io.StringWriter(), indentArrayIn out } } - override def visitNumRaw(d: Double, index: Int) = { + override def visitFloat64(d: Double, index: Int) = { flushBuffer() RenderUtils.renderDouble(out, d) out @@ -183,7 +181,7 @@ class YamlRenderer(out: StringWriter = new java.io.StringWriter(), indentArrayIn newlineBuffered = false dashBuffered = false } - override def visitArray(index: Int) = new ArrVisitor[StringWriter, StringWriter] { + override def visitArray(length: Int, index: Int) = new ArrVisitor[StringWriter, StringWriter] { var empty = true flushBuffer() @@ -213,7 +211,7 @@ class YamlRenderer(out: StringWriter = new java.io.StringWriter(), indentArrayIn out } } - override def visitObject(index: Int) = new ObjVisitor[StringWriter, StringWriter] { + override def visitObject(length: Int, index: Int) = new ObjVisitor[StringWriter, StringWriter] { var empty = true flushBuffer() if (!topLevel) depth += 1 @@ -222,10 +220,10 @@ class YamlRenderer(out: StringWriter = new java.io.StringWriter(), indentArrayIn if (afterKey) newlineBuffered = true def subVisitor = YamlRenderer.this - def visitKey(s: CharSequence, index: Int): Unit = { + def visitKey(index: Int) = YamlRenderer.this + def visitKeyValue(s: Any): Unit = { empty = false flushBuffer() - ujson.Renderer.escape(out, s, true) out.append(colonSnippet) afterKey = true newlineBuffered = false @@ -257,4 +255,4 @@ object RenderUtils { else d.toString ) } -} \ No newline at end of file +} diff --git a/sjsonnet/src/sjsonnet/Std.scala b/sjsonnet/src/sjsonnet/Std.scala index 848b84e8..eb9e2f44 100644 --- a/sjsonnet/src/sjsonnet/Std.scala +++ b/sjsonnet/src/sjsonnet/Std.scala @@ -8,22 +8,23 @@ import sjsonnet.Expr.Params import sjsonnet.Scope.empty import scala.collection.mutable.ArrayBuffer +import scala.collection.compat._ object Std { sealed trait ReadWriter[T]{ - def apply(t: Val, extVars: Map[String, ujson.Js], wd: os.Path): Either[String, T] + def apply(t: Val, extVars: Map[String, ujson.Value], wd: os.Path): Either[String, T] def write(t: T): Val } object ReadWriter{ implicit object StringRead extends ReadWriter[String]{ - def apply(t: Val, extVars: Map[String, ujson.Js], wd: os.Path) = t match{ + def apply(t: Val, extVars: Map[String, ujson.Value], wd: os.Path) = t match{ case Val.Str(s) => Right(s) case _ => Left("String") } def write(t: String) = Val.Str(t) } implicit object BooleanRead extends ReadWriter[Boolean]{ - def apply(t: Val, extVars: Map[String, ujson.Js], wd: os.Path) = t match{ + def apply(t: Val, extVars: Map[String, ujson.Value], wd: os.Path) = t match{ case Val.True => Right(true) case Val.False => Right(false) case _ => Left("Boolean") @@ -31,39 +32,39 @@ object Std { def write(t: Boolean) = Val.bool(t) } implicit object IntRead extends ReadWriter[Int]{ - def apply(t: Val, extVars: Map[String, ujson.Js], wd: os.Path) = t match{ + def apply(t: Val, extVars: Map[String, ujson.Value], wd: os.Path) = t match{ case Val.Num(s) => Right(s.toInt) case _ => Left("Int") } def write(t: Int) = Val.Num(t) } implicit object DoubleRead extends ReadWriter[Double]{ - def apply(t: Val, extVars: Map[String, ujson.Js], wd: os.Path) = t match{ + def apply(t: Val, extVars: Map[String, ujson.Value], wd: os.Path) = t match{ case Val.Num(s) => Right(s) case _ => Left("Number") } def write(t: Double) = Val.Num(t) } implicit object ValRead extends ReadWriter[Val]{ - def apply(t: Val, extVars: Map[String, ujson.Js], wd: os.Path) = Right(t) + def apply(t: Val, extVars: Map[String, ujson.Value], wd: os.Path) = Right(t) def write(t: Val) = t } implicit object ObjRead extends ReadWriter[Val.Obj]{ - def apply(t: Val, extVars: Map[String, ujson.Js], wd: os.Path) = t match{ + def apply(t: Val, extVars: Map[String, ujson.Value], wd: os.Path) = t match{ case v: Val.Obj => Right(v) case _ => Left("Object") } def write(t: Val.Obj) = t } implicit object ArrRead extends ReadWriter[Val.Arr]{ - def apply(t: Val, extVars: Map[String, ujson.Js], wd: os.Path) = t match{ + def apply(t: Val, extVars: Map[String, ujson.Value], wd: os.Path) = t match{ case v: Val.Arr => Right(v) case _ => Left("Array") } def write(t: Val.Arr) = t } implicit object FuncRead extends ReadWriter[Val.Func]{ - def apply(t: Val, extVars: Map[String, ujson.Js], wd: os.Path) = t match{ + def apply(t: Val, extVars: Map[String, ujson.Value], wd: os.Path) = t match{ case v: Val.Func => Right(v) case _ => Left("Function") } @@ -71,18 +72,18 @@ object Std { } implicit object ApplyerRead extends ReadWriter[Applyer]{ - def apply(t: Val, extVars: Map[String, ujson.Js], wd: os.Path) = t match{ + def apply(t: Val, extVars: Map[String, ujson.Value], wd: os.Path) = t match{ case v: Val.Func => Right(Applyer(v, extVars, wd)) case _ => Left("Function") } def write(t: Applyer) = t.f } } - case class Applyer(f: Val.Func, extVars: Map[String, ujson.Js], wd: os.Path){ + case class Applyer(f: Val.Func, extVars: Map[String, ujson.Value], wd: os.Path){ def apply(args: Lazy*) = f.apply(args.map((None, _)), "(memory)", extVars, -1, wd) } - def validate(vs: Seq[Val], extVars: Map[String, ujson.Js], wd: os.Path, rs: Seq[ReadWriter[_]]) = { + def validate(vs: Seq[Val], extVars: Map[String, ujson.Value], wd: os.Path, rs: Seq[ReadWriter[_]]) = { for((v, r) <- vs.zip(rs)) yield r.apply(v, extVars, wd) match{ case Left(err) => throw new DelegateError("Wrong parameter type: expected " + err + ", got " + v.prettyName) case Right(x) => x @@ -90,23 +91,23 @@ object Std { } def builtin[R: ReadWriter, T1: ReadWriter](name: String, p1: String) - (eval: (os.Path, Map[String, ujson.Js], T1) => R): (String, Val.Func) = builtin0(name, p1){ (vs, extVars, wd) => + (eval: (os.Path, Map[String, ujson.Value], T1) => R): (String, Val.Func) = builtin0(name, p1){ (vs, extVars, wd) => val Seq(v: T1) = validate(vs, extVars, wd, Seq(implicitly[ReadWriter[T1]])) eval(wd, extVars, v) } def builtin[R: ReadWriter, T1: ReadWriter, T2: ReadWriter](name: String, p1: String, p2: String) - (eval: (os.Path, Map[String, ujson.Js], T1, T2) => R): (String, Val.Func) = builtin0(name, p1, p2){ (vs, extVars, wd) => + (eval: (os.Path, Map[String, ujson.Value], T1, T2) => R): (String, Val.Func) = builtin0(name, p1, p2){ (vs, extVars, wd) => val Seq(v1: T1, v2: T2) = validate(vs, extVars, wd, Seq(implicitly[ReadWriter[T1]], implicitly[ReadWriter[T2]])) eval(wd, extVars, v1, v2) } def builtin[R: ReadWriter, T1: ReadWriter, T2: ReadWriter, T3: ReadWriter](name: String, p1: String, p2: String, p3: String) - (eval: (os.Path, Map[String, ujson.Js], T1, T2, T3) => R): (String, Val.Func) = builtin0(name, p1, p2, p3){ (vs, extVars, wd) => + (eval: (os.Path, Map[String, ujson.Value], T1, T2, T3) => R): (String, Val.Func) = builtin0(name, p1, p2, p3){ (vs, extVars, wd) => val Seq(v1: T1, v2: T2, v3: T3) = validate(vs, extVars, wd, Seq(implicitly[ReadWriter[T1]], implicitly[ReadWriter[T2]], implicitly[ReadWriter[T3]])) eval(wd, extVars, v1, v2, v3) } - def builtin0[R: ReadWriter](name: String, params: String*)(eval: (Seq[Val], Map[String, ujson.Js], os.Path) => R) = { + def builtin0[R: ReadWriter](name: String, params: String*)(eval: (Seq[Val], Map[String, ujson.Value], os.Path) => R) = { name -> Val.Func( empty, Params(params.map(_ -> None)), @@ -118,7 +119,7 @@ object Std { * * Arguments of the eval function are (args, extVars, wd) */ - def builtinWithDefaults[R: ReadWriter](name: String, params: (String, Option[Expr])*)(eval: (Map[String, Val], Map[String, ujson.Js], os.Path) => R): (String, Val.Func) = { + def builtinWithDefaults[R: ReadWriter](name: String, params: (String, Option[Expr])*)(eval: (Map[String, Val], Map[String, ujson.Value], os.Path) => R): (String, Val.Func) = { name -> Val.Func( empty, Params(params), @@ -195,11 +196,11 @@ object Std { case _: Val.Str | Val.Null => // donothing case x => throw new DelegateError("Cannot call .lines on " + x.prettyName) } - Materializer.apply(v1, extVars, wd).asInstanceOf[ujson.Js.Arr] + Materializer.apply(v1, extVars, wd).asInstanceOf[ujson.Arr] .value - .filter(_ != ujson.Js.Null) + .filter(_ != ujson.Null) .map{ - case ujson.Js.Str(s) => s + "\n" + case ujson.Str(s) => s + "\n" case _ => ??? /* we ensure it's all strings above */ } .mkString @@ -229,17 +230,17 @@ object Std { ) }, builtin("mergePatch", "target", "patch"){ (wd, extVars, target: Val, patch: Val) => - def rec(l: ujson.Js, r: ujson.Js): ujson.Js = { + def rec(l: ujson.Value, r: ujson.Value): ujson.Value = { (l, r) match{ - case (l0, r: ujson.Js.Obj) => + case (l0, r: ujson.Obj) => val l = l0 match{ - case l: ujson.Js.Obj => l - case _ => ujson.Js.Obj() + case l: ujson.Obj => l + case _ => ujson.Obj() } for((k, v) <- r.value){ - if (v == ujson.Js.Null) l.value.remove(k) + if (v == ujson.Null) l.value.remove(k) else if (l.value.contains(k)) l(k) = rec(l(k), r(k)) - else l(k) = rec(ujson.Js.Obj(), r(k)) + else l(k) = rec(ujson.Obj(), r(k)) } l case (_, _) => r @@ -404,7 +405,7 @@ object Std { indices.append(matchIndex) matchIndex = str.indexOf(pat, matchIndex + 1) } - Val.Arr(indices.map(x => Lazy(Val.Num(x)))) + Val.Arr(indices.map(x => Lazy(Val.Num(x))).toSeq) } }, builtin("substr", "s", "from", "len"){ (wd, extVars, s: String, from: Int, len: Int) => { @@ -450,7 +451,7 @@ object Std { case x => throw new DelegateError("Cannot join " + x.prettyName) } } - Val.Arr(out) + Val.Arr(out.toSeq) case x => throw new DelegateError("Cannot join " + x.prettyName) } res @@ -464,24 +465,24 @@ object Std { case x => throw new DelegateError("Cannot call flattenArrays on " + x) } } - Val.Arr(out) + Val.Arr(out.toSeq) }, builtin("manifestIni", "v"){ (wd, extVars, v: Val) => val materialized = Materializer(v, extVars, wd) - def sect(x: ujson.Js.Obj) = { + def sect(x: ujson.Obj) = { x.value.flatMap{ - case (k, ujson.Js.Str(v)) => Seq(k + " = " + v) - case (k, ujson.Js.Arr(vs)) => + case (k, ujson.Str(v)) => Seq(k + " = " + v) + case (k, ujson.Arr(vs)) => vs.map{ - case ujson.Js.Str(v) => k + " = " + v + case ujson.Str(v) => k + " = " + v case x => throw new DelegateError("Cannot call manifestIni on " + x.getClass) } case (k, x) => throw new DelegateError("Cannot call manifestIni on " + x.getClass) } } - val lines = materialized.obj.get("main").fold(Iterable[String]())(x => sect(x.asInstanceOf[ujson.Js.Obj])) ++ + val lines = materialized.obj.get("main").fold(Iterable[String]())(x => sect(x.asInstanceOf[ujson.Obj])) ++ materialized.obj.get("sections").fold(Iterable[String]())(x => - x.obj.flatMap{case (k, v) => Seq("[" + k + "]") ++ sect(v.asInstanceOf[ujson.Js.Obj])} + x.obj.flatMap{case (k, v) => Seq("[" + k + "]") ++ sect(v.asInstanceOf[ujson.Obj])} ) lines.flatMap(Seq(_, "\n")).mkString }, @@ -539,19 +540,19 @@ object Std { import scalatags.Text.all.{value => _, _} - def rec(v: ujson.Js): Frag = { + def rec(v: ujson.Value): Frag = { v match { - case ujson.Js.Str(s) => s - case ujson.Js.Arr(Seq(ujson.Js.Str(t), attrs: ujson.Js.Obj, children@_*)) => + case ujson.Str(s) => s + case ujson.Arr(collection.mutable.Seq(ujson.Str(t), attrs: ujson.Obj, children@_*)) => tag(t)( attrs.value.map { - case (k, ujson.Js.Str(v)) => attr(k) := v + case (k, ujson.Str(v)) => attr(k) := v case (k, v) => throw new DelegateError("Cannot call manifestXmlJsonml on " + v.getClass) }.toSeq, children.map(rec) ) - case ujson.Js.Arr(Seq(ujson.Js.Str(t), children@_*)) => - tag(t)(children.map(rec)) + case ujson.Arr(collection.mutable.Seq(ujson.Str(t), children@_*)) => + tag(t)(children.map(rec).toSeq) case x => throw new DelegateError("Cannot call manifestXmlJsonml on " + x.getClass) } @@ -592,98 +593,98 @@ object Std { } }, builtin("uniq", "arr"){ (wd, extVars, arr: Val.Arr) => - val ujson.Js.Arr(vs) = Materializer(arr, extVars, wd) - val out = collection.mutable.Buffer.empty[ujson.Js] + val ujson.Arr(vs) = Materializer(arr, extVars, wd) + val out = collection.mutable.Buffer.empty[ujson.Value] for(v <- vs) if (out.isEmpty || out.last != v) out.append(v) - Val.Arr(out.map(v => Lazy(Materializer.reverse(v)))) + Val.Arr(out.map(v => Lazy(Materializer.reverse(v))).toSeq) }, builtin("set", "arr"){ (wd, extVars, arr: Val.Arr) => - val ujson.Js.Arr(vs0) = Materializer(arr, extVars, wd) + val ujson.Arr(vs0) = Materializer(arr, extVars, wd) val vs = - if (vs0.forall(_.isInstanceOf[ujson.Js.Str])){ - vs0.map(_.asInstanceOf[ujson.Js.Str]).sortBy(_.value) - }else if (vs0.forall(_.isInstanceOf[ujson.Js.Num])){ - vs0.map(_.asInstanceOf[ujson.Js.Num]).sortBy(_.value) + if (vs0.forall(_.isInstanceOf[ujson.Str])){ + vs0.map(_.asInstanceOf[ujson.Str]).sortBy(_.value) + }else if (vs0.forall(_.isInstanceOf[ujson.Num])){ + vs0.map(_.asInstanceOf[ujson.Num]).sortBy(_.value) }else { throw new DelegateError("Every element of the input must be of the same type, string or number") } - val out = collection.mutable.Buffer.empty[ujson.Js] + val out = collection.mutable.Buffer.empty[ujson.Value] for(v <- vs) if (out.isEmpty || out.last != v) out.append(v) - Val.Arr(out.map(v => Lazy(Materializer.reverse(v)))) + Val.Arr(out.map(v => Lazy(Materializer.reverse(v))).toSeq) }, builtin("setUnion", "a", "b"){ (wd, extVars, a: Val.Arr, b: Val.Arr) => - val ujson.Js.Arr(vs1) = Materializer(a, extVars, wd) - val ujson.Js.Arr(vs2) = Materializer(b, extVars, wd) + val ujson.Arr(vs1) = Materializer(a, extVars, wd) + val ujson.Arr(vs2) = Materializer(b, extVars, wd) val vs0 = vs1 ++ vs2 val vs = - if (vs0.forall(_.isInstanceOf[ujson.Js.Str])){ - vs0.map(_.asInstanceOf[ujson.Js.Str]).sortBy(_.value) - }else if (vs0.forall(_.isInstanceOf[ujson.Js.Num])){ - vs0.map(_.asInstanceOf[ujson.Js.Num]).sortBy(_.value) + if (vs0.forall(_.isInstanceOf[ujson.Str])){ + vs0.map(_.asInstanceOf[ujson.Str]).sortBy(_.value) + }else if (vs0.forall(_.isInstanceOf[ujson.Num])){ + vs0.map(_.asInstanceOf[ujson.Num]).sortBy(_.value) }else { throw new DelegateError("Every element of the input must be of the same type, string or number") } - val out = collection.mutable.Buffer.empty[ujson.Js] + val out = collection.mutable.Buffer.empty[ujson.Value] for(v <- vs) if (out.isEmpty || out.last != v) out.append(v) - Val.Arr(out.map(v => Lazy(Materializer.reverse(v)))) + Val.Arr(out.map(v => Lazy(Materializer.reverse(v))).toSeq) }, builtin("setInter", "a", "b"){ (wd, extVars, a: Val, b: Val.Arr) => val vs1 = Materializer(a, extVars, wd) match{ - case ujson.Js.Arr(vs1) => vs1 + case ujson.Arr(vs1) => vs1 case x => Seq(x) } - val ujson.Js.Arr(vs2) = Materializer(b, extVars, wd) + val ujson.Arr(vs2) = Materializer(b, extVars, wd) - val vs0 = vs1.to[collection.mutable.LinkedHashSet] - .intersect(vs2.to[collection.mutable.LinkedHashSet]) + val vs0 = vs1.to(collection.mutable.LinkedHashSet) + .intersect(vs2.to(collection.mutable.LinkedHashSet)) .toSeq val vs = - if (vs0.forall(_.isInstanceOf[ujson.Js.Str])){ - vs0.map(_.asInstanceOf[ujson.Js.Str]).sortBy(_.value) - }else if (vs0.forall(_.isInstanceOf[ujson.Js.Num])){ - vs0.map(_.asInstanceOf[ujson.Js.Num]).sortBy(_.value) + if (vs0.forall(_.isInstanceOf[ujson.Str])){ + vs0.map(_.asInstanceOf[ujson.Str]).sortBy(_.value) + }else if (vs0.forall(_.isInstanceOf[ujson.Num])){ + vs0.map(_.asInstanceOf[ujson.Num]).sortBy(_.value) }else { throw new DelegateError("Every element of the input must be of the same type, string or number") } - val out = collection.mutable.Buffer.empty[ujson.Js] + val out = collection.mutable.Buffer.empty[ujson.Value] for(v <- vs) if (out.isEmpty || out.last != v) out.append(v) - Val.Arr(out.map(v => Lazy(Materializer.reverse(v)))) + Val.Arr(out.map(v => Lazy(Materializer.reverse(v))).toSeq) }, builtin("setDiff", "a", "b"){ (wd, extVars, a: Val.Arr, b: Val.Arr) => - val ujson.Js.Arr(vs1) = Materializer(a, extVars, wd) - val ujson.Js.Arr(vs2) = Materializer(b, extVars, wd) + val ujson.Arr(vs1) = Materializer(a, extVars, wd) + val ujson.Arr(vs2) = Materializer(b, extVars, wd) - val vs0 = vs1.to[collection.mutable.LinkedHashSet] - .diff(vs2.to[collection.mutable.LinkedHashSet]) + val vs0 = vs1.to(collection.mutable.LinkedHashSet) + .diff(vs2.to(collection.mutable.LinkedHashSet)) .toSeq val vs = - if (vs0.forall(_.isInstanceOf[ujson.Js.Str])){ - vs0.map(_.asInstanceOf[ujson.Js.Str]).sortBy(_.value) - }else if (vs0.forall(_.isInstanceOf[ujson.Js.Num])){ - vs0.map(_.asInstanceOf[ujson.Js.Num]).sortBy(_.value) + if (vs0.forall(_.isInstanceOf[ujson.Str])){ + vs0.map(_.asInstanceOf[ujson.Str]).sortBy(_.value) + }else if (vs0.forall(_.isInstanceOf[ujson.Num])){ + vs0.map(_.asInstanceOf[ujson.Num]).sortBy(_.value) }else { throw new DelegateError("Every element of the input must be of the same type, string or number") } - val out = collection.mutable.Buffer.empty[ujson.Js] + val out = collection.mutable.Buffer.empty[ujson.Value] for(v <- vs) if (out.isEmpty || out.last != v) out.append(v) - Val.Arr(out.map(v => Lazy(Materializer.reverse(v)))) + Val.Arr(out.map(v => Lazy(Materializer.reverse(v))).toSeq) }, builtin("setMember", "x", "arr"){ (wd, extVars, x: Val, arr: Val.Arr) => val vs1 = Materializer(x, extVars, wd) - val ujson.Js.Arr(vs2) = Materializer(arr, extVars, wd) + val ujson.Arr(vs2) = Materializer(arr, extVars, wd) vs2.contains(vs1) }, builtin("split", "str", "c"){ (wd, extVars, str: String, c: String) => @@ -701,7 +702,7 @@ object Std { output.append(new String(Character.toChars(codepoint))) offset += Character.charCount(codepoint) } - Val.Arr(output.map(s => Lazy(Val.Str(s)))) + Val.Arr(output.map(s => Lazy(Val.Str(s))).toSeq) }, builtin("parseInt", "str"){ (wd, extVars, str: String) => @@ -715,17 +716,17 @@ object Std { }, builtin("parseJson", "str") { (wd, extVars, str: String) => - def recursiveTransform(js: ujson.Js): Val = { + def recursiveTransform(js: ujson.Value): Val = { js match { - case ujson.Js.Null => Val.Null - case ujson.Js.True => Val.True - case ujson.Js.False => Val.False - case ujson.Js.Num(value) => Val.Num(value) - case ujson.Js.Str(value) => Val.Str(value) - case ujson.Js.Arr(values) => - val transformedValue: Seq[Lazy] = values.map( v => Lazy(recursiveTransform(v))) + case ujson.Null => Val.Null + case ujson.True => Val.True + case ujson.False => Val.False + case ujson.Num(value) => Val.Num(value) + case ujson.Str(value) => Val.Str(value) + case ujson.Arr(values) => + val transformedValue: Seq[Lazy] = values.map(v => Lazy(recursiveTransform(v))).toSeq Val.Arr(transformedValue) - case ujson.Js.Obj(valueMap) => + case ujson.Obj(valueMap) => val transformedValue = valueMap .mapValues { v => Val.Obj.Member(false, Expr.Member.Visibility.Normal, (_, _ ,_) => Lazy(recursiveTransform(v)))