diff --git a/.github/workflows/pr-build.yaml b/.github/workflows/pr-build.yaml index ecb801b7..d6f0adf3 100644 --- a/.github/workflows/pr-build.yaml +++ b/.github/workflows/pr-build.yaml @@ -22,7 +22,11 @@ jobs: distribution: 'adopt' - name: Run mill tests run: ./mill __.test - - name: Compile with sbt + - name: Compile Scala 2.13 with sbt + run: sbt ++2.13 compile bench/compile bench/jmh:compile + - name: Compile Scala 2.13 with sbt run: sbt compile bench/compile bench/jmh:compile - - name: Run sbt tests + - name: Run sbt tests (Scala 2.13) + run: sbt ++2.13 test + - name: Run sbt tests (Scala 3) run: sbt test diff --git a/sjsonnet/src/sjsonnet/BaseCharRenderer.scala b/sjsonnet/src/sjsonnet/BaseCharRenderer.scala index 5cec5045..9c5f419a 100644 --- a/sjsonnet/src/sjsonnet/BaseCharRenderer.scala +++ b/sjsonnet/src/sjsonnet/BaseCharRenderer.scala @@ -28,17 +28,21 @@ class BaseCharRenderer[T <: upickle.core.CharOps.Output] renderIndent() } } - def visitArray(length: Int, index: Int) = new ArrVisitor[T, T] { + + def visitArray(length: Int, index: Int): ArrVisitor[T, T] = new ArrVisitor[T, T] { flushBuffer() elemBuilder.append('[') depth += 1 renderIndent() - def subVisitor = BaseCharRenderer.this + + def subVisitor: BaseCharRenderer[T] = BaseCharRenderer.this + def visitValue(v: T, index: Int): Unit = { flushBuffer() commaBuffered = true } + def visitEnd(index: Int) = { commaBuffered = false depth -= 1 @@ -49,20 +53,25 @@ class BaseCharRenderer[T <: upickle.core.CharOps.Output] } } - def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[T, T] { + def visitJsonableObject(length: Int, index: Int): ObjVisitor[T, T] = new ObjVisitor[T, T] { flushBuffer() elemBuilder.append('{') depth += 1 renderIndent() - def subVisitor = BaseCharRenderer.this - def visitKey(index: Int) = BaseCharRenderer.this + + def subVisitor: BaseCharRenderer[T] = BaseCharRenderer.this + + def visitKey(index: Int): BaseCharRenderer[T] = BaseCharRenderer.this + def visitKeyValue(s: Any): Unit = { elemBuilder.append(':') if (indent != -1) elemBuilder.append(' ') } + def visitValue(v: T, index: Int): Unit = { commaBuffered = true } + def visitEnd(index: Int) = { commaBuffered = false depth -= 1 diff --git a/sjsonnet/src/sjsonnet/BaseRenderer.scala b/sjsonnet/src/sjsonnet/BaseRenderer.scala index dca22588..9b52be5f 100644 --- a/sjsonnet/src/sjsonnet/BaseRenderer.scala +++ b/sjsonnet/src/sjsonnet/BaseRenderer.scala @@ -27,17 +27,21 @@ class BaseRenderer[T <: java.io.Writer] renderIndent() } } - def visitArray(length: Int, index: Int) = new ArrVisitor[T, T] { + + def visitArray(length: Int, index: Int): ArrVisitor[T, T] = new ArrVisitor[T, T] { flushBuffer() out.append('[') depth += 1 renderIndent() - def subVisitor = BaseRenderer.this + + def subVisitor: BaseRenderer[T] = BaseRenderer.this + def visitValue(v: T, index: Int): Unit = { flushBuffer() commaBuffered = true } + def visitEnd(index: Int) = { commaBuffered = false depth -= 1 @@ -47,17 +51,22 @@ class BaseRenderer[T <: java.io.Writer] } } - def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[T, T] { + def visitJsonableObject(length: Int, index: Int): ObjVisitor[T, T] = new ObjVisitor[T, T] { flushBuffer() out.append('{') depth += 1 renderIndent() - def subVisitor = BaseRenderer.this - def visitKey(index: Int) = BaseRenderer.this + + def subVisitor: BaseRenderer[T] = BaseRenderer.this + + def visitKey(index: Int): BaseRenderer[T] = BaseRenderer.this + def visitKeyValue(s: Any): Unit = out.append(colonSnippet) + def visitValue(v: T, index: Int): Unit = { commaBuffered = true } + def visitEnd(index: Int) = { commaBuffered = false depth -= 1 diff --git a/sjsonnet/src/sjsonnet/Error.scala b/sjsonnet/src/sjsonnet/Error.scala index f080f7d2..cb6ef569 100644 --- a/sjsonnet/src/sjsonnet/Error.scala +++ b/sjsonnet/src/sjsonnet/Error.scala @@ -78,7 +78,7 @@ class ParseError(msg: String, stack: List[Error.Frame] = Nil, underlying: Option extends Error(msg, stack, underlying) { override protected def copy(msg: String = msg, stack: List[Error.Frame] = stack, - underlying: Option[Throwable] = underlying) = + underlying: Option[Throwable] = underlying): ParseError = new ParseError(msg, stack, underlying) } @@ -86,7 +86,7 @@ class StaticError(msg: String, stack: List[Error.Frame] = Nil, underlying: Optio extends Error(msg, stack, underlying) { override protected def copy(msg: String = msg, stack: List[Error.Frame] = stack, - underlying: Option[Throwable] = underlying) = + underlying: Option[Throwable] = underlying): StaticError = new StaticError(msg, stack, underlying) } diff --git a/sjsonnet/src/sjsonnet/Evaluator.scala b/sjsonnet/src/sjsonnet/Evaluator.scala index 28550791..859eb3f1 100644 --- a/sjsonnet/src/sjsonnet/Evaluator.scala +++ b/sjsonnet/src/sjsonnet/Evaluator.scala @@ -502,18 +502,18 @@ class Evaluator(resolver: CachedResolver, def visitMemberList(objPos: Position, e: ObjBody.MemberList, sup: Val.Obj)(implicit scope: ValScope): Val.Obj = { val asserts = e.asserts val fields = e.fields - var cachedSimpleScope: ValScope | Null = null + var cachedSimpleScope: Option[ValScope] = None var cachedObj: Val.Obj = null var asserting: Boolean = false def makeNewScope(self: Val.Obj, sup: Val.Obj): ValScope = { if((sup eq null) && (self eq cachedObj)) { cachedSimpleScope match { - case null => + case None => val cachedScope = createNewScope(self, sup) - cachedSimpleScope = cachedScope + cachedSimpleScope = Some(cachedScope) cachedScope - case cachedScope: ValScope => + case Some(cachedScope) => cachedScope } } else createNewScope(self, sup) diff --git a/sjsonnet/src/sjsonnet/Format.scala b/sjsonnet/src/sjsonnet/Format.scala index 6d742974..134e82d5 100644 --- a/sjsonnet/src/sjsonnet/Format.scala +++ b/sjsonnet/src/sjsonnet/Format.scala @@ -46,7 +46,7 @@ object Format{ def plain[A: P] = P( CharsWhile(_ != '%', 0).! ) - def format[A: P] = P( plain ~ (("%" ~/ formatSpec) ~ plain).rep ~ End) + def format0[A: P] = P( plain ~ (("%" ~/ formatSpec) ~ plain).rep ~ End) @@ -81,7 +81,7 @@ object Format{ values0: Val, pos: Position) (implicit evaluator: EvalScope): String = { - val (leading, chunks) = fastparse.parse(s, format).get.value + val (leading, chunks) = fastparse.parse(s, format0(using _)).get.value format(leading, chunks, values0, pos) } @@ -257,7 +257,7 @@ object Format{ } class PartialApplyFmt(fmt: String) extends Val.Builtin1("values") { - val (leading, chunks) = fastparse.parse(fmt, format).get.value + val (leading, chunks) = fastparse.parse(fmt, format0(using _)).get.value def evalRhs(values0: Val, ev: EvalScope, pos: Position): Val = Val.Str(pos, format(leading, chunks, values0, pos)(ev)) } diff --git a/sjsonnet/src/sjsonnet/PrettyYamlRenderer.scala b/sjsonnet/src/sjsonnet/PrettyYamlRenderer.scala index fb89aa25..076f98fd 100644 --- a/sjsonnet/src/sjsonnet/PrettyYamlRenderer.scala +++ b/sjsonnet/src/sjsonnet/PrettyYamlRenderer.scala @@ -138,18 +138,20 @@ class PrettyYamlRenderer(out: Writer = new java.io.StringWriter(), newlineBuffered = false dashBuffered = false } - override def visitArray(length: Int, index: Int) = new ArrVisitor[Writer, Writer] { + + override def visitArray(length: Int, index: Int): ArrVisitor[Writer, Writer] = new ArrVisitor[Writer, Writer] { var empty = true val dedentInObject = afterKey && !indentArrayInObject - def subVisitor = { - if (empty){ + + def subVisitor: PrettyYamlRenderer = { + if (empty) { afterColon = false flushBuffer() val outerFirstElementInArray = firstElementInArray firstElementInArray = true if (!topLevel) { depth += 1 - if (!firstElementInArray || !outerFirstElementInArray) newlineBuffered = true + if (!firstElementInArray || !outerFirstElementInArray) newlineBuffered = true } topLevel = false @@ -161,6 +163,7 @@ class PrettyYamlRenderer(out: Writer = new java.io.StringWriter(), leftHandPrefixOffset = 0 PrettyYamlRenderer.this } + def visitValue(v: Writer, index: Int): Unit = { firstElementInArray = true empty = false @@ -169,6 +172,7 @@ class PrettyYamlRenderer(out: Writer = new java.io.StringWriter(), dashBuffered = true } + def visitEnd(index: Int) = { firstElementInArray = false if (!dedentInObject) depth -= 1 @@ -182,16 +186,19 @@ class PrettyYamlRenderer(out: Writer = new java.io.StringWriter(), out } } - override def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[Writer, Writer] { + + override def visitJsonableObject(length: Int, index: Int): ObjVisitor[Writer, Writer] = new ObjVisitor[Writer, Writer] { firstElementInArray = false var empty = true flushBuffer() if (!topLevel) depth += 1 topLevel = false - def subVisitor = PrettyYamlRenderer.this - def visitKey(index: Int) = { - if (empty){ + def subVisitor: PrettyYamlRenderer = PrettyYamlRenderer.this + + def visitKey(index: Int): PrettyYamlRenderer = { + + if (empty) { leftHandPrefixOffset = 0 afterColon = false @@ -200,12 +207,13 @@ class PrettyYamlRenderer(out: Writer = new java.io.StringWriter(), } PrettyYamlRenderer.this } + def visitKeyValue(s: Any): Unit = { empty = false flushBuffer() out.append(":") saveCurrentPos() - if (bufferedComment != null){ + if (bufferedComment != null) { out.append(bufferedComment) bufferedComment = null } @@ -213,10 +221,12 @@ class PrettyYamlRenderer(out: Writer = new java.io.StringWriter(), afterColon = true newlineBuffered = false } + def visitValue(v: Writer, index: Int): Unit = { newlineBuffered = true afterKey = false } + def visitEnd(index: Int) = { if (empty) { addSpaceAfterColon() @@ -473,7 +483,7 @@ object PrettyYamlRenderer{ yamlPunctuation | (&(CharIn(".0-9\\-")) ~ (yamlTime | yamlDate | yamlNumber) | yamlKeyword) ~ End ) - fastparse.parse(str, parser).isSuccess || + fastparse.parse(str, parser(using _)).isSuccess || str.contains(": ") || // Looks like a key-value pair str.contains(" #") || // Comments str.charAt(str.length - 1) == ':' || // Looks like a key-value pair diff --git a/sjsonnet/src/sjsonnet/ReadWriter.scala b/sjsonnet/src/sjsonnet/ReadWriter.scala index d7667bea..01e109a9 100644 --- a/sjsonnet/src/sjsonnet/ReadWriter.scala +++ b/sjsonnet/src/sjsonnet/ReadWriter.scala @@ -10,34 +10,34 @@ sealed abstract class ReadWriter[T] { object ReadWriter{ implicit object StringRead extends ReadWriter[String]{ def apply(t: Val) = t.asString - def write(pos: Position, t: String) = Val.Str(pos, t) + def write(pos: Position, t: String): Val.Str = Val.Str(pos, t) } implicit object BooleanRead extends ReadWriter[Boolean]{ def apply(t: Val) = t.asBoolean - def write(pos: Position, t: Boolean) = Val.bool(pos, t) + def write(pos: Position, t: Boolean): Val.Bool = Val.bool(pos, t) } implicit object IntRead extends ReadWriter[Int]{ def apply(t: Val) = t.asInt - def write(pos: Position, t: Int) = Val.Num(pos, t) + def write(pos: Position, t: Int): Val.Num = Val.Num(pos, t) } implicit object DoubleRead extends ReadWriter[Double]{ def apply(t: Val) = t.asDouble - def write(pos: Position, t: Double) = Val.Num(pos, t) + def write(pos: Position, t: Double): Val.Num = Val.Num(pos, t) } implicit object ValRead extends ReadWriter[Val]{ def apply(t: Val) = t - def write(pos: Position, t: Val) = t + def write(pos: Position, t: Val): Val = t } implicit object ObjRead extends ReadWriter[Val.Obj]{ def apply(t: Val) = t.asObj - def write(pos: Position, t: Val.Obj) = t + def write(pos: Position, t: Val.Obj): Val.Obj = t } implicit object ArrRead extends ReadWriter[Val.Arr]{ def apply(t: Val) = t.asArr - def write(pos: Position, t: Val.Arr) = t + def write(pos: Position, t: Val.Arr): Val.Arr = t } implicit object FuncRead extends ReadWriter[Val.Func]{ def apply(t: Val) = t.asFunc - def write(pos: Position, t: Val.Func) = t + def write(pos: Position, t: Val.Func): Val.Func = t } } diff --git a/sjsonnet/src/sjsonnet/Renderer.scala b/sjsonnet/src/sjsonnet/Renderer.scala index df9ab922..c3636408 100644 --- a/sjsonnet/src/sjsonnet/Renderer.scala +++ b/sjsonnet/src/sjsonnet/Renderer.scala @@ -46,19 +46,23 @@ class Renderer(out: Writer = new java.io.StringWriter(), newlineBuffered = false commaBuffered = false } - override def visitArray(length: Int, index: Int) = new ArrVisitor[Writer, Writer] { + + override def visitArray(length: Int, index: Int): ArrVisitor[Writer, Writer] = new ArrVisitor[Writer, Writer] { var empty = true flushBuffer() elemBuilder.append('[') newlineBuffered = true depth += 1 - def subVisitor = Renderer.this + + def subVisitor: Renderer = Renderer.this + def visitValue(v: Writer, index: Int): Unit = { empty = false flushBuffer() commaBuffered = true } + def visitEnd(index: Int) = { commaBuffered = false newlineBuffered = false @@ -72,23 +76,28 @@ class Renderer(out: Writer = new java.io.StringWriter(), } } - override def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[Writer, Writer] { + override def visitJsonableObject(length: Int, index: Int): ObjVisitor[Writer, Writer] = new ObjVisitor[Writer, Writer] { var empty = true flushBuffer() elemBuilder.append('{') newlineBuffered = true depth += 1 - def subVisitor = Renderer.this - def visitKey(index: Int) = Renderer.this + + def subVisitor: Renderer = Renderer.this + + def visitKey(index: Int): Renderer = Renderer.this + def visitKeyValue(v: Any): Unit = { empty = false //flushBuffer() elemBuilder.append(':') elemBuilder.append(' ') } + def visitValue(v: Writer, index: Int): Unit = { commaBuffered = true } + def visitEnd(index: Int) = { commaBuffered = false newlineBuffered = false @@ -141,21 +150,26 @@ class PythonRenderer(out: Writer = new java.io.StringWriter(), out } - override def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[Writer, Writer] { + override def visitJsonableObject(length: Int, index: Int): ObjVisitor[Writer, Writer] = new ObjVisitor[Writer, Writer] { flushBuffer() elemBuilder.append('{') depth += 1 renderIndent() - def subVisitor = PythonRenderer.this - def visitKey(index: Int) = PythonRenderer.this + + def subVisitor: PythonRenderer = PythonRenderer.this + + def visitKey(index: Int): PythonRenderer = PythonRenderer.this + def visitKeyValue(s: Any): Unit = { elemBuilder.ensureLength(2) elemBuilder.append(':') elemBuilder.append(' ') } + def visitValue(v: Writer, index: Int): Unit = { commaBuffered = true } + def visitEnd(index: Int) = { commaBuffered = false depth -= 1 @@ -181,18 +195,21 @@ class PythonRenderer(out: Writer = new java.io.StringWriter(), case class MaterializeJsonRenderer(indent: Int = 4, escapeUnicode: Boolean = false, out: StringWriter = new StringWriter()) extends BaseCharRenderer(out, indent, escapeUnicode) { - override def visitArray(length: Int, index: Int) = new ArrVisitor[StringWriter, StringWriter] { + override def visitArray(length: Int, index: Int): ArrVisitor[StringWriter, StringWriter] = new ArrVisitor[StringWriter, StringWriter] { flushBuffer() elemBuilder.append('[') depth += 1 // account for rendering differences of whitespaces in ujson and jsonnet manifestJson - if(length == 0) elemBuilder.append('\n') else renderIndent() - def subVisitor = MaterializeJsonRenderer.this + if (length == 0) elemBuilder.append('\n') else renderIndent() + + def subVisitor: MaterializeJsonRenderer = MaterializeJsonRenderer.this + def visitValue(v: StringWriter, index: Int): Unit = { flushBuffer() commaBuffered = true } + def visitEnd(index: Int) = { commaBuffered = false depth -= 1 @@ -203,21 +220,26 @@ case class MaterializeJsonRenderer(indent: Int = 4, escapeUnicode: Boolean = fal } } - override def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[StringWriter, StringWriter] { + override def visitJsonableObject(length: Int, index: Int): ObjVisitor[StringWriter, StringWriter] = new ObjVisitor[StringWriter, StringWriter] { flushBuffer() elemBuilder.append('{') depth += 1 // account for rendering differences of whitespaces in ujson and jsonnet manifestJson - if(length == 0) elemBuilder.append('\n') else renderIndent() - def subVisitor = MaterializeJsonRenderer.this - def visitKey(index: Int) = MaterializeJsonRenderer.this + if (length == 0) elemBuilder.append('\n') else renderIndent() + + def subVisitor: MaterializeJsonRenderer = MaterializeJsonRenderer.this + + def visitKey(index: Int): MaterializeJsonRenderer = MaterializeJsonRenderer.this + def visitKeyValue(s: Any): Unit = { elemBuilder.append(':') if (indent != -1) elemBuilder.append(' ') } + def visitValue(v: StringWriter, index: Int): Unit = { commaBuffered = true } + def visitEnd(index: Int) = { commaBuffered = false depth -= 1 diff --git a/sjsonnet/src/sjsonnet/Std.scala b/sjsonnet/src/sjsonnet/Std.scala index 19a97a0f..097a702a 100644 --- a/sjsonnet/src/sjsonnet/Std.scala +++ b/sjsonnet/src/sjsonnet/Std.scala @@ -1272,7 +1272,7 @@ class Std { Val.Str(self.pos, fs.currentFile.relativeToString(ev.wd)) } ) - )* + ): _* ) def builtin[R: ReadWriter, T1: ReadWriter](name: String, p1: String) diff --git a/sjsonnet/src/sjsonnet/ValVisitor.scala b/sjsonnet/src/sjsonnet/ValVisitor.scala index e6af5a66..2f2e68ca 100644 --- a/sjsonnet/src/sjsonnet/ValVisitor.scala +++ b/sjsonnet/src/sjsonnet/ValVisitor.scala @@ -21,7 +21,7 @@ class ValVisitor(pos: Position) extends JsVisitor[Val, Val] { self => val allKeys = new util.LinkedHashMap[String, java.lang.Boolean] var key: String = null def subVisitor: Visitor[?, ?] = self - def visitKey(index: Int) = upickle.core.StringVisitor + def visitKey(index: Int): Visitor[?, ?] = upickle.core.StringVisitor def visitKeyValue(s: Any): Unit = key = s.toString def visitValue(v: Val, index: Int): Unit = { cache.put(key, v) diff --git a/sjsonnet/src/sjsonnet/YamlRenderer.scala b/sjsonnet/src/sjsonnet/YamlRenderer.scala index 1f6945e8..ae55600a 100644 --- a/sjsonnet/src/sjsonnet/YamlRenderer.scala +++ b/sjsonnet/src/sjsonnet/YamlRenderer.scala @@ -8,7 +8,7 @@ import upickle.core.{ArrVisitor, ObjVisitor} class YamlRenderer(_out: StringWriter = new java.io.StringWriter(), indentArrayInObject: Boolean = false, - indent: Int = 2) extends BaseCharRenderer(_out, indent){ + indent: Int = 2) extends BaseCharRenderer[StringWriter](_out, indent){ var newlineBuffered = false var dashBuffered = false var afterKey = false @@ -81,7 +81,7 @@ class YamlRenderer(_out: StringWriter = new java.io.StringWriter(), indentArrayI dashBuffered = false } - override def visitArray(length: Int, index: Int) = new ArrVisitor[StringWriter, StringWriter] { + override def visitArray(length: Int, index: Int): ArrVisitor[StringWriter, StringWriter] = new ArrVisitor[StringWriter, StringWriter] { var empty = true flushBuffer() @@ -96,13 +96,15 @@ class YamlRenderer(_out: StringWriter = new java.io.StringWriter(), indentArrayI if (dedentInObject) depth -= 1 dashBuffered = true - def subVisitor = YamlRenderer.this + def subVisitor: YamlRenderer = YamlRenderer.this + def visitValue(v: StringWriter, index: Int): Unit = { empty = false flushBuffer() newlineBuffered = true dashBuffered = true } + def visitEnd(index: Int) = { if (!dedentInObject) depth -= 1 if (empty) { @@ -116,7 +118,8 @@ class YamlRenderer(_out: StringWriter = new java.io.StringWriter(), indentArrayI _out } } - override def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[StringWriter, StringWriter] { + + override def visitJsonableObject(length: Int, index: Int): ObjVisitor[StringWriter, StringWriter] = new ObjVisitor[StringWriter, StringWriter] { var empty = true flushBuffer() if (!topLevel) depth += 1 @@ -124,8 +127,10 @@ class YamlRenderer(_out: StringWriter = new java.io.StringWriter(), indentArrayI if (afterKey) newlineBuffered = true - def subVisitor = YamlRenderer.this - def visitKey(index: Int) = YamlRenderer.this + def subVisitor: YamlRenderer = YamlRenderer.this + + def visitKey(index: Int): YamlRenderer = YamlRenderer.this + def visitKeyValue(s: Any): Unit = { empty = false flushBuffer() @@ -136,10 +141,12 @@ class YamlRenderer(_out: StringWriter = new java.io.StringWriter(), indentArrayI afterKey = true newlineBuffered = false } + def visitValue(v: StringWriter, index: Int): Unit = { newlineBuffered = true afterKey = false } + def visitEnd(index: Int) = { if (empty) { elemBuilder.ensureLength(2) diff --git a/sjsonnet/test/src/sjsonnet/DummyPath.scala b/sjsonnet/test/src/sjsonnet/DummyPath.scala index 2b76dac1..79c80197 100644 --- a/sjsonnet/test/src/sjsonnet/DummyPath.scala +++ b/sjsonnet/test/src/sjsonnet/DummyPath.scala @@ -15,7 +15,7 @@ case class DummyPath(segments: String*) extends Path{ def last: String = segments.last - def /(s: String): Path = DummyPath(segments :+ s*) + def /(s: String): Path = DummyPath(segments :+ s:_*) def renderOffsetStr(offset: Int, loadedFileContents: mutable.HashMap[Path, Array[Int]]): String = { segments.mkString("/") + ":" + offset diff --git a/sjsonnet/test/src/sjsonnet/FormatTests.scala b/sjsonnet/test/src/sjsonnet/FormatTests.scala index a3e4f4a4..77dfe910 100644 --- a/sjsonnet/test/src/sjsonnet/FormatTests.scala +++ b/sjsonnet/test/src/sjsonnet/FormatTests.scala @@ -10,7 +10,7 @@ object FormatTests extends TestSuite{ val json = ujson.read(jsonStr) val formatted = Format.format(fmt, Materializer.reverse(null, json), dummyPos)( new EvalScope{ - def extVars = _ => None + def extVars: String => Option[Expr] = _ => None def wd: Path = DummyPath() def visitExpr(expr: Expr)(implicit scope: ValScope): Val = ??? def materialize(v: Val): Value = ??? diff --git a/sjsonnet/test/src/sjsonnet/OldRenderer.scala b/sjsonnet/test/src/sjsonnet/OldRenderer.scala index f9cf5045..98156129 100644 --- a/sjsonnet/test/src/sjsonnet/OldRenderer.scala +++ b/sjsonnet/test/src/sjsonnet/OldRenderer.scala @@ -38,19 +38,23 @@ class OldRenderer(out: Writer = new java.io.StringWriter(), newlineBuffered = false commaBuffered = false } - override def visitArray(length: Int, index: Int) = new ArrVisitor[Writer, Writer] { + + override def visitArray(length: Int, index: Int): ArrVisitor[Writer, Writer] = new ArrVisitor[Writer, Writer] { var empty = true flushBuffer() out.append('[') newlineBuffered = true depth += 1 - def subVisitor = OldRenderer.this + + def subVisitor: OldRenderer = OldRenderer.this + def visitValue(v: Writer, index: Int): Unit = { empty = false flushBuffer() commaBuffered = true } + def visitEnd(index: Int) = { commaBuffered = false newlineBuffered = false @@ -63,22 +67,27 @@ class OldRenderer(out: Writer = new java.io.StringWriter(), } } - override def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[Writer, Writer] { + override def visitJsonableObject(length: Int, index: Int): ObjVisitor[Writer, Writer] = new ObjVisitor[Writer, Writer] { var empty = true flushBuffer() out.append('{') newlineBuffered = true depth += 1 - def subVisitor = OldRenderer.this - def visitKey(index: Int) = OldRenderer.this + + def subVisitor: OldRenderer = OldRenderer.this + + def visitKey(index: Int): OldRenderer = OldRenderer.this + def visitKeyValue(v: Any): Unit = { empty = false flushBuffer() out.append(colonSnippet) } + def visitValue(v: Writer, index: Int): Unit = { commaBuffered = true } + def visitEnd(index: Int) = { commaBuffered = false newlineBuffered = false diff --git a/sjsonnet/test/src/sjsonnet/OldYamlRenderer.scala b/sjsonnet/test/src/sjsonnet/OldYamlRenderer.scala index b335b505..659fc045 100644 --- a/sjsonnet/test/src/sjsonnet/OldYamlRenderer.scala +++ b/sjsonnet/test/src/sjsonnet/OldYamlRenderer.scala @@ -54,7 +54,8 @@ class OldYamlRenderer(out: StringWriter = new java.io.StringWriter(), indentArra newlineBuffered = false dashBuffered = false } - override def visitArray(length: Int, index: Int) = new ArrVisitor[StringWriter, StringWriter] { + + override def visitArray(length: Int, index: Int): ArrVisitor[StringWriter, StringWriter] = new ArrVisitor[StringWriter, StringWriter] { var empty = true flushBuffer() @@ -69,13 +70,15 @@ class OldYamlRenderer(out: StringWriter = new java.io.StringWriter(), indentArra if (dedentInObject) depth -= 1 dashBuffered = true - def subVisitor = OldYamlRenderer.this + def subVisitor: OldYamlRenderer = OldYamlRenderer.this + def visitValue(v: StringWriter, index: Int): Unit = { empty = false flushBuffer() newlineBuffered = true dashBuffered = true } + def visitEnd(index: Int) = { if (!dedentInObject) depth -= 1 if (empty) out.append("[]") @@ -84,7 +87,8 @@ class OldYamlRenderer(out: StringWriter = new java.io.StringWriter(), indentArra out } } - override def visitJsonableObject(length: Int, index: Int) = new ObjVisitor[StringWriter, StringWriter] { + + override def visitJsonableObject(length: Int, index: Int): ObjVisitor[StringWriter, StringWriter] = new ObjVisitor[StringWriter, StringWriter] { var empty = true flushBuffer() if (!topLevel) depth += 1 @@ -92,8 +96,10 @@ class OldYamlRenderer(out: StringWriter = new java.io.StringWriter(), indentArra if (afterKey) newlineBuffered = true - def subVisitor = OldYamlRenderer.this - def visitKey(index: Int) = OldYamlRenderer.this + def subVisitor: OldYamlRenderer = OldYamlRenderer.this + + def visitKey(index: Int): OldYamlRenderer = OldYamlRenderer.this + def visitKeyValue(s: Any): Unit = { empty = false flushBuffer() @@ -101,10 +107,12 @@ class OldYamlRenderer(out: StringWriter = new java.io.StringWriter(), indentArra afterKey = true newlineBuffered = false } + def visitValue(v: StringWriter, index: Int): Unit = { newlineBuffered = true afterKey = false } + def visitEnd(index: Int) = { if (empty) out.append("{}") newlineBuffered = false