commonMain.pro.felixo.protobuf.schemadocument.Token.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of protobuf-kotlin-schemadocument-jvm Show documentation
Show all versions of protobuf-kotlin-schemadocument-jvm Show documentation
Protocol Buffers 3 support for Kotlin Multiplatform
The newest version!
package pro.felixo.protobuf.schemadocument
/**
* Represents a token in a .proto file.
*/
sealed class Token {
data class Identifier(override val text: String) : Token() {
val components: List = text.split('.')
override fun toString(): String = text
}
data class NumberLiteral(override val text: String) : Token() {
val value: Int = text.toInt()
override fun toString(): String = text
}
data class StringLiteral(override val text: String) : Token() {
val value: String = text.substring(1, text.length - 1).replace("\\\"", "\"").replace("\\\\", "\\")
override fun toString(): String = text
}
object OpenBrace : Token() {
override val text: String = "{"
}
object CloseBrace : Token() {
override val text: String = "}"
}
object OpenBracket : Token() {
override val text: String = "["
}
object CloseBracket : Token() {
override val text: String = "]"
}
object OpenParen : Token() {
override val text: String = "("
}
object CloseParen : Token() {
override val text: String = ")"
}
object Semicolon : Token() {
override val text: String = ";"
}
object Equals : Token() {
override val text: String = "="
}
object Comma : Token() {
override val text: String = ","
}
abstract val text: String
override fun toString(): String = text
}