mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
Introduce the requirement of let for assignment.
This commit is contained in:
@ -4,15 +4,15 @@ import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("assignment")
|
||||
class Assignment(val symbol: Symbol, val value: Expression) : Expression() {
|
||||
override val type: NodeType = NodeType.Assignment
|
||||
@SerialName("letAssignment")
|
||||
class LetAssignment(val symbol: Symbol, val value: Expression) : Expression() {
|
||||
override val type: NodeType = NodeType.LetAssignment
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(symbol, value)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Assignment) return false
|
||||
if (other !is LetAssignment) return false
|
||||
return other.symbol == symbol && other.value == value
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
|
||||
override fun visitListLiteral(node: ListLiteral): Unit = handle(node)
|
||||
override fun visitSymbol(node: Symbol): Unit = handle(node)
|
||||
override fun visitFunctionCall(node: FunctionCall): Unit = handle(node)
|
||||
override fun visitDefine(node: Assignment): Unit = handle(node)
|
||||
override fun visitLetAssignment(node: LetAssignment): Unit = handle(node)
|
||||
override fun visitSymbolReference(node: SymbolReference): Unit = handle(node)
|
||||
override fun visitLambda(node: Lambda): Unit = handle(node)
|
||||
override fun visitParentheses(node: Parentheses): Unit = handle(node)
|
||||
|
@ -12,7 +12,7 @@ enum class NodeType(val parent: NodeType? = null) {
|
||||
ListLiteral(Expression),
|
||||
StringLiteral(Expression),
|
||||
Parentheses(Expression),
|
||||
Assignment(Expression),
|
||||
LetAssignment(Expression),
|
||||
Lambda(Expression),
|
||||
PrefixOperation(Expression),
|
||||
InfixOperation(Expression),
|
||||
|
@ -7,7 +7,7 @@ interface NodeVisitor<T> {
|
||||
fun visitListLiteral(node: ListLiteral): T
|
||||
fun visitSymbol(node: Symbol): T
|
||||
fun visitFunctionCall(node: FunctionCall): T
|
||||
fun visitDefine(node: Assignment): T
|
||||
fun visitLetAssignment(node: LetAssignment): T
|
||||
fun visitSymbolReference(node: SymbolReference): T
|
||||
fun visitLambda(node: Lambda): T
|
||||
fun visitParentheses(node: Parentheses): T
|
||||
@ -26,7 +26,7 @@ interface NodeVisitor<T> {
|
||||
is BooleanLiteral -> visitBooleanLiteral(node)
|
||||
is ListLiteral -> visitListLiteral(node)
|
||||
is FunctionCall -> visitFunctionCall(node)
|
||||
is Assignment -> visitDefine(node)
|
||||
is LetAssignment -> visitLetAssignment(node)
|
||||
is SymbolReference -> visitSymbolReference(node)
|
||||
is Lambda -> visitLambda(node)
|
||||
is Parentheses -> visitParentheses(node)
|
||||
|
Reference in New Issue
Block a user