mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 21:21:33 +00:00
implement support for setting indexed values
This commit is contained in:
@ -59,13 +59,22 @@ types:
|
||||
type: Expression
|
||||
- name: typeSpec
|
||||
type: TypeSpec?
|
||||
SetAssignment:
|
||||
SymbolSetAssignment:
|
||||
parent: Expression
|
||||
values:
|
||||
- name: symbol
|
||||
type: Symbol
|
||||
- name: value
|
||||
type: Expression
|
||||
IndexedSetAssignment:
|
||||
parent: Expression
|
||||
values:
|
||||
- name: target
|
||||
type: Expression
|
||||
- name: index
|
||||
type: Expression
|
||||
- name: value
|
||||
type: Expression
|
||||
InfixOperator:
|
||||
values:
|
||||
- name: token
|
||||
|
@ -10,7 +10,8 @@ digraph A {
|
||||
type_CompilationUnit [shape=box,label="CompilationUnit"]
|
||||
type_LetAssignment [shape=box,label="LetAssignment"]
|
||||
type_VarAssignment [shape=box,label="VarAssignment"]
|
||||
type_SetAssignment [shape=box,label="SetAssignment"]
|
||||
type_SymbolSetAssignment [shape=box,label="SymbolSetAssignment"]
|
||||
type_IndexedSetAssignment [shape=box,label="IndexedSetAssignment"]
|
||||
type_InfixOperator [shape=box,label="InfixOperator"]
|
||||
type_InfixOperation [shape=box,label="InfixOperation"]
|
||||
type_BooleanLiteral [shape=box,label="BooleanLiteral"]
|
||||
@ -57,7 +58,8 @@ digraph A {
|
||||
type_Node -> type_NativeTypeDescriptor
|
||||
type_Expression -> type_LetAssignment
|
||||
type_Expression -> type_VarAssignment
|
||||
type_Expression -> type_SetAssignment
|
||||
type_Expression -> type_SymbolSetAssignment
|
||||
type_Expression -> type_IndexedSetAssignment
|
||||
type_Expression -> type_InfixOperation
|
||||
type_Expression -> type_BooleanLiteral
|
||||
type_Expression -> type_FunctionCall
|
||||
@ -94,8 +96,9 @@ digraph A {
|
||||
type_VarAssignment -> type_Symbol [style=dotted]
|
||||
type_VarAssignment -> type_Expression [style=dotted]
|
||||
type_VarAssignment -> type_TypeSpec [style=dotted]
|
||||
type_SetAssignment -> type_Symbol [style=dotted]
|
||||
type_SetAssignment -> type_Expression [style=dotted]
|
||||
type_SymbolSetAssignment -> type_Symbol [style=dotted]
|
||||
type_SymbolSetAssignment -> type_Expression [style=dotted]
|
||||
type_IndexedSetAssignment -> type_Expression [style=dotted]
|
||||
type_InfixOperation -> type_Expression [style=dotted]
|
||||
type_InfixOperation -> type_InfixOperator [style=dotted]
|
||||
type_FunctionCall -> type_Symbol [style=dotted]
|
||||
|
@ -0,0 +1,30 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast.gen
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("indexedSetAssignment")
|
||||
class IndexedSetAssignment(val target: Expression, val index: Expression, val value: Expression) : Expression() {
|
||||
override val type: NodeType = NodeType.IndexedSetAssignment
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(target, index, value)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitIndexedSetAssignment(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is IndexedSetAssignment) return false
|
||||
return other.target == target && other.index == index && other.value == value
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = target.hashCode()
|
||||
result = 31 * result + index.hashCode()
|
||||
result = 31 * result + value.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
@ -47,6 +47,9 @@ class NodeCoalescer(val followChildren: Boolean = true, val handler: (Node) -> U
|
||||
override fun visitIndexedBy(node: IndexedBy): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitIndexedSetAssignment(node: IndexedSetAssignment): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitInfixOperation(node: InfixOperation): Unit =
|
||||
handle(node)
|
||||
|
||||
@ -83,9 +86,6 @@ class NodeCoalescer(val followChildren: Boolean = true, val handler: (Node) -> U
|
||||
override fun visitReturn(node: Return): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitSetAssignment(node: SetAssignment): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitStringLiteral(node: StringLiteral): Unit =
|
||||
handle(node)
|
||||
|
||||
@ -98,6 +98,9 @@ class NodeCoalescer(val followChildren: Boolean = true, val handler: (Node) -> U
|
||||
override fun visitSymbolReference(node: SymbolReference): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitSymbolSetAssignment(node: SymbolSetAssignment): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitTypeDefinition(node: TypeDefinition): Unit =
|
||||
handle(node)
|
||||
|
||||
|
@ -38,6 +38,8 @@ interface NodeParser {
|
||||
|
||||
fun parseIndexedBy(): IndexedBy
|
||||
|
||||
fun parseIndexedSetAssignment(): IndexedSetAssignment
|
||||
|
||||
fun parseInfixOperation(): InfixOperation
|
||||
|
||||
fun parseIntegerLiteral(): IntegerLiteral
|
||||
@ -62,8 +64,6 @@ interface NodeParser {
|
||||
|
||||
fun parseReturn(): Return
|
||||
|
||||
fun parseSetAssignment(): SetAssignment
|
||||
|
||||
fun parseStringLiteral(): StringLiteral
|
||||
|
||||
fun parseSuffixOperation(): SuffixOperation
|
||||
@ -72,6 +72,8 @@ interface NodeParser {
|
||||
|
||||
fun parseSymbolReference(): SymbolReference
|
||||
|
||||
fun parseSymbolSetAssignment(): SymbolSetAssignment
|
||||
|
||||
fun parseTypeDefinition(): TypeDefinition
|
||||
|
||||
fun parseTypeSpec(): TypeSpec
|
||||
|
@ -12,7 +12,8 @@ fun NodeParser.parse(type: NodeType): Node =
|
||||
NodeType.CompilationUnit -> parseCompilationUnit()
|
||||
NodeType.LetAssignment -> parseLetAssignment()
|
||||
NodeType.VarAssignment -> parseVarAssignment()
|
||||
NodeType.SetAssignment -> parseSetAssignment()
|
||||
NodeType.SymbolSetAssignment -> parseSymbolSetAssignment()
|
||||
NodeType.IndexedSetAssignment -> parseIndexedSetAssignment()
|
||||
NodeType.InfixOperation -> parseInfixOperation()
|
||||
NodeType.BooleanLiteral -> parseBooleanLiteral()
|
||||
NodeType.FunctionCall -> parseFunctionCall()
|
||||
|
@ -21,6 +21,7 @@ enum class NodeType(val parent: NodeType? = null) {
|
||||
ImportDeclaration(Declaration),
|
||||
ImportPath(Node),
|
||||
IndexedBy(Expression),
|
||||
IndexedSetAssignment(Expression),
|
||||
InfixOperation(Expression),
|
||||
IntegerLiteral(Expression),
|
||||
LetAssignment(Expression),
|
||||
@ -33,11 +34,11 @@ enum class NodeType(val parent: NodeType? = null) {
|
||||
Parentheses(Expression),
|
||||
PrefixOperation(Expression),
|
||||
Return(Expression),
|
||||
SetAssignment(Expression),
|
||||
StringLiteral(Expression),
|
||||
SuffixOperation(Expression),
|
||||
Symbol(Node),
|
||||
SymbolReference(Expression),
|
||||
SymbolSetAssignment(Expression),
|
||||
TypeDefinition(Definition),
|
||||
TypeSpec(Node),
|
||||
VarAssignment(Expression),
|
||||
|
@ -32,6 +32,8 @@ interface NodeVisitor<T> {
|
||||
|
||||
fun visitIndexedBy(node: IndexedBy): T
|
||||
|
||||
fun visitIndexedSetAssignment(node: IndexedSetAssignment): T
|
||||
|
||||
fun visitInfixOperation(node: InfixOperation): T
|
||||
|
||||
fun visitIntegerLiteral(node: IntegerLiteral): T
|
||||
@ -56,8 +58,6 @@ interface NodeVisitor<T> {
|
||||
|
||||
fun visitReturn(node: Return): T
|
||||
|
||||
fun visitSetAssignment(node: SetAssignment): T
|
||||
|
||||
fun visitStringLiteral(node: StringLiteral): T
|
||||
|
||||
fun visitSuffixOperation(node: SuffixOperation): T
|
||||
@ -66,6 +66,8 @@ interface NodeVisitor<T> {
|
||||
|
||||
fun visitSymbolReference(node: SymbolReference): T
|
||||
|
||||
fun visitSymbolSetAssignment(node: SymbolSetAssignment): T
|
||||
|
||||
fun visitTypeDefinition(node: TypeDefinition): T
|
||||
|
||||
fun visitTypeSpec(node: TypeSpec): T
|
||||
|
@ -9,7 +9,8 @@ fun <T> NodeVisitor<T>.visit(node: Node): T =
|
||||
is CompilationUnit -> visitCompilationUnit(node)
|
||||
is LetAssignment -> visitLetAssignment(node)
|
||||
is VarAssignment -> visitVarAssignment(node)
|
||||
is SetAssignment -> visitSetAssignment(node)
|
||||
is SymbolSetAssignment -> visitSymbolSetAssignment(node)
|
||||
is IndexedSetAssignment -> visitIndexedSetAssignment(node)
|
||||
is InfixOperation -> visitInfixOperation(node)
|
||||
is BooleanLiteral -> visitBooleanLiteral(node)
|
||||
is FunctionCall -> visitFunctionCall(node)
|
||||
|
@ -5,18 +5,18 @@ 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
|
||||
@SerialName("symbolSetAssignment")
|
||||
class SymbolSetAssignment(val symbol: Symbol, val value: Expression) : Expression() {
|
||||
override val type: NodeType = NodeType.SymbolSetAssignment
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(symbol, value)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitSetAssignment(this)
|
||||
visitor.visitSymbolSetAssignment(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is SetAssignment) return false
|
||||
if (other !is SymbolSetAssignment) return false
|
||||
return other.symbol == symbol && other.value == value
|
||||
}
|
||||
|
Reference in New Issue
Block a user