Skip to content

Commit

Permalink
Move to good old oslib
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Dec 24, 2024
1 parent 1eb2eb9 commit d5e542f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ lazy val parsergen = module("parser-gen")
"com.disneystreaming.smithy4s" %% "smithy4s-json" % smithy4sVersion.value,
("org.scalameta" %% "scalameta" % "4.11.0").cross(CrossVersion.for3Use2_13),
"org.polyvariant.treesitter4s" %% "core" % "0.4.0",
"com.lihaoyi" %% "os-lib" % "0.11.3",
),
scalacOptions -= "-release:11",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import treesittersmithy.NodeTypes
import treesittersmithy.TypeName
import util.chaining.*

import java.nio.file.Files
import java.nio.file.Paths
import scala.annotation.targetName
import scala.jdk.CollectionConverters.*
import scala.meta.Dialect

extension (tn: TypeName) {
Expand Down Expand Up @@ -304,13 +301,14 @@ private def renderProduct(p: Type.Product): String = {
val types =
Json
.read[NodeTypes](
Blob(Files.readString(Paths.get("tree-sitter-smithyql/src/node-types.json")))
Blob(os.read(os.pwd / "tree-sitter-smithyql" / "src" / "node-types.json"))
)
.toTry
.get
.value

val base = Paths.get(s"modules/treesitter/src/main/scala/playground/generated/nodes")
val base =
os.pwd / "modules" / "treesitter" / "src" / "main" / "scala" / "playground" / "generated" / "nodes"

val rendered = types
.filter(_.named)
Expand All @@ -326,15 +324,14 @@ private def renderProduct(p: Type.Product): String = {
_.render
)

Files.createDirectories(base)

Files.walk(base).iterator().asScala.filter(Files.isRegularFile(_)).foreach(Files.delete)
os.remove.all(base)

rendered
.foreach { (tpe, code) =>
Files.writeString(
base.resolve(s"${tpe.tpe.render}.scala"),
os.write(
base / s"${tpe.tpe.render}.scala",
code,
createFolders = true,
)
}
}
Expand Down

0 comments on commit d5e542f

Please sign in to comment.