diff options
author | Marvin Borner | 2019-08-15 22:49:57 +0200 |
---|---|---|
committer | Marvin Borner | 2019-08-15 22:49:57 +0200 |
commit | c4f53cfabe7efc987916d3a7a40e81cb85ae9193 (patch) | |
tree | 44b5eb0177bde3aebf9fe4b0733cb8c37bd56bd5 /src/runMain/kotlin/Syntax.kt | |
parent | cc8c02d780f703e0ea547e79dacf6a571686e1df (diff) |
Added linenumber logging
Diffstat (limited to 'src/runMain/kotlin/Syntax.kt')
-rw-r--r-- | src/runMain/kotlin/Syntax.kt | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/runMain/kotlin/Syntax.kt b/src/runMain/kotlin/Syntax.kt index 938814d..8ba809c 100644 --- a/src/runMain/kotlin/Syntax.kt +++ b/src/runMain/kotlin/Syntax.kt @@ -13,16 +13,16 @@ class Syntax { statement.forEach { println("${it.content} ${it.type}") } statement.forEachIndexed { j, token -> if (statement.count { it.content == "(" } != statement.count { it.content == ")" }) - throw SyntaxError("Bracket", "Brackets are not even") + throw SyntaxError("Bracket", "Brackets are not even", token.lineNumber) when (token.type) { Keyword -> allowNext(statement, j, listOf(Bracket)) Function -> allowNext(statement, j, listOf(Bracket)) Constant -> allowNext(statement, j, listOf(Comparison, Arithmetic, Logical, Bracket)) - Assignment -> allowNext(statement, j, listOf(Constant, Function)) - Arithmetic -> allowNext(statement, j, listOf(Constant, Function)) - Comparison -> allowNext(statement, j, listOf(Constant, Function)) - Logical -> allowNext(statement, j, listOf(Constant, Function)) + Assignment -> allowNext(statement, j, listOf(Constant, Function, Variable)) + Arithmetic -> allowNext(statement, j, listOf(Constant, Function, Variable)) + Comparison -> allowNext(statement, j, listOf(Constant, Function, Variable)) + Logical -> allowNext(statement, j, listOf(Constant, Function, Variable)) Variable -> allowNext(statement, j, listOf(Assignment, Bracket, Arithmetic, Logical, Comparison)) Punctuation -> allowNext(statement, j, listOf(Constant)) Bracket -> allowNext(statement, j, listOf(Constant, Keyword, Logical, Assignment, Variable)) @@ -82,7 +82,7 @@ class Syntax { private fun allowNext(statement: MutableList<Token>, index: kotlin.Int, allowed: List<TokenType>) { if (statement.size > index + 1 && nextNonEmpty(statement, index).type !in allowed) { val token = nextNonEmpty(statement, index) - throw SyntaxError(token.type.toString(), token.content) + throw SyntaxError(token.type.toString(), token.content, token.lineNumber) } } |