From 866ae47239f93eea7625e65a94799ce7245f03c4 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 13 Jun 2020 11:51:33 +0300 Subject: [PATCH 1/2] replace `raw` by `symbol` in algebra --- kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MST.kt | 2 +- .../commonMain/kotlin/scientifik/kmath/ast/MSTExpression.kt | 2 +- .../commonMain/kotlin/scientifik/kmath/operations/Algebra.kt | 5 ++++- .../commonMain/kotlin/scientifik/kmath/operations/Complex.kt | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MST.kt b/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MST.kt index eba2c3343..3375ecdf3 100644 --- a/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MST.kt +++ b/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MST.kt @@ -43,7 +43,7 @@ sealed class MST { fun NumericAlgebra.evaluate(node: MST): T { return when (node) { is MST.Numeric -> number(node.value) - is MST.Singular -> raw(node.value) + is MST.Singular -> symbol(node.value) is MST.Unary -> unaryOperation(node.operation, evaluate(node.value)) is MST.Binary -> when { node.left is MST.Numeric && node.right is MST.Numeric -> { diff --git a/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MSTExpression.kt b/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MSTExpression.kt index 3ee454b2a..dbd5238e3 100644 --- a/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MSTExpression.kt +++ b/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MSTExpression.kt @@ -12,7 +12,7 @@ class MSTExpression(val algebra: NumericAlgebra, val mst: MST) : Expressio * Substitute algebra raw value */ private inner class InnerAlgebra(val arguments: Map) : NumericAlgebra by algebra { - override fun raw(value: String): T = arguments[value] ?: super.raw(value) + override fun symbol(value: String): T = arguments[value] ?: super.symbol(value) } override fun invoke(arguments: Map): T = InnerAlgebra(arguments).evaluate(mst) diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Algebra.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Algebra.kt index 166287ec7..8ed3f329e 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Algebra.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Algebra.kt @@ -10,7 +10,10 @@ interface Algebra { /** * Wrap raw string or variable */ - fun raw(value: String): T = error("Wrapping of '$value' is not supported in $this") + fun symbol(value: String): T = error("Wrapping of '$value' is not supported in $this") + + @Deprecated("Symbol is more concise",replaceWith = ReplaceWith("symbol")) + fun raw(value: String): T = symbol(value) /** * Dynamic call of unary operation with name [operation] on [arg] diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt index 01aef824d..6ce1d929b 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt @@ -51,10 +51,10 @@ object ComplexField : ExtendedField { operator fun Double.times(c: Complex) = Complex(c.re * this, c.im * this) - override fun raw(value: String): Complex = if (value == "i") { + override fun symbol(value: String): Complex = if (value == "i") { i } else { - super.raw(value) + super.symbol(value) } } From 0950580b85ca02a72c13863efc72aae2367e3ab3 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 13 Jun 2020 18:26:18 +0300 Subject: [PATCH 2/2] Moe better-parse to common. Watch for https://github.com/h0tk3y/better-parse/issues/27 --- kmath-ast/build.gradle.kts | 6 ++++++ .../kotlin/scientifik/kmath/ast/parser.kt | 0 2 files changed, 6 insertions(+) rename kmath-ast/src/{jvmMain => commonMain}/kotlin/scientifik/kmath/ast/parser.kt (100%) diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts index 88540e7b8..65a1ac12c 100644 --- a/kmath-ast/build.gradle.kts +++ b/kmath-ast/build.gradle.kts @@ -11,6 +11,7 @@ kotlin.sourceSets { dependencies { api(project(":kmath-core")) implementation("com.github.h0tk3y.betterParse:better-parse-multiplatform:0.4.0-alpha-3") + implementation("com.github.h0tk3y.betterParse:better-parse-multiplatform-metadata:0.4.0-alpha-3") } } jvmMain{ @@ -18,4 +19,9 @@ kotlin.sourceSets { implementation("com.github.h0tk3y.betterParse:better-parse-jvm:0.4.0-alpha-3") } } + jsMain{ + dependencies{ + implementation("com.github.h0tk3y.betterParse:better-parse-js:0.4.0-alpha-3") + } + } } \ No newline at end of file diff --git a/kmath-ast/src/jvmMain/kotlin/scientifik/kmath/ast/parser.kt b/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/parser.kt similarity index 100% rename from kmath-ast/src/jvmMain/kotlin/scientifik/kmath/ast/parser.kt rename to kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/parser.kt