mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
gradle: 8.4 and parser: lazy tokenization
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user