mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-17 20:01:31 +00:00
language: implement list indexing
This commit is contained in:
29
ast/src/main/kotlin/gay/pizza/pork/ast/IndexedBy.kt
Normal file
29
ast/src/main/kotlin/gay/pizza/pork/ast/IndexedBy.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("indexedBy")
|
||||
class IndexedBy(val expression: Expression, val index: Expression) : Expression() {
|
||||
override val type: NodeType = NodeType.IndexedBy
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(expression, index)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitIndexedBy(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is IndexedBy) return false
|
||||
return other.expression == expression && other.index == index
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = expression.hashCode()
|
||||
result = 31 * result + index.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
@ -35,6 +35,9 @@ class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
|
||||
override fun visitImportDeclaration(node: ImportDeclaration): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitIndexedBy(node: IndexedBy): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitInfixOperation(node: InfixOperation): Unit =
|
||||
handle(node)
|
||||
|
||||
|
@ -30,6 +30,8 @@ interface NodeParser {
|
||||
|
||||
fun parseImportDeclaration(): ImportDeclaration
|
||||
|
||||
fun parseIndexedBy(): IndexedBy
|
||||
|
||||
fun parseInfixOperation(): InfixOperation
|
||||
|
||||
fun parseIntegerLiteral(): IntegerLiteral
|
||||
|
@ -34,5 +34,6 @@ fun NodeParser.parse(type: NodeType): Node =
|
||||
NodeType.Continue -> parseContinue()
|
||||
NodeType.NoneLiteral -> parseNoneLiteral()
|
||||
NodeType.Native -> parseNative()
|
||||
NodeType.IndexedBy -> parseIndexedBy()
|
||||
else -> throw RuntimeException("Unable to automatically parse type: ${type.name}")
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ enum class NodeType(val parent: NodeType? = null) {
|
||||
FunctionDefinition(Definition),
|
||||
If(Expression),
|
||||
ImportDeclaration(Declaration),
|
||||
IndexedBy(Expression),
|
||||
InfixOperation(Expression),
|
||||
IntegerLiteral(Expression),
|
||||
LetAssignment(Expression),
|
||||
|
@ -24,6 +24,8 @@ interface NodeVisitor<T> {
|
||||
|
||||
fun visitImportDeclaration(node: ImportDeclaration): T
|
||||
|
||||
fun visitIndexedBy(node: IndexedBy): T
|
||||
|
||||
fun visitInfixOperation(node: InfixOperation): T
|
||||
|
||||
fun visitIntegerLiteral(node: IntegerLiteral): T
|
||||
|
@ -31,6 +31,7 @@ fun <T> NodeVisitor<T>.visit(node: Node): T =
|
||||
is Continue -> visitContinue(node)
|
||||
is NoneLiteral -> visitNoneLiteral(node)
|
||||
is Native -> visitNative(node)
|
||||
is IndexedBy -> visitIndexedBy(node)
|
||||
}
|
||||
|
||||
fun <T> NodeVisitor<T>.visitNodes(vararg nodes: Node?): List<T> =
|
||||
|
Reference in New Issue
Block a user