mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-17 20:01:31 +00:00
language: var, reassign, comparison operators
This commit is contained in:
@ -14,5 +14,9 @@ enum class InfixOperator(val token: String) {
|
||||
Equals("=="),
|
||||
NotEquals("!="),
|
||||
EuclideanModulo("mod"),
|
||||
Remainder("rem")
|
||||
Remainder("rem"),
|
||||
Lesser("<"),
|
||||
Greater(">"),
|
||||
GreaterEqual(">="),
|
||||
LesserEqual("<=")
|
||||
}
|
||||
|
@ -53,6 +53,9 @@ class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
|
||||
override fun visitPrefixOperation(node: PrefixOperation): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitSetAssignment(node: SetAssignment): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitStringLiteral(node: StringLiteral): Unit =
|
||||
handle(node)
|
||||
|
||||
@ -62,6 +65,9 @@ class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
|
||||
override fun visitSymbolReference(node: SymbolReference): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitVarAssignment(node: VarAssignment): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitWhile(node: While): Unit =
|
||||
handle(node)
|
||||
|
||||
|
@ -23,8 +23,10 @@ enum class NodeType(val parent: NodeType? = null) {
|
||||
Native(Node),
|
||||
Parentheses(Expression),
|
||||
PrefixOperation(Expression),
|
||||
SetAssignment(Expression),
|
||||
StringLiteral(Expression),
|
||||
Symbol(Node),
|
||||
SymbolReference(Expression),
|
||||
VarAssignment(Expression),
|
||||
While(Expression)
|
||||
}
|
||||
|
@ -36,11 +36,15 @@ interface NodeVisitor<T> {
|
||||
|
||||
fun visitPrefixOperation(node: PrefixOperation): T
|
||||
|
||||
fun visitSetAssignment(node: SetAssignment): T
|
||||
|
||||
fun visitStringLiteral(node: StringLiteral): T
|
||||
|
||||
fun visitSymbol(node: Symbol): T
|
||||
|
||||
fun visitSymbolReference(node: SymbolReference): T
|
||||
|
||||
fun visitVarAssignment(node: VarAssignment): T
|
||||
|
||||
fun visitWhile(node: While): T
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ fun <T> NodeVisitor<T>.visit(node: Node): T =
|
||||
is Block -> visitBlock(node)
|
||||
is CompilationUnit -> visitCompilationUnit(node)
|
||||
is LetAssignment -> visitLetAssignment(node)
|
||||
is VarAssignment -> visitVarAssignment(node)
|
||||
is SetAssignment -> visitSetAssignment(node)
|
||||
is InfixOperation -> visitInfixOperation(node)
|
||||
is BooleanLiteral -> visitBooleanLiteral(node)
|
||||
is FunctionCall -> visitFunctionCall(node)
|
||||
|
29
ast/src/main/kotlin/gay/pizza/pork/ast/SetAssignment.kt
Normal file
29
ast/src/main/kotlin/gay/pizza/pork/ast/SetAssignment.kt
Normal file
@ -0,0 +1,29 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("setAssignment")
|
||||
class SetAssignment(val symbol: Symbol, val value: Expression) : Expression() {
|
||||
override val type: NodeType = NodeType.SetAssignment
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(symbol, value)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitSetAssignment(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is SetAssignment) return false
|
||||
return other.symbol == symbol && other.value == value
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = symbol.hashCode()
|
||||
result = 31 * result + value.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
29
ast/src/main/kotlin/gay/pizza/pork/ast/VarAssignment.kt
Normal file
29
ast/src/main/kotlin/gay/pizza/pork/ast/VarAssignment.kt
Normal file
@ -0,0 +1,29 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("varAssignment")
|
||||
class VarAssignment(val symbol: Symbol, val value: Expression) : Expression() {
|
||||
override val type: NodeType = NodeType.VarAssignment
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(symbol, value)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitVarAssignment(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is VarAssignment) return false
|
||||
return other.symbol == symbol && other.value == value
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = symbol.hashCode()
|
||||
result = 31 * result + value.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user