diff --git a/src/main/kotlin/gay/pizza/pork/ast/NodeTypeTrait.kt b/src/main/kotlin/gay/pizza/pork/ast/NodeTypeTrait.kt deleted file mode 100644 index 3e1d4d6..0000000 --- a/src/main/kotlin/gay/pizza/pork/ast/NodeTypeTrait.kt +++ /dev/null @@ -1,7 +0,0 @@ -package gay.pizza.pork.ast - -enum class NodeTypeTrait { - Intermediate, - Operation, - Literal -} diff --git a/src/main/kotlin/gay/pizza/pork/cli/AstCommand.kt b/src/main/kotlin/gay/pizza/pork/cli/AstCommand.kt index 3c3a547..8696f74 100644 --- a/src/main/kotlin/gay/pizza/pork/cli/AstCommand.kt +++ b/src/main/kotlin/gay/pizza/pork/cli/AstCommand.kt @@ -4,7 +4,6 @@ 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.nodes.Node -import gay.pizza.pork.frontend.FileFrontend import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json @@ -19,7 +18,7 @@ class AstCommand : CliktCommand(help = "Print AST", name = "ast") { } override fun run() { - val frontend = FileFrontend(path) - println(json.encodeToString(Node.serializer(), frontend.parse())) + val tool = FileTool(path) + println(json.encodeToString(Node.serializer(), tool.parse())) } } diff --git a/src/main/kotlin/gay/pizza/pork/cli/AttributeCommand.kt b/src/main/kotlin/gay/pizza/pork/cli/AttributeCommand.kt index 824e78f..60d7179 100644 --- a/src/main/kotlin/gay/pizza/pork/cli/AttributeCommand.kt +++ b/src/main/kotlin/gay/pizza/pork/cli/AttributeCommand.kt @@ -4,16 +4,15 @@ 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 tool = FileTool(path) val attribution = TokenNodeAttribution() - val compilationUnit = frontend.parse(attribution) + val compilationUnit = tool.parse(attribution) val coalescer = NodeCoalescer { node -> val tokens = attribution.assembleTokens(node) diff --git a/src/main/kotlin/gay/pizza/pork/frontend/FileFrontend.kt b/src/main/kotlin/gay/pizza/pork/cli/FileTool.kt similarity index 81% rename from src/main/kotlin/gay/pizza/pork/frontend/FileFrontend.kt rename to src/main/kotlin/gay/pizza/pork/cli/FileTool.kt index 9f831a2..2437257 100644 --- a/src/main/kotlin/gay/pizza/pork/frontend/FileFrontend.kt +++ b/src/main/kotlin/gay/pizza/pork/cli/FileTool.kt @@ -1,11 +1,11 @@ -package gay.pizza.pork.frontend +package gay.pizza.pork.cli import gay.pizza.pork.parse.CharSource import gay.pizza.pork.parse.StringCharSource import java.nio.file.Path import kotlin.io.path.readText -class FileFrontend(val path: Path) : Frontend() { +class FileTool(val path: Path) : Tool() { override fun createCharSource(): CharSource = StringCharSource(path.readText()) override fun resolveImportSource(path: String): CharSource = StringCharSource(this.path.parent.resolve(path).readText()) diff --git a/src/main/kotlin/gay/pizza/pork/cli/HighlightCommand.kt b/src/main/kotlin/gay/pizza/pork/cli/HighlightCommand.kt index e58fd92..3d28d01 100644 --- a/src/main/kotlin/gay/pizza/pork/cli/HighlightCommand.kt +++ b/src/main/kotlin/gay/pizza/pork/cli/HighlightCommand.kt @@ -3,14 +3,13 @@ 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.frontend.FileFrontend import gay.pizza.pork.parse.AnsiHighlightScheme class HighlightCommand : CliktCommand(help = "Syntax Highlighter", name = "highlight") { val path by argument("file").path(mustExist = true, canBeDir = false) override fun run() { - val frontend = FileFrontend(path) - print(frontend.highlight(AnsiHighlightScheme()).joinToString("")) + val tool = FileTool(path) + print(tool.highlight(AnsiHighlightScheme()).joinToString("")) } } diff --git a/src/main/kotlin/gay/pizza/pork/cli/ReprintCommand.kt b/src/main/kotlin/gay/pizza/pork/cli/ReprintCommand.kt index 0c1b675..9d9e04b 100644 --- a/src/main/kotlin/gay/pizza/pork/cli/ReprintCommand.kt +++ b/src/main/kotlin/gay/pizza/pork/cli/ReprintCommand.kt @@ -3,13 +3,12 @@ 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.frontend.FileFrontend class ReprintCommand : CliktCommand(help = "Reprint Parsed Compilation Unit", name = "reprint") { val path by argument("file").path(mustExist = true, canBeDir = false) override fun run() { - val frontend = FileFrontend(path) - print(frontend.reprint()) + val tool = FileTool(path) + print(tool.reprint()) } } diff --git a/src/main/kotlin/gay/pizza/pork/cli/RunCommand.kt b/src/main/kotlin/gay/pizza/pork/cli/RunCommand.kt index e606767..81caa98 100644 --- a/src/main/kotlin/gay/pizza/pork/cli/RunCommand.kt +++ b/src/main/kotlin/gay/pizza/pork/cli/RunCommand.kt @@ -6,20 +6,19 @@ import com.github.ajalt.clikt.parameters.types.path import gay.pizza.pork.eval.Arguments import gay.pizza.pork.eval.CallableFunction import gay.pizza.pork.eval.Scope -import gay.pizza.pork.frontend.FileFrontend class RunCommand : CliktCommand(help = "Run Program", name = "run") { val path by argument("file").path(mustExist = true, canBeDir = false) override fun run() { - val frontend = FileFrontend(path) + val tool = FileTool(path) val scope = Scope() scope.define("println", CallableFunction { arguments -> for (argument in arguments.values) { println(argument) } }) - frontend.evaluate(scope) + tool.evaluate(scope) scope.call("main", Arguments(emptyList())) } } diff --git a/src/main/kotlin/gay/pizza/pork/cli/TokenizeCommand.kt b/src/main/kotlin/gay/pizza/pork/cli/TokenizeCommand.kt index a99374b..0461f0b 100644 --- a/src/main/kotlin/gay/pizza/pork/cli/TokenizeCommand.kt +++ b/src/main/kotlin/gay/pizza/pork/cli/TokenizeCommand.kt @@ -3,14 +3,13 @@ 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.frontend.FileFrontend class TokenizeCommand : CliktCommand(help = "Tokenize Compilation Unit", name = "tokenize") { val path by argument("file").path(mustExist = true, canBeDir = false) override fun run() { - val frontend = FileFrontend(path) - val tokenStream = frontend.tokenize() + val tool = FileTool(path) + val tokenStream = tool.tokenize() for (token in tokenStream.tokens) { println("${token.start} ${token.type.name} '${sanitize(token.text)}'") } diff --git a/src/main/kotlin/gay/pizza/pork/frontend/Frontend.kt b/src/main/kotlin/gay/pizza/pork/cli/Tool.kt similarity index 89% rename from src/main/kotlin/gay/pizza/pork/frontend/Frontend.kt rename to src/main/kotlin/gay/pizza/pork/cli/Tool.kt index 29c10da..dda0ff1 100644 --- a/src/main/kotlin/gay/pizza/pork/frontend/Frontend.kt +++ b/src/main/kotlin/gay/pizza/pork/cli/Tool.kt @@ -1,4 +1,4 @@ -package gay.pizza.pork.frontend +package gay.pizza.pork.cli import gay.pizza.pork.ast.NodeVisitor import gay.pizza.pork.ast.Printer @@ -8,7 +8,7 @@ import gay.pizza.pork.eval.ImportLoader import gay.pizza.pork.eval.Scope import gay.pizza.pork.parse.* -abstract class Frontend { +abstract class Tool { abstract fun createCharSource(): CharSource abstract fun resolveImportSource(path: String): CharSource @@ -28,7 +28,7 @@ abstract class Frontend { fun visit(visitor: NodeVisitor): T = visitor.visit(parse()) - private class FrontendImportLoader(val frontend: Frontend) : ImportLoader { + private class FrontendImportLoader(val frontend: Tool) : ImportLoader { override fun load(path: String): CompilationUnit { val tokenStream = Tokenizer(frontend.resolveImportSource(path)).tokenize() return Parser(TokenStreamSource(tokenStream), DiscardNodeAttribution).readCompilationUnit()