From 11c98d6acfaf955f632e24d9ab77a54d002aefec Mon Sep 17 00:00:00 2001 From: Iaroslav Date: Mon, 27 Jul 2020 23:06:28 +0700 Subject: [PATCH] Upgrade better-parse to 0.4.0 --- kmath-ast/build.gradle.kts | 8 +----- .../kotlin/scientifik/kmath/ast/parser.kt | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts index 4f67d57eb..d13a7712d 100644 --- a/kmath-ast/build.gradle.kts +++ b/kmath-ast/build.gradle.kts @@ -9,21 +9,15 @@ kotlin.sourceSets { commonMain { 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") + implementation("com.github.h0tk3y.betterParse:better-parse:0.4.0") } } jvmMain { dependencies { - implementation("com.github.h0tk3y.betterParse:better-parse-jvm:0.4.0-alpha-3") implementation("org.ow2.asm:asm:8.0.1") implementation("org.ow2.asm:asm-commons:8.0.1") implementation(kotlin("reflect")) } } - - 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/commonMain/kotlin/scientifik/kmath/ast/parser.kt b/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/parser.kt index a0b729ffe..11797d79f 100644 --- a/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/parser.kt +++ b/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/parser.kt @@ -7,6 +7,7 @@ import com.github.h0tk3y.betterParse.grammar.parser import com.github.h0tk3y.betterParse.grammar.tryParseToEnd import com.github.h0tk3y.betterParse.lexer.Token import com.github.h0tk3y.betterParse.lexer.TokenMatch +import com.github.h0tk3y.betterParse.lexer.regexToken import com.github.h0tk3y.betterParse.parser.ParseResult import com.github.h0tk3y.betterParse.parser.Parser import scientifik.kmath.operations.FieldOperations @@ -15,20 +16,21 @@ import scientifik.kmath.operations.RingOperations import scientifik.kmath.operations.SpaceOperations /** - * TODO move to common + * TODO move to core */ object ArithmeticsEvaluator : Grammar() { - private val num: Token by token("[\\d.]+(?:[eE][-+]?\\d+)?".toRegex()) - private val id: Token by token("[a-z_A-Z][\\da-z_A-Z]*".toRegex()) - private val lpar: Token by token("\\(".toRegex()) - private val rpar: Token by token("\\)".toRegex()) - private val comma: Token by token(",".toRegex()) - private val mul: Token by token("\\*".toRegex()) - private val pow: Token by token("\\^".toRegex()) - private val div: Token by token("/".toRegex()) - private val minus: Token by token("-".toRegex()) - private val plus: Token by token("\\+".toRegex()) - private val ws: Token by token("\\s+".toRegex(), ignore = true) + // TODO replace with "...".toRegex() when better-parse 0.4.1 is released + private val num: Token by regexToken("[\\d.]+(?:[eE][-+]?\\d+)?") + private val id: Token by regexToken("[a-z_A-Z][\\da-z_A-Z]*") + private val lpar: Token by regexToken("\\(") + private val rpar: Token by regexToken("\\)") + private val comma: Token by regexToken(",") + private val mul: Token by regexToken("\\*") + private val pow: Token by regexToken("\\^") + private val div: Token by regexToken("/") + private val minus: Token by regexToken("-") + private val plus: Token by regexToken("\\+") + private val ws: Token by regexToken("\\s+", ignore = true) private val number: Parser by num use { MST.Numeric(text.toDouble()) } private val singular: Parser by id use { MST.Symbolic(text) }