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/Lexical.kt | |
parent | cc8c02d780f703e0ea547e79dacf6a571686e1df (diff) |
Added linenumber logging
Diffstat (limited to 'src/runMain/kotlin/Lexical.kt')
-rw-r--r-- | src/runMain/kotlin/Lexical.kt | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/runMain/kotlin/Lexical.kt b/src/runMain/kotlin/Lexical.kt index 0d37065..4452235 100644 --- a/src/runMain/kotlin/Lexical.kt +++ b/src/runMain/kotlin/Lexical.kt @@ -7,20 +7,23 @@ class Lexical { */ fun analyze(source: String): MutableList<MutableList<Token>> { var buffer = "" + var lineNumber = 1 var skipStatementEnd = false var statementEnd: Boolean val statements = mutableListOf<MutableList<Token>>() val currentStatement = mutableListOf<Token>() for (i in source.indices) { - buffer += source[i] if (source[i] == '"') skipStatementEnd = !skipStatementEnd + if (source[i] == '\n') lineNumber++ statementEnd = source[i] == ';' && !skipStatementEnd + buffer += source[i] + val tokenType = getTokenType(buffer, if (source.length > i + 1) source[i + 1] else ' ') if (tokenType != Skip && !statementEnd) { val newToken = Token() newToken.content = buffer newToken.type = tokenType - newToken.lineNumber = 1 + newToken.lineNumber = lineNumber currentStatement.add(newToken) buffer = "" } else if (statementEnd) { @@ -80,5 +83,5 @@ class Lexical { private val punctuation = listOf(",", ":", ".", ";") private val brackets = listOf("(", ")", "[", "]", "{", "}") // TODO: Use brackets for functions private val classifier = listOf("\"", "'") - private val emptiness = listOf(" ", "\t") + private val emptiness = listOf(" ", "\t", "\n") } |