Dev #127

Merged
altavir merged 214 commits from dev into master 2020-08-11 08:33:21 +03:00
2 changed files with 15 additions and 19 deletions
Showing only changes of commit 11c98d6acf - Show all commits

View File

@ -9,21 +9,15 @@ kotlin.sourceSets {
commonMain { commonMain {
dependencies { dependencies {
api(project(":kmath-core")) api(project(":kmath-core"))
implementation("com.github.h0tk3y.betterParse:better-parse-multiplatform:0.4.0-alpha-3") implementation("com.github.h0tk3y.betterParse:better-parse:0.4.0")
implementation("com.github.h0tk3y.betterParse:better-parse-multiplatform-metadata:0.4.0-alpha-3")
} }
} }
jvmMain { jvmMain {
dependencies { 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:8.0.1")
implementation("org.ow2.asm:asm-commons:8.0.1") implementation("org.ow2.asm:asm-commons:8.0.1")
implementation(kotlin("reflect")) implementation(kotlin("reflect"))
} }
} }
jsMain {
dependencies { implementation("com.github.h0tk3y.betterParse:better-parse-js:0.4.0-alpha-3") }
}
} }

View File

@ -7,6 +7,7 @@ import com.github.h0tk3y.betterParse.grammar.parser
import com.github.h0tk3y.betterParse.grammar.tryParseToEnd import com.github.h0tk3y.betterParse.grammar.tryParseToEnd
import com.github.h0tk3y.betterParse.lexer.Token import com.github.h0tk3y.betterParse.lexer.Token
import com.github.h0tk3y.betterParse.lexer.TokenMatch 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.ParseResult
import com.github.h0tk3y.betterParse.parser.Parser import com.github.h0tk3y.betterParse.parser.Parser
import scientifik.kmath.operations.FieldOperations import scientifik.kmath.operations.FieldOperations
@ -15,20 +16,21 @@ import scientifik.kmath.operations.RingOperations
import scientifik.kmath.operations.SpaceOperations import scientifik.kmath.operations.SpaceOperations
/** /**
* TODO move to common * TODO move to core
*/ */
object ArithmeticsEvaluator : Grammar<MST>() { object ArithmeticsEvaluator : Grammar<MST>() {
private val num: Token by token("[\\d.]+(?:[eE][-+]?\\d+)?".toRegex()) // TODO replace with "...".toRegex() when better-parse 0.4.1 is released
private val id: Token by token("[a-z_A-Z][\\da-z_A-Z]*".toRegex()) private val num: Token by regexToken("[\\d.]+(?:[eE][-+]?\\d+)?")
private val lpar: Token by token("\\(".toRegex()) private val id: Token by regexToken("[a-z_A-Z][\\da-z_A-Z]*")
private val rpar: Token by token("\\)".toRegex()) private val lpar: Token by regexToken("\\(")
private val comma: Token by token(",".toRegex()) private val rpar: Token by regexToken("\\)")
private val mul: Token by token("\\*".toRegex()) private val comma: Token by regexToken(",")
private val pow: Token by token("\\^".toRegex()) private val mul: Token by regexToken("\\*")
private val div: Token by token("/".toRegex()) private val pow: Token by regexToken("\\^")
private val minus: Token by token("-".toRegex()) private val div: Token by regexToken("/")
private val plus: Token by token("\\+".toRegex()) private val minus: Token by regexToken("-")
private val ws: Token by token("\\s+".toRegex(), ignore = true) private val plus: Token by regexToken("\\+")
private val ws: Token by regexToken("\\s+", ignore = true)
private val number: Parser<MST> by num use { MST.Numeric(text.toDouble()) } private val number: Parser<MST> by num use { MST.Numeric(text.toDouble()) }
private val singular: Parser<MST> by id use { MST.Symbolic(text) } private val singular: Parser<MST> by id use { MST.Symbolic(text) }