gradle: 8.4 and parser: lazy tokenization

This commit is contained in:
2023-10-13 08:56:04 -07:00
parent 5078f38f61
commit e96bcd8754
8 changed files with 59 additions and 11 deletions

View File

@ -4,15 +4,21 @@ import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import gay.pizza.dough.fs.PlatformFsProvider
import gay.pizza.pork.minimal.FileTool
import gay.pizza.pork.parser.TokenType
class TokenizeCommand : CliktCommand(help = "Tokenize Compilation Unit", name = "tokenize") {
val path by argument("file")
override fun run() {
val tool = FileTool(PlatformFsProvider.resolve(path))
val tokenStream = tool.tokenize()
for (token in tokenStream.tokens) {
println("${token.sourceIndex.index} ${token.type.name} '${sanitize(token.text)}'")
val tokenSource = tool.tokenize()
while (true) {
val token = tokenSource.next()
println("${token.sourceIndex} ${token.type.name} '${sanitize(token.text)}'")
tokenSource.peekTypeAhead(5)
if (token.type == TokenType.EndOfFile) {
break
}
}
}