Rewrite parser in Kotlin