Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
winitzki committed Jul 11, 2024
1 parent 22b3d79 commit 07c5fb2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 8 additions & 14 deletions scall-cli/src/test/scala/io/chymyst/dhall/unit/PerfTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ import java.nio.file.{Files, Paths}

class PerfTest extends FunSuite with ResourceFiles with TestTimings {

test("parse schema.dhall 1") {
val file = resourceAsFile("yaml-perftest/schema.dhall").get
val results = (1 to 20).map { i =>
val (_, elapsed) = elapsedNanos(Parser.parseDhallStream(new FileInputStream(file)).get.value.value)
println(s"iteration $i : schema.dhall parsed in ${elapsed / 1e9} seconds")
}
}

test("parse schema.dhall 2") {
val file = resourceAsFile("yaml-perftest/schema.dhall").get
val (_, elapsed) = elapsedNanos(Parser.parseDhallStream(new FileInputStream(file)).get.value.value)
println(s"schema.dhall parsed in ${elapsed / 1e9} seconds")
}

test("create yaml from realistic example 1") {
val file = resourceAsFile("yaml-perftest/create_yaml.dhall").get
val options = YamlOptions()
Expand All @@ -44,6 +30,14 @@ class PerfTest extends FunSuite with ResourceFiles with TestTimings {
expect(resultYaml == expectedYaml)
}

test("parse schema.dhall 20 times") {
val file = resourceAsFile("yaml-perftest/schema.dhall").get
val results = (1 to 20).map { i =>
val (_, elapsed) = elapsedNanos(Parser.parseDhallStream(new FileInputStream(file)).get.value.value)
println(s"iteration $i : schema.dhall parsed in ${elapsed / 1e9} seconds")
}
}

test("parse Prelude/JSON/renderAs.dhall") {
val file = resourceAsFile("dhall-lang/Prelude/JSON/renderAs.dhall").get

Check failure on line 42 in scall-cli/src/test/scala/io/chymyst/dhall/unit/PerfTest.scala

View workflow job for this annotation

GitHub Actions / Test results

io.chymyst.dhall.unit.PerfTest ► parse Prelude/JSON/renderAs.dhall

Failed test found in: scall-cli/target/test-reports/TEST-io.chymyst.dhall.unit.PerfTest.xml Error: sbt.ForkMain$ForkError: java.util.NoSuchElementException: None.get
Raw output
sbt.ForkMain$ForkError: java.util.NoSuchElementException: None.get
	at scala.None$.get(Option.scala:627)
	at scala.None$.get(Option.scala:626)
	at io.chymyst.dhall.unit.PerfTest.$anonfun$new$6(PerfTest.scala:42)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
val (_, elapsed) = elapsedNanos(Parser.parseDhallStream(new FileInputStream(file)).get.value.value)
Expand Down
2 changes: 2 additions & 0 deletions scall-core/src/main/scala/io/chymyst/dhall/Grammar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ object Grammar {
def import_expression[$: P]: P[Expression] = P(
import_only | completion_expression
)
.memoize

def completion_expression[$: P]: P[Expression] = P(
selector_expression ~ (whsp ~ complete ~ whsp ~ selector_expression).?
Expand All @@ -1132,6 +1133,7 @@ object Grammar {
def selector_expression[$: P]: P[Expression] = P(
primitive_expression ~ (whsp ~ "." ~ whsp ~ /* No cut here, or else (List ./imported.file) cannot be parsed. */ selector).rep
).map { case (base, selectors) => selectors.foldLeft(base)((prev, selector) => selector.chooseExpression(prev)) }
.memoize

sealed trait ExpressionSelector {
def chooseExpression(base: Expression): Expression = this match {
Expand Down

0 comments on commit 07c5fb2

Please sign in to comment.