Files
pork/tool/src/main/kotlin/gay/pizza/pork/tool/TokenizeCommand.kt

24 lines
723 B
Kotlin
Raw Normal View History

2023-09-04 01:56:24 -07:00
package gay.pizza.pork.tool
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import gay.pizza.dough.fs.PlatformFsProvider
2023-09-11 02:34:28 -04:00
import gay.pizza.pork.minimal.FileTool
2023-09-02 20:22:08 -07:00
class TokenizeCommand : CliktCommand(help = "Tokenize Compilation Unit", name = "tokenize") {
val path by argument("file")
override fun run() {
val tool = FileTool(PlatformFsProvider.resolve(path))
2023-09-03 01:11:27 -07:00
val tokenStream = tool.tokenize()
for (token in tokenStream.tokens) {
println("${token.sourceIndex.index} ${token.type.name} '${sanitize(token.text)}'")
}
}
private fun sanitize(input: String): String =
input
.replace("\n", "\\n")
.replace("\r", "\\r")
}