feat(lexer): Scan empty string
This commit is contained in:
parent
4054ed5fce
commit
f72501fde2
5 changed files with 45 additions and 0 deletions
11
src/lexer/Lexer.kt
Normal file
11
src/lexer/Lexer.kt
Normal file
|
@ -0,0 +1,11 @@
|
|||
package lexer
|
||||
|
||||
class Lexer {
|
||||
fun scan(source: String): List<Token> {
|
||||
if (source.isEmpty()) {
|
||||
return listOf(Token(TokenType.EOF, LexerPosition(1, 1, 0)))
|
||||
}
|
||||
|
||||
return emptyList()
|
||||
}
|
||||
}
|
5
src/lexer/LexerPosition.kt
Normal file
5
src/lexer/LexerPosition.kt
Normal file
|
@ -0,0 +1,5 @@
|
|||
package lexer
|
||||
|
||||
class LexerPosition(val line: Int, val column: Int, val length: Int) {
|
||||
// Do nothing
|
||||
}
|
8
src/lexer/Token.kt
Normal file
8
src/lexer/Token.kt
Normal file
|
@ -0,0 +1,8 @@
|
|||
package lexer
|
||||
|
||||
class Token(
|
||||
val type: TokenType,
|
||||
val position: LexerPosition
|
||||
) {
|
||||
// Do nothing
|
||||
}
|
5
src/lexer/TokenType.kt
Normal file
5
src/lexer/TokenType.kt
Normal file
|
@ -0,0 +1,5 @@
|
|||
package lexer
|
||||
|
||||
enum class TokenType {
|
||||
EOF
|
||||
}
|
16
tests/lexer/LexerScanTest.kt
Normal file
16
tests/lexer/LexerScanTest.kt
Normal file
|
@ -0,0 +1,16 @@
|
|||
package be.ugent.logprog.lexer
|
||||
|
||||
import lexer.Lexer
|
||||
import lexer.TokenType
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class LexerScanTest {
|
||||
@Test
|
||||
fun scan_emptyString_returnsEOF() {
|
||||
val lexer = Lexer()
|
||||
val tokens = lexer.scan("")
|
||||
assertEquals(1, tokens.size)
|
||||
assertEquals(TokenType.EOF, tokens[0].type)
|
||||
}
|
||||
}
|
Reference in a new issue