mirror of
https://github.com/enso-org/enso.git
synced 2024-11-26 08:52:58 +03:00
Remove obsolete Rust parser experiment, superseded by the much more mature new Rust parser integration (#3815)
We've had an old attempt at integrating a Rust parser with our Scala/Java projects. It seems to have been abandoned and is not used anywhere - it is also superseded by the new integration of the Rust parser. I think it was used as an experiment to see how to approach such an integration. Since it is not used anymore - it make sense to remove it, because it only adds some (slight, but non-zero) maintenance effort. We can always bring it back from git history if necessary.
This commit is contained in:
parent
2bc0611869
commit
bc09c7b4c2
26
build.sbt
26
build.sbt
@ -1193,32 +1193,6 @@ lazy val `language-server` = (project in file("engine/language-server"))
|
||||
.dependsOn(`library-manager-test` % Test)
|
||||
.dependsOn(`runtime-version-manager-test` % Test)
|
||||
|
||||
lazy val ast = (project in file("lib/scala/ast"))
|
||||
.settings(
|
||||
version := ensoVersion,
|
||||
Compile / sourceGenerators += GenerateAST.task
|
||||
)
|
||||
|
||||
lazy val parser = (project in file("lib/scala/parser"))
|
||||
.settings(
|
||||
fork := true,
|
||||
Compile / compile / compileInputs := (Compile / compile / compileInputs)
|
||||
.dependsOn(Cargo("build --project parser"))
|
||||
.value,
|
||||
javaOptions += {
|
||||
val root = baseDirectory.value.getParentFile.getParentFile.getParentFile
|
||||
s"-Djava.library.path=$root/target/rust/debug"
|
||||
},
|
||||
libraryDependencies ++= Seq(
|
||||
"org.scalatest" %%% "scalatest" % scalatestVersion % Test
|
||||
),
|
||||
testFrameworks := List(
|
||||
new TestFramework("org.scalatest.tools.Framework"),
|
||||
new TestFramework("org.scalameter.ScalaMeterFramework")
|
||||
)
|
||||
)
|
||||
.dependsOn(ast)
|
||||
|
||||
lazy val cleanInstruments = taskKey[Unit](
|
||||
"Cleans fragile class files to force a full recompilation and preserve" +
|
||||
"consistency of instrumentation configuration."
|
||||
|
@ -1,41 +0,0 @@
|
||||
package org.enso.parser
|
||||
|
||||
import org.enso.ast.Ast
|
||||
|
||||
import scala.annotation.unused
|
||||
|
||||
/** This is the Enso language parser.
|
||||
*
|
||||
* It is a wrapper of parser written in Rust that uses JNI to efficiently
|
||||
* construct scala AST directly without any serialization overhead.
|
||||
*
|
||||
* The methods are loaded from a native shared library `parser` that is located
|
||||
* in a directory specified by `-Djava.library.path` and has one of the extensions
|
||||
* `.dll`, `.so` or `dylib` depending on the platform (windows, linux or mac).
|
||||
*
|
||||
* The shared library itself is generated into `target/rust/debug` by executing
|
||||
* `cargo build -p parser`. Each method marked by `@native` must have a
|
||||
* corresponding counterpart in rust, otherwise the loading of the shared library
|
||||
* is going to fail at runtime with `UnsatisfiedLinkingError`.
|
||||
*/
|
||||
class Parser private () {
|
||||
|
||||
/** Parses a content of a single source file. */
|
||||
@native def parseStr(@unused input: String): Ast.AnyAst
|
||||
|
||||
/** Parses a single source file. */
|
||||
@native def parseFile(@unused filename: String): Ast.AnyAst
|
||||
|
||||
/** Parses a content of a single source file into a stream of tokens. */
|
||||
@native def lexStr(@unused input: String): Ast.AnyAst
|
||||
|
||||
/** Parses a single source file into a stream of tokens. */
|
||||
@native def lexFile(@unused filename: String): Ast.AnyAst
|
||||
}
|
||||
|
||||
object Parser {
|
||||
System.loadLibrary("parser")
|
||||
|
||||
/** Constructs a new parser */
|
||||
def apply(): Parser = new Parser()
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package org.enso.parser
|
||||
|
||||
import org.enso.ast.Ast
|
||||
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
|
||||
class ParserTest extends AnyFlatSpec with Matchers {
|
||||
val parser: Parser = Parser()
|
||||
|
||||
it should "parse file" in {
|
||||
val expected =
|
||||
Ast.Ast(uid = None, len = 0, off = 0, ast = Ast.Txt.Text("Hello!"))
|
||||
assert(expected == parser.parseStr("Hello!"))
|
||||
assert(expected == parser.parseFile("Hello!"))
|
||||
assert(expected == parser.lexStr("Hello!"))
|
||||
assert(expected == parser.lexFile("Hello!"))
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
import sbt.Keys._
|
||||
import sbt._
|
||||
import sbt.internal.util.ManagedLogger
|
||||
|
||||
object GenerateAST {
|
||||
|
||||
lazy val task = Def.task {
|
||||
val log = state.value.log
|
||||
val lib = baseDirectory.value.getParentFile.getParentFile
|
||||
val source = lib / "rust/ast/src/ast.rs"
|
||||
val output = sourceManaged.value / "main/org/enso/ast/Ast.scala"
|
||||
val cache = streams.value.cacheStoreFactory.make("ast_source")
|
||||
|
||||
Tracked.diffInputs(cache, FileInfo.lastModified)(Set(source)) {
|
||||
source: ChangeReport[File] =>
|
||||
if (source.modified.nonEmpty) {
|
||||
output.getParentFile.mkdirs
|
||||
generateAST(output, log)
|
||||
}
|
||||
}
|
||||
|
||||
Seq(output)
|
||||
}
|
||||
|
||||
/** Generates the Scala AST in the specified file. All errors are reported in
|
||||
* stderr and raise a runtime exception.
|
||||
*
|
||||
* @param out the file where the generated AST is going to be placed
|
||||
*/
|
||||
def generateAST(out: File, log: ManagedLogger): Unit = {
|
||||
val args = s"run -p ast -- --generate-scala-ast $out"
|
||||
|
||||
log.info(s"Generating Scala AST from Rust definitions.")
|
||||
|
||||
try Cargo.run(args, log)
|
||||
catch {
|
||||
case ex: RuntimeException =>
|
||||
log.error(s"Generation of the Scala AST failed.")
|
||||
throw ex
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user