aboutsummaryrefslogtreecommitdiff
path: root/src/runMain/kotlin/Lexical.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/runMain/kotlin/Lexical.kt')
-rw-r--r--src/runMain/kotlin/Lexical.kt12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/runMain/kotlin/Lexical.kt b/src/runMain/kotlin/Lexical.kt
index dbf2bad..73b15aa 100644
--- a/src/runMain/kotlin/Lexical.kt
+++ b/src/runMain/kotlin/Lexical.kt
@@ -6,19 +6,23 @@ class Lexical {
* Analyzes the given [source] and returns the tokens divided into an array of statements
* TODO: Add line number to token (abstract to class?)
*/
- fun analyze(source: String): MutableList<MutableList<Pair<String, TokenType>>> {
+ fun analyze(source: String): MutableList<MutableList<Token>> {
var buffer = ""
var skipStatementEnd = false
var statementEnd: Boolean
- val statements = mutableListOf<MutableList<Pair<String, TokenType>>>()
- val currentStatement = mutableListOf<Pair<String, TokenType>>()
+ val statements = mutableListOf<MutableList<Token>>()
+ val currentStatement = mutableListOf<Token>()
for (i in source.indices) {
buffer += 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 != Skip && !statementEnd) {
- currentStatement.add(buffer to tokenType)
+ val newToken = Token()
+ newToken.content = buffer
+ newToken.type = tokenType
+ newToken.lineNumber = 13
+ currentStatement.add(newToken)
buffer = ""
} else if (statementEnd) {
statements.add(currentStatement.toMutableList())