diff options
author | Marvin Borner | 2019-08-15 00:17:29 +0200 |
---|---|---|
committer | Marvin Borner | 2019-08-15 00:17:29 +0200 |
commit | 9ebc0391be2dcf54608518361eba78708bf6d26f (patch) | |
tree | 6ebd7778f770d64455567b9b73d83cff2f1fdcc3 /src/runMain/kotlin/Lexical.kt | |
parent | 8039d51f78f7a1cb0acc74a3e8f09d4a522cf6f2 (diff) |
Added removing of padding
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 7cd66af..459927c 100644 --- a/src/runMain/kotlin/Lexical.kt +++ b/src/runMain/kotlin/Lexical.kt @@ -3,12 +3,14 @@ import exceptions.* class Lexical { fun analyze(source: String): MutableList<MutableList<Pair<String, TokenType>>> { var buffer = "" + var skipStatementEnd = false var statementEnd: Boolean val statements = mutableListOf<MutableList<Pair<String, TokenType>>>() val currentStatement = mutableListOf<Pair<String, TokenType>>() for (i in source.indices) { buffer += source[i] - statementEnd = source[i] == ';' + if (source[i] == '"') skipStatementEnd = !skipStatementEnd + statementEnd = source[i] == ';' && !skipStatementEnd val tokenType = getTokenType(buffer, if (source.length > i + 1) source[i + 1] else ' ') if (tokenType != TokenType.Skip && !statementEnd) { currentStatement.add(buffer to tokenType) @@ -48,8 +50,8 @@ class Lexical { (token + next).matches(Regex("[0-9]*")) -> TokenType.Skip token.matches(Regex("[0-9]*")) -> TokenType.Constant - token.contains(" ") && token.length > 1 -> throw UnknownType(token) - token == " " -> TokenType.Empty + token in emptiness && token.length > 1 -> throw UnknownType(token) + token in emptiness -> TokenType.Empty token in punctuation -> TokenType.Punctuation @@ -69,4 +71,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") } |