Skip to content

Commit

Permalink
fixing compiler errors
Browse files Browse the repository at this point in the history
  • Loading branch information
almibe committed May 9, 2023
1 parent 7974ed8 commit de554bd
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 63 deletions.
10 changes: 5 additions & 5 deletions lig/shared/src/test/scala/dev/ligature/lig/LigInputSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package dev.ligature.lig

import dev.ligature.gaze.Gaze
import dev.ligature.{Identifier, IntegerLiteral, Statement, StringLiteral}
import dev.ligature.{Identifier, Statement, LigatureLiteral}
import munit.FunSuite

class LigInputSuite extends FunSuite {
Expand Down Expand Up @@ -63,12 +63,12 @@ class LigInputSuite extends FunSuite {
Statement(
Identifier.fromString("e").getOrElse(???),
Identifier.fromString("a").getOrElse(???),
IntegerLiteral(234)
LigatureLiteral.IntegerLiteral(234)
),
Statement(
Identifier.fromString("e").getOrElse(???),
Identifier.fromString("a").getOrElse(???),
IntegerLiteral(432)
LigatureLiteral.IntegerLiteral(432)
)
)
val res = read(input)
Expand All @@ -90,12 +90,12 @@ class LigInputSuite extends FunSuite {
Statement(
Identifier.fromString("e").getOrElse(???),
Identifier.fromString("a").getOrElse(???),
IntegerLiteral(234)
LigatureLiteral.IntegerLiteral(234)
),
Statement(
Identifier.fromString("e2").getOrElse(???),
Identifier.fromString("a").getOrElse(???),
IntegerLiteral(234)
LigatureLiteral.IntegerLiteral(234)
)
)
val result = read(input)
Expand Down
22 changes: 11 additions & 11 deletions lig/shared/src/test/scala/dev/ligature/lig/LigSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package dev.ligature.lig

import munit.FunSuite
import dev.ligature.{Identifier, IntegerLiteral, Statement, StringLiteral}
import dev.ligature.{Identifier, LigatureLiteral, Statement}
import dev.ligature.gaze.Gaze

class LigSuite extends FunSuite {
Expand Down Expand Up @@ -36,12 +36,12 @@ class LigSuite extends FunSuite {
Statement(
identifier("e2"),
identifier("a2"),
StringLiteral("string literal")
LigatureLiteral.StringLiteral("string literal")
),
Statement(
identifier("e2"),
identifier("a3"),
IntegerLiteral(Long.MaxValue)
LigatureLiteral.IntegerLiteral(Long.MaxValue)
)
)
val lines = write(statements.iterator)
Expand All @@ -61,8 +61,8 @@ class LigSuite extends FunSuite {
|""".stripMargin
val expectedStatements = Set(
Statement(identifier("a"), identifier("b"), identifier("c")),
Statement(identifier("a"), identifier("b"), IntegerLiteral(123)),
Statement(identifier("a"), identifier("b"), StringLiteral("Test")),
Statement(identifier("a"), identifier("b"), LigatureLiteral.IntegerLiteral(123)),
Statement(identifier("a"), identifier("b"), LigatureLiteral.StringLiteral("Test")),
)
val resStatements = read(statements)
resStatements match {
Expand All @@ -88,14 +88,14 @@ class LigSuite extends FunSuite {

test("parse IntegerLiteral") {
val test = "3452345"
val res = parseIntegerLiteral(Gaze.from(test))
assertEquals(res, Right(IntegerLiteral(3452345)))
val res: Either[LigError, LigatureLiteral] = parseIntegerLiteral(Gaze.from(test))
assertEquals(res, Right(LigatureLiteral.IntegerLiteral(3452345)))
}

test("parse StringLiteral") {
val test = "\"3452345\\nHello\""
val res = parseStringLiteral(Gaze.from(test))
assertEquals(res, Right(StringLiteral("3452345\\nHello")))
val res: Either[LigError, LigatureLiteral] = parseStringLiteral(Gaze.from(test))
assertEquals(res, Right(LigatureLiteral.StringLiteral("3452345\\nHello")))
}

test("write identifiers") {
Expand All @@ -104,13 +104,13 @@ class LigSuite extends FunSuite {
}

test("write IntegerLiteral") {
val test = IntegerLiteral(3535)
val test = LigatureLiteral.IntegerLiteral(3535)
val res = writeValue(test)
assertEquals(res, "3535")
}

test("write StringLiteral") {
val test = StringLiteral("3535 55Hello")
val test = LigatureLiteral.StringLiteral("3535 55Hello")
val res = writeValue(test)
assertEquals(res, "\"3535 55Hello\"")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import dev.ligature.{Dataset, Identifier, Ligature, LigatureError, Statement}
import dev.ligature.lig.{LigError, read, write}
import dev.ligature.wander.run
import dev.ligature.wander.printWanderValue
import dev.ligature.wander.parser.ScriptResult
import dev.ligature.wander.ScriptResult

enum AuthMode:
case None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

package dev.ligature.js

import dev.ligature.Dataset
import dev.ligature.wander.run as wanderRun

import scala.scalajs.js.annotation.JSExportTopLevel
import dev.ligature.wander.common

@JSExportTopLevel("run")
def run(script: String, dataset: Dataset): String = {
wanderRun(script, dataset).toString
def run(script: String): String = {
wanderRun(script, common()).toString
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ abstract class LigatureTestSuite extends CatsEffectSuite {
_ <- instance.write(testDataset) { tx =>
for {
_ <- tx.addStatement(Statement(entity1, a, entity2))
_ <- tx.addStatement(Statement(entity1, a, IntegerLiteral(100)))
_ <- tx.addStatement(Statement(entity1, a, IntegerLiteral(101)))
_ <- tx.addStatement(Statement(entity1, a, IntegerLiteral(100)))
_ <- tx.addStatement(Statement(entity2, a, IntegerLiteral(-243729)))
_ <- tx.addStatement(Statement(entity1, a, LigatureLiteral.IntegerLiteral(100)))
_ <- tx.addStatement(Statement(entity1, a, LigatureLiteral.IntegerLiteral(101)))
_ <- tx.addStatement(Statement(entity1, a, LigatureLiteral.IntegerLiteral(100)))
_ <- tx.addStatement(Statement(entity2, a, LigatureLiteral.IntegerLiteral(-243729)))
} yield IO.unit
}
statements <- instance.query(testDataset) { tx =>
Expand All @@ -162,9 +162,9 @@ abstract class LigatureTestSuite extends CatsEffectSuite {
res,
Set(
Statement(entity1, a, entity2),
Statement(entity1, a, IntegerLiteral(100)),
Statement(entity1, a, IntegerLiteral(101)),
Statement(entity2, a, IntegerLiteral(-243729))
Statement(entity1, a, LigatureLiteral.IntegerLiteral(100)),
Statement(entity1, a, LigatureLiteral.IntegerLiteral(101)),
Statement(entity2, a, LigatureLiteral.IntegerLiteral(-243729))
)
)
}
Expand All @@ -176,10 +176,10 @@ abstract class LigatureTestSuite extends CatsEffectSuite {
_ <- instance.write(testDataset) { tx =>
for {
_ <- tx.addStatement(Statement(entity1, a, entity2))
_ <- tx.addStatement(Statement(entity1, a, StringLiteral("text")))
_ <- tx.addStatement(Statement(entity1, a, StringLiteral("text2")))
_ <- tx.addStatement(Statement(entity1, a, StringLiteral("text")))
_ <- tx.addStatement(Statement(entity2, a, StringLiteral("text")))
_ <- tx.addStatement(Statement(entity1, a, LigatureLiteral.StringLiteral("text")))
_ <- tx.addStatement(Statement(entity1, a, LigatureLiteral.StringLiteral("text2")))
_ <- tx.addStatement(Statement(entity1, a, LigatureLiteral.StringLiteral("text")))
_ <- tx.addStatement(Statement(entity2, a, LigatureLiteral.StringLiteral("text")))
} yield IO.unit
}
statements <- instance.query(testDataset) { tx =>
Expand All @@ -190,9 +190,9 @@ abstract class LigatureTestSuite extends CatsEffectSuite {
res,
Set(
Statement(entity1, a, entity2),
Statement(entity1, a, StringLiteral("text")),
Statement(entity1, a, StringLiteral("text2")),
Statement(entity2, a, StringLiteral("text"))
Statement(entity1, a, LigatureLiteral.StringLiteral("text")),
Statement(entity1, a, LigatureLiteral.StringLiteral("text2")),
Statement(entity2, a, LigatureLiteral.StringLiteral("text"))
)
)
}
Expand Down Expand Up @@ -266,17 +266,17 @@ abstract class LigatureTestSuite extends CatsEffectSuite {
_ <- instance.createDataset(testDataset)
_ <- instance.write(testDataset) { tx =>
for {
_ <- tx.addStatement(Statement(entity1, a, StringLiteral("hello")))
_ <- tx.addStatement(Statement(entity1, a, StringLiteral("hello")))
_ <- tx.addStatement(Statement(entity2, a, StringLiteral("hello")))
_ <- tx.removeStatement(Statement(entity1, a, StringLiteral("hello")))
_ <- tx.addStatement(Statement(entity1, a, LigatureLiteral.StringLiteral("hello")))
_ <- tx.addStatement(Statement(entity1, a, LigatureLiteral.StringLiteral("hello")))
_ <- tx.addStatement(Statement(entity2, a, LigatureLiteral.StringLiteral("hello")))
_ <- tx.removeStatement(Statement(entity1, a, LigatureLiteral.StringLiteral("hello")))
} yield ()
}
statements <- instance.query(testDataset) { tx =>
tx.allStatements().compile.toList
}
} yield statements.toSet
assertIO(res, Set(Statement(entity2, a, StringLiteral("hello"))))
assertIO(res, Set(Statement(entity2, a, LigatureLiteral.StringLiteral("hello"))))
}

// test("allow canceling WriteTx by throwing exception") {
Expand Down Expand Up @@ -312,13 +312,13 @@ abstract class LigatureTestSuite extends CatsEffectSuite {
_ <- instance.write(testDataset) { tx =>
for {
_ <- tx.addStatement(
Statement(entity1, a, StringLiteral("Hello"))
Statement(entity1, a, LigatureLiteral.StringLiteral("Hello"))
)
_ <- tx.addStatement(Statement(entity2, a, entity1))
_ <- tx.addStatement(Statement(entity2, a, entity3))
_ <- tx.addStatement(Statement(entity3, b, entity2))
_ <- tx.addStatement(
Statement(entity3, b, StringLiteral("Hello"))
Statement(entity3, b, LigatureLiteral.StringLiteral("Hello"))
)
} yield ()
}
Expand All @@ -327,11 +327,11 @@ abstract class LigatureTestSuite extends CatsEffectSuite {
all <- tx.matchStatements().compile.toList
as <- tx.matchStatements(None, Some(a)).compile.toList
hellos <- tx
.matchStatements(None, None, Some(StringLiteral("Hello")))
.matchStatements(None, None, Some(LigatureLiteral.StringLiteral("Hello")))
.compile
.toList
helloa <- tx
.matchStatements(None, Some(a), Some(StringLiteral("Hello")))
.matchStatements(None, Some(a), Some(LigatureLiteral.StringLiteral("Hello")))
.compile
.toList
} yield (all.toSet, as.toSet, hellos.toSet, helloa.toSet)
Expand All @@ -341,32 +341,32 @@ abstract class LigatureTestSuite extends CatsEffectSuite {
assertEquals(
all,
Set(
Statement(entity1, a, StringLiteral("Hello")),
Statement(entity1, a, LigatureLiteral.StringLiteral("Hello")),
Statement(entity2, a, entity1),
Statement(entity2, a, entity3),
Statement(entity3, b, entity2),
Statement(entity3, b, StringLiteral("Hello"))
Statement(entity3, b, LigatureLiteral.StringLiteral("Hello"))
)
)
assertEquals(
as,
Set(
Statement(entity1, a, StringLiteral("Hello")),
Statement(entity1, a, LigatureLiteral.StringLiteral("Hello")),
Statement(entity2, a, entity1),
Statement(entity2, a, entity3)
)
)
assertEquals(
hellos,
Set(
Statement(entity1, a, StringLiteral("Hello")),
Statement(entity3, b, StringLiteral("Hello"))
Statement(entity1, a, LigatureLiteral.StringLiteral("Hello")),
Statement(entity3, b, LigatureLiteral.StringLiteral("Hello"))
)
)
assertEquals(
helloa,
Set(
Statement(entity1, a, StringLiteral("Hello"))
Statement(entity1, a, LigatureLiteral.StringLiteral("Hello"))
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class XodusQueryTx(
Option(result)
}

private def lookupStringLiteral(stringLiteral: StringLiteral): Option[ByteIterable] = {
private def lookupStringLiteral(stringLiteral: LigatureLiteral.StringLiteral): Option[ByteIterable] = {
val store = xodusOperations.openStore(tx, LigatureStore.StringToIdStore)
val result = store.get(
tx,
Expand All @@ -64,11 +64,11 @@ class XodusQueryTx(
Array(ByteBinding.byteToEntry(LigatureValueType.Identifier.id), id)
)
)
case stringLiteral: StringLiteral =>
case stringLiteral: LigatureLiteral.StringLiteral =>
lookupStringLiteral(stringLiteral).map(id =>
CompoundByteIterable(Array(ByteBinding.byteToEntry(LigatureValueType.String.id), id))
)
case integerLiteral: IntegerLiteral =>
case integerLiteral: LigatureLiteral.IntegerLiteral =>
Some(
CompoundByteIterable(
Array(
Expand All @@ -80,19 +80,19 @@ class XodusQueryTx(
}
}

private def lookupStringLiteral(internalIdentifier: ByteIterable): StringLiteral =
private def lookupStringLiteral(internalIdentifier: ByteIterable): LigatureLiteral.StringLiteral =
val idToStringStore = xodusOperations.openStore(tx, LigatureStore.IdToStringStore)
val result = idToStringStore.get(tx, CompoundByteIterable(Array(datasetID, internalIdentifier)))
if (result != null) {
StringLiteral(StringBinding.entryToString(result))
LigatureLiteral.StringLiteral(StringBinding.entryToString(result))
} else {
???
}

private def constructValue(valueTypeId: Byte, valueContent: ByteIterable): Value =
LigatureValueType.getValueType(valueTypeId) match {
case LigatureValueType.Identifier => lookupIdentifier(valueContent)
case LigatureValueType.Integer => IntegerLiteral(LongBinding.entryToLong(valueContent))
case LigatureValueType.Integer => LigatureLiteral.IntegerLiteral(LongBinding.entryToLong(valueContent))
case LigatureValueType.String => lookupStringLiteral(valueContent)
case LigatureValueType.Bytes => ???
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class XodusWriteTx(
internalId
}

private def lookupStringLiteral(literal: StringLiteral): Option[ByteIterable] =
private def lookupStringLiteral(literal: LigatureLiteral.StringLiteral): Option[ByteIterable] =
val stringToIdStore = xodusOperations.openStore(tx, LigatureStore.StringToIdStore)
val encodedString = CompoundByteIterable(
Array(datasetID, StringBinding.stringToEntry(literal.value))
Expand All @@ -53,7 +53,7 @@ class XodusWriteTx(
Option(result)

// TODO this function might be able to be merged with lookupOrCreateIdentifier
private def lookupOrCreateStringLiteral(literal: StringLiteral): ByteIterable =
private def lookupOrCreateStringLiteral(literal: LigatureLiteral.StringLiteral): ByteIterable =
val stringToIdStore = xodusOperations.openStore(tx, LigatureStore.StringToIdStore)
val encodedString = StringBinding.stringToEntry(literal.value)
val encodedStringWithDataset = CompoundByteIterable(Array(datasetID, encodedString))
Expand Down Expand Up @@ -87,14 +87,14 @@ class XodusWriteTx(
)
)
temp
case stringLiteral: StringLiteral =>
case stringLiteral: LigatureLiteral.StringLiteral =>
CompoundByteIterable(
Array(
ByteBinding.byteToEntry(LigatureValueType.String.id),
lookupOrCreateStringLiteral(stringLiteral)
)
)
case integerLiteral: IntegerLiteral =>
case integerLiteral: LigatureLiteral.IntegerLiteral =>
CompoundByteIterable(
Array(
ByteBinding.byteToEntry(LigatureValueType.Integer.id),
Expand Down Expand Up @@ -215,7 +215,7 @@ class XodusWriteTx(
)
)
}
case stringLiteral: StringLiteral =>
case stringLiteral: LigatureLiteral.StringLiteral =>
lookupStringLiteral(stringLiteral) match {
case None => None
case Some(stringId) =>
Expand All @@ -225,7 +225,7 @@ class XodusWriteTx(
)
)
}
case IntegerLiteral(value) =>
case LigatureLiteral.IntegerLiteral(value) =>
Some(LongBinding.longToEntry(value)) // TODO needs value type
}

Expand Down Expand Up @@ -311,12 +311,12 @@ class XodusWriteTx(
value match {
case identifier: Identifier =>
checkAndRemoveIdentifier(identifier, valueEncoded.subIterable(1, 8))
case stringLiteral: StringLiteral =>
case stringLiteral: LigatureLiteral.StringLiteral =>
val stringToIdStore = xodusOperations.openStore(tx, LigatureStore.StringToIdStore)
val idToStringStore = xodusOperations.openStore(tx, LigatureStore.IdToStringStore)
stringToIdStore.delete(tx, StringBinding.stringToEntry(stringLiteral.value))
idToStringStore.delete(tx, valueEncoded.subIterable(1, 8))
case _: IntegerLiteral => ()
case _: LigatureLiteral.IntegerLiteral => ()
// TODO support bytes
}
}

0 comments on commit de554bd

Please sign in to comment.