Decimal percentages

closes #68
This commit is contained in:
sadellie 2023-07-20 22:25:15 +03:00
parent 627ce5a785
commit 4e28521ec0
2 changed files with 6 additions and 2 deletions

View File

@ -197,7 +197,7 @@ class Tokenizer(private val streamOfTokens: String) {
}
private fun List<String>.getNumberOrExpressionBefore(pos: Int): List<String> {
val digits = Token.Digit.all.map { it[0] }
val digits = Token.Digit.allWithDot.map { it[0] }
val tokenInFront = this[pos - 1]
@ -205,7 +205,7 @@ class Tokenizer(private val streamOfTokens: String) {
if (tokenInFront.all { it in digits }) return listOf(tokenInFront)
// Not just a number. Probably expression in brackets.
if (tokenInFront != Token.Operator.rightBracket) throw Exception("Unexpected token before the percentage")
if (tokenInFront != Token.Operator.rightBracket) throw Exception("Unexpected token before percentage")
// Start walking left until we get balanced brackets
var cursor = pos - 1

View File

@ -120,5 +120,9 @@ class FixLexiconTest {
)
assertLex("(80÷100)×(80÷100)", "80%80%")
assertLex("10+(2.0÷100×(10))", "10+2.0%")
assertLex("10+(2.÷100×(10))", "10+2.%")
}
}