mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-10-10 16:19:37 +00:00
Fix attribution of tokens.
This commit is contained in:
27
src/main/kotlin/gay/pizza/pork/cli/AttributeCommand.kt
Normal file
27
src/main/kotlin/gay/pizza/pork/cli/AttributeCommand.kt
Normal file
@ -0,0 +1,27 @@
|
||||
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.NodeCoalescer
|
||||
import gay.pizza.pork.frontend.FileFrontend
|
||||
import gay.pizza.pork.parse.TokenNodeAttribution
|
||||
|
||||
class AttributeCommand : CliktCommand(help = "Attribute AST", name = "attribute") {
|
||||
val path by argument("file").path(mustExist = true, canBeDir = false)
|
||||
|
||||
override fun run() {
|
||||
val frontend = FileFrontend(path)
|
||||
val attribution = TokenNodeAttribution()
|
||||
val program = frontend.parse(attribution)
|
||||
|
||||
val coalescer = NodeCoalescer { node ->
|
||||
val tokens = attribution.assembleTokens(node)
|
||||
println("node ${node.toString().replace("\n", "^")}")
|
||||
for (token in tokens) {
|
||||
println("token $token")
|
||||
}
|
||||
}
|
||||
coalescer.visit(program)
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ class RootCommand : CliktCommand(
|
||||
TokenizeCommand(),
|
||||
ReprintCommand(),
|
||||
AstCommand(),
|
||||
AttributeCommand(),
|
||||
GenerateKotlinCommand(),
|
||||
GenerateDartCommand()
|
||||
)
|
||||
|
Reference in New Issue
Block a user