From a5499260fae7e412da6ca6fcd9769382d7d9357f Mon Sep 17 00:00:00 2001 From: Iaroslav Date: Mon, 27 Jul 2020 15:45:05 +0700 Subject: [PATCH] Update num rule to match 1e+1 like numbers --- kmath-ast/reference/ArithmeticsEvaluator.g4 | 8 ++++---- .../src/commonMain/kotlin/scientifik/kmath/ast/parser.kt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/kmath-ast/reference/ArithmeticsEvaluator.g4 b/kmath-ast/reference/ArithmeticsEvaluator.g4 index 137d42860..ba8166bc8 100644 --- a/kmath-ast/reference/ArithmeticsEvaluator.g4 +++ b/kmath-ast/reference/ArithmeticsEvaluator.g4 @@ -2,11 +2,11 @@ grammar ArithmeticsEvaluator; fragment DIGIT: '0'..'9'; fragment LETTER: 'a'..'z'; -fragment CAPITAL_LETTER: 'A'..'Z' +fragment CAPITAL_LETTER: 'A'..'Z'; fragment UNDERSCORE: '_'; ID: (LETTER | UNDERSCORE | CAPITAL_LETTER) (LETTER | UNDERSCORE | DIGIT | CAPITAL_LETTER)*; -NUM: (DIGIT | '.')+ ([eE] MINUS? DIGIT+)?; +NUM: (DIGIT | '.')+ ([eE] (MINUS? | PLUS?) DIGIT+)?; MUL: '*'; DIV: '/'; PLUS: '+'; @@ -17,7 +17,7 @@ LPAR: '('; RPAR: ')'; WS: [ \n\t\r]+ -> skip; -number +num : NUM ; @@ -34,7 +34,7 @@ binaryFunction ; term - : number + : num | singular | unaryFunction | binaryFunction 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 27f133d6a..a0b729ffe 100644 --- a/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/parser.kt +++ b/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/parser.kt @@ -18,7 +18,7 @@ import scientifik.kmath.operations.SpaceOperations * TODO move to common */ object ArithmeticsEvaluator : Grammar() { - private val num: Token by token("[\\d.]+(?:[eE]-?\\d+)?".toRegex()) + 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())