mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 12:50:55 +00:00
Cleanup TokenType
This commit is contained in:
parent
ef4045ecb4
commit
f1645d0924
@ -2,7 +2,7 @@ package gay.pizza.pork.eval
|
||||
|
||||
import gay.pizza.pork.ast.*
|
||||
|
||||
class Evaluator(root: Scope) : Visitor<Any> {
|
||||
class PorkEvaluator(root: Scope) : Visitor<Any> {
|
||||
private var currentScope: Scope = root
|
||||
|
||||
override fun visitDefine(node: Define): Any {
|
@ -2,7 +2,7 @@ package gay.pizza.pork
|
||||
|
||||
import gay.pizza.pork.ast.*
|
||||
import gay.pizza.pork.eval.Scope
|
||||
import gay.pizza.pork.eval.Evaluator
|
||||
import gay.pizza.pork.eval.PorkEvaluator
|
||||
import gay.pizza.pork.parse.*
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.readText
|
||||
@ -10,7 +10,7 @@ import kotlin.io.path.readText
|
||||
fun main(args: Array<String>) {
|
||||
fun eval(ast: Program) {
|
||||
val scope = Scope()
|
||||
val evaluator = Evaluator(scope)
|
||||
val evaluator = PorkEvaluator(scope)
|
||||
evaluator.visit(ast)
|
||||
println("> ${scope.call("main")}")
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class PorkTokenizer(val source: CharSource) {
|
||||
tokenStart = source.currentIndex
|
||||
val char = source.next()
|
||||
for (item in TokenType.SingleChars) {
|
||||
if (item.singleChar == char) {
|
||||
if (item.char == char) {
|
||||
return Token(item, char.toString())
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,27 @@
|
||||
package gay.pizza.pork.parse
|
||||
|
||||
enum class TokenType(val singleChar: Char? = null, val keyword: String? = null) {
|
||||
enum class TokenType(val char: Char? = null, val keyword: String? = null) {
|
||||
Symbol,
|
||||
IntLiteral,
|
||||
Equals(singleChar = '='),
|
||||
Plus(singleChar = '+'),
|
||||
Minus(singleChar = '-'),
|
||||
Multiply(singleChar = '*'),
|
||||
Divide(singleChar = '/'),
|
||||
LeftCurly(singleChar = '{'),
|
||||
RightCurly(singleChar = '}'),
|
||||
LeftBracket(singleChar = '['),
|
||||
RightBracket(singleChar = ']'),
|
||||
LeftParentheses(singleChar = '('),
|
||||
RightParentheses(singleChar = ')'),
|
||||
Comma(singleChar = ','),
|
||||
Equals(char = '='),
|
||||
Plus(char = '+'),
|
||||
Minus(char = '-'),
|
||||
Multiply(char = '*'),
|
||||
Divide(char = '/'),
|
||||
LeftCurly(char = '{'),
|
||||
RightCurly(char = '}'),
|
||||
LeftBracket(char = '['),
|
||||
RightBracket(char = ']'),
|
||||
LeftParentheses(char = '('),
|
||||
RightParentheses(char = ')'),
|
||||
Comma(char = ','),
|
||||
False(keyword = "false"),
|
||||
True(keyword = "true"),
|
||||
In(keyword = "in"),
|
||||
EndOfFile;
|
||||
|
||||
companion object {
|
||||
val Keywords = entries.filter { it.keyword != null }
|
||||
val SingleChars = entries.filter { it.singleChar != null }
|
||||
val SingleChars = entries.filter { it.char != null }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user