mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-17 20:01:31 +00:00
language: add unary plus & minus, post increment & decrement operators, non-newline print builtin. fix block comments (#4)
This commit is contained in:
@ -59,6 +59,9 @@ class NodeCoalescer(val handler: (Node) -> Unit) : NodeVisitor<Unit> {
|
||||
override fun visitStringLiteral(node: StringLiteral): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitSuffixOperation(node: SuffixOperation): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitSymbol(node: Symbol): Unit =
|
||||
handle(node)
|
||||
|
||||
|
@ -25,6 +25,7 @@ enum class NodeType(val parent: NodeType? = null) {
|
||||
PrefixOperation(Expression),
|
||||
SetAssignment(Expression),
|
||||
StringLiteral(Expression),
|
||||
SuffixOperation(Expression),
|
||||
Symbol(Node),
|
||||
SymbolReference(Expression),
|
||||
VarAssignment(Expression),
|
||||
|
@ -40,6 +40,8 @@ interface NodeVisitor<T> {
|
||||
|
||||
fun visitStringLiteral(node: StringLiteral): T
|
||||
|
||||
fun visitSuffixOperation(node: SuffixOperation): T
|
||||
|
||||
fun visitSymbol(node: Symbol): T
|
||||
|
||||
fun visitSymbolReference(node: SymbolReference): T
|
||||
|
@ -20,6 +20,7 @@ fun <T> NodeVisitor<T>.visit(node: Node): T =
|
||||
is ListLiteral -> visitListLiteral(node)
|
||||
is Parentheses -> visitParentheses(node)
|
||||
is PrefixOperation -> visitPrefixOperation(node)
|
||||
is SuffixOperation -> visitSuffixOperation(node)
|
||||
is StringLiteral -> visitStringLiteral(node)
|
||||
is SymbolReference -> visitSymbolReference(node)
|
||||
is While -> visitWhile(node)
|
||||
|
@ -7,5 +7,7 @@ import kotlinx.serialization.Serializable
|
||||
@Serializable
|
||||
@SerialName("prefixOperator")
|
||||
enum class PrefixOperator(val token: String) {
|
||||
Negate("!")
|
||||
Negate("!"),
|
||||
UnaryPlus("+"),
|
||||
UnaryMinus("-")
|
||||
}
|
||||
|
29
ast/src/main/kotlin/gay/pizza/pork/ast/SuffixOperation.kt
Normal file
29
ast/src/main/kotlin/gay/pizza/pork/ast/SuffixOperation.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("suffixOperation")
|
||||
class SuffixOperation(val op: SuffixOperator, val reference: SymbolReference) : Expression() {
|
||||
override val type: NodeType = NodeType.SuffixOperation
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitNodes(reference)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitSuffixOperation(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is SuffixOperation) return false
|
||||
return other.op == op && other.reference == reference
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = op.hashCode()
|
||||
result = 31 * result + reference.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
12
ast/src/main/kotlin/gay/pizza/pork/ast/SuffixOperator.kt
Normal file
12
ast/src/main/kotlin/gay/pizza/pork/ast/SuffixOperator.kt
Normal file
@ -0,0 +1,12 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("suffixOperator")
|
||||
enum class SuffixOperator(val token: String) {
|
||||
Increment("++"),
|
||||
Decrement("--")
|
||||
}
|
Reference in New Issue
Block a user