Skip to content

Commit 4d2d925

Browse files
committed
upgraded to scala 3
removed runtime compilation
1 parent 35f2647 commit 4d2d925

File tree

6 files changed

+13
-157
lines changed

6 files changed

+13
-157
lines changed

README.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
### Introduction and Motivation
88

9-
`mathParser` is a small Library created for a single purpose:
9+
`math-parser` is a small Library created for a single purpose:
1010
It parses strings into abstract syntax trees (AST) of math-like languages.
1111
The AST can be used to easily reason over it, modify it, optimize it or derive it.
1212

@@ -22,22 +22,21 @@ import mathParser.SpireImplicits._
2222

2323
// define your language:
2424
object X
25-
val language = mathParser.SpireLanguages.doubleLanguage
26-
.withVariables(List("x" -> X))
25+
val language = mathParser.SpireLanguages.doubleLanguage.withVariables(List("x" -> X))
2726

2827
// parsing: string => Option[AST]
2928
// .get only to demonstrate.
3029
val parsed = language.parse(string).get
3130

3231
// evaluating:
3332
language.evaluate(parsed){
34-
case X => 5 // assign values to your variables
33+
case X => 5 // assign values to your variables
3534
} // == 5*5*2 + 1 == 51
3635

3736
// deriving:
3837
val derived = language.derive(parsed)(X) // d/dx (2*x*x + 1) == 4*x
3938
language.evaluate(derived){
40-
case X => 5
39+
case X => 5
4140
} // == 4*5 == 20
4241
```
4342

@@ -50,10 +49,6 @@ Using a bunch of traits and the famous cake pattern, it is possible to define a
5049
* Analytic Function Derivative:
5150
For the predefined languages it is possible to calculate analytical derivatives for arbitrary functions.
5251

53-
* Runtime compilation:
54-
For the predefined languages it is possible to use the scala compiler at runtime to compile your AST into a high-performance function-object.
55-
56-
5752
### Setup
5853

5954
To use the library extend your sbt build with:
@@ -67,12 +62,6 @@ There is a subproject to work with `spire`.
6762
libraryDependencies += "com.github.gregor-i.math-parser" %% "math-parser-spire" % {current-version}
6863
```
6964

70-
If you want to use runtime compilation (only availible on the jvm), use the following library dependency.
71-
Be aware that this has the scala compiler as runtime dependencies.
72-
```sbt
73-
libraryDependencies += "com.github.gregor-i.math-parser" %% "math-parser-compile-jvm" % {current-version}
74-
```
75-
7665
### Examples and Usage
7766

7867
To get started take a look into the `examples` folder.

build.sbt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ThisBuild / version := {
77
.getOrElse("SNAPSHOT")
88
}
99
ThisBuild / organization := "com.github.gregor-i"
10-
ThisBuild / scalaVersion := "2.13.5"
10+
ThisBuild / scalaVersion := "3.0.0"
1111

1212
val `math-parser` =
1313
crossProject(JSPlatform, JVMPlatform)
@@ -18,16 +18,12 @@ val `math-parser-spire` =
1818
project
1919
.dependsOn(`math-parser`.jvm)
2020
.settings(
21-
libraryDependencies += "org.typelevel" %%% "spire" % "0.17.0"
21+
libraryDependencies += "org.typelevel" % "spire_2.13" % "0.17.0"
2222
)
2323
.settings(testSettings)
2424

25-
val `math-parser-compile-jvm` = project
26-
.dependsOn(`math-parser-spire` % "compile -> compile; test -> test")
27-
.settings(libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value)
28-
2925
val `examples` = project
30-
.dependsOn(`math-parser-spire`, `math-parser-compile-jvm`)
26+
.dependsOn(`math-parser-spire`)
3127
.settings(publish / skip := true)
3228
.settings(packagedArtifacts := Map.empty)
3329
.settings(

examples/src/main/scala/plotter/FunctionPlotterCli.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package plotter
22

3-
import java.io.File
4-
5-
import mathParser.MathParser
6-
import org.jfree.chart.ChartPanel
73
import de.sciss.chart.api._
8-
94
import mathParser.SpireImplicits._
10-
import mathParser.algebra.compile.SpireCompiler.compilerDouble1
5+
import org.jfree.chart.ChartPanel
6+
7+
import java.io.File
118

129
case class Config(
1310
term: String = null,
@@ -53,8 +50,9 @@ object Main {
5350
def main(args: Array[String]): Unit = {
5451
ConfigParser.parse(args, Config()).foreach { config =>
5552
val parsed = lang.parse(config.term).get
56-
val f = lang.compile[Double => Double](parsed).get
57-
val `f'` = lang.compile[Double => Double](lang.derive(parsed)(X)).get
53+
val derived = lang.derive(parsed)(X)
54+
val f = (x: Double) => lang.evaluate(parsed){ case X => x }
55+
val `f'` = (x: Double) => lang.evaluate(derived){ case X => x }
5856

5957
val p1 = new XYSeries(s"f(x)": Comparable[_], false, true)
6058
val p2 = new XYSeries(s"f'(x)": Comparable[_], false, true)

math-parser-compile-jvm/src/main/scala/mathParser/algebra/compile/SpireCompiler.scala

Lines changed: 0 additions & 76 deletions
This file was deleted.

math-parser-compile-jvm/src/test/scala/mathParser/algebra/compile/CompileSpec.scala

Lines changed: 0 additions & 41 deletions
This file was deleted.

release.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)