mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 05:10:55 +00:00
Add reprint command to regenerate program from AST.
This commit is contained in:
parent
1445490770
commit
05cb52bc32
22
src/main/kotlin/gay/pizza/pork/cli/ReprintCommand.kt
Normal file
22
src/main/kotlin/gay/pizza/pork/cli/ReprintCommand.kt
Normal file
@ -0,0 +1,22 @@
|
||||
package gay.pizza.pork.cli
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.parameters.arguments.argument
|
||||
import com.github.ajalt.clikt.parameters.types.path
|
||||
import gay.pizza.pork.ast.Printer
|
||||
import gay.pizza.pork.parse.PorkParser
|
||||
import gay.pizza.pork.parse.PorkTokenizer
|
||||
import gay.pizza.pork.parse.StringCharSource
|
||||
import gay.pizza.pork.parse.TokenStreamSource
|
||||
import kotlin.io.path.readText
|
||||
|
||||
class ReprintCommand : CliktCommand(help = "Reprint Parsed Program", name = "reprint") {
|
||||
val path by argument("file").path(mustExist = true, canBeDir = false)
|
||||
|
||||
override fun run() {
|
||||
val content = path.readText()
|
||||
val tokenStream = PorkTokenizer(StringCharSource(content)).tokenize()
|
||||
val program = PorkParser(TokenStreamSource(tokenStream)).readProgram()
|
||||
print(buildString { Printer(this).visit(program) })
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ class RootCommand : CliktCommand(
|
||||
RunCommand(),
|
||||
HighlightCommand(),
|
||||
TokenizeCommand(),
|
||||
ReprintCommand(),
|
||||
GenerateKotlinCommand()
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user