mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-17 20:01:31 +00:00
language: implement let definitions
This commit is contained in:
30
ast/src/main/kotlin/gay/pizza/pork/ast/LetDefinition.kt
Normal file
30
ast/src/main/kotlin/gay/pizza/pork/ast/LetDefinition.kt
Normal file
@ -0,0 +1,30 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("letDefinition")
|
||||
class LetDefinition(override val modifiers: DefinitionModifiers, override val symbol: Symbol, val value: Expression) : Definition() {
|
||||
override val type: NodeType = NodeType.LetDefinition
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(symbol, value)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitLetDefinition(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is LetDefinition) return false
|
||||
return other.modifiers == modifiers && other.symbol == symbol && other.value == value
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = modifiers.hashCode()
|
||||
result = 31 * result + symbol.hashCode()
|
||||
result = 31 * result + value.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
@ -41,6 +41,9 @@ class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
|
||||
override fun visitLetAssignment(node: LetAssignment): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitLetDefinition(node: LetDefinition): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitListLiteral(node: ListLiteral): Unit =
|
||||
handle(node)
|
||||
|
||||
|
@ -19,6 +19,7 @@ enum class NodeType(val parent: NodeType? = null) {
|
||||
InfixOperation(Expression),
|
||||
IntegerLiteral(Expression),
|
||||
LetAssignment(Expression),
|
||||
LetDefinition(Definition),
|
||||
ListLiteral(Expression),
|
||||
Native(Node),
|
||||
Parentheses(Expression),
|
||||
|
@ -28,6 +28,8 @@ interface NodeVisitor<T> {
|
||||
|
||||
fun visitLetAssignment(node: LetAssignment): T
|
||||
|
||||
fun visitLetDefinition(node: LetDefinition): T
|
||||
|
||||
fun visitListLiteral(node: ListLiteral): T
|
||||
|
||||
fun visitNative(node: Native): T
|
||||
|
@ -13,6 +13,7 @@ fun <T> NodeVisitor<T>.visit(node: Node): T =
|
||||
is BooleanLiteral -> visitBooleanLiteral(node)
|
||||
is FunctionCall -> visitFunctionCall(node)
|
||||
is FunctionDefinition -> visitFunctionDefinition(node)
|
||||
is LetDefinition -> visitLetDefinition(node)
|
||||
is If -> visitIf(node)
|
||||
is ImportDeclaration -> visitImportDeclaration(node)
|
||||
is IntegerLiteral -> visitIntegerLiteral(node)
|
||||
|
Reference in New Issue
Block a user