Lexing with Multiple States
import org.kiot.lexer.Lexer
val data = LexerData.build {
// default state is always 0
state(default) {
": " action 1
"\\w+" action 2
}
state(1) {
".+" action 3
}
}
class SimpleLexer(chars: CharSequence) : Lexer<Nothing>(data, chars) {
override fun onAction(action: Int) {
when (action) {
1 -> switchState(1)
2 -> println("word: ${string()}")
3 -> println("definition: ${string()}")
}
}
}
lexer.lex("KiotLand: A land where Kotlin lovers gather.")
/*
word: KiotLand
definition: A land where Kotlin lovers gather.
*/Last updated