mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 21:21:33 +00:00
language: add unary plus & minus, post increment & decrement operators, non-newline print builtin. fix block comments (#4)
This commit is contained in:
@ -181,6 +181,12 @@ types:
|
||||
- name: Negate
|
||||
values:
|
||||
token: "!"
|
||||
- name: UnaryPlus
|
||||
values:
|
||||
token: "+"
|
||||
- name: UnaryMinus
|
||||
values:
|
||||
token: "-"
|
||||
PrefixOperation:
|
||||
parent: Expression
|
||||
values:
|
||||
@ -188,6 +194,24 @@ types:
|
||||
type: PrefixOperator
|
||||
- name: expression
|
||||
type: Expression
|
||||
SuffixOperator:
|
||||
values:
|
||||
- name: token
|
||||
type: String
|
||||
enums:
|
||||
- name: Increment
|
||||
values:
|
||||
token: "++"
|
||||
- name: Decrement
|
||||
values:
|
||||
token: "--"
|
||||
SuffixOperation:
|
||||
parent: Expression
|
||||
values:
|
||||
- name: op
|
||||
type: SuffixOperator
|
||||
- name: reference
|
||||
type: SymbolReference
|
||||
StringLiteral:
|
||||
parent: Expression
|
||||
values:
|
||||
|
@ -24,6 +24,8 @@ digraph A {
|
||||
type_Parentheses [shape=box,label="Parentheses"]
|
||||
type_PrefixOperator [shape=box,label="PrefixOperator"]
|
||||
type_PrefixOperation [shape=box,label="PrefixOperation"]
|
||||
type_SuffixOperator [shape=box,label="SuffixOperator"]
|
||||
type_SuffixOperation [shape=box,label="SuffixOperation"]
|
||||
type_StringLiteral [shape=box,label="StringLiteral"]
|
||||
type_SymbolReference [shape=box,label="SymbolReference"]
|
||||
type_While [shape=box,label="While"]
|
||||
@ -49,6 +51,7 @@ digraph A {
|
||||
type_Expression -> type_ListLiteral
|
||||
type_Expression -> type_Parentheses
|
||||
type_Expression -> type_PrefixOperation
|
||||
type_Expression -> type_SuffixOperation
|
||||
type_Expression -> type_StringLiteral
|
||||
type_Expression -> type_SymbolReference
|
||||
type_Expression -> type_While
|
||||
@ -84,6 +87,8 @@ digraph A {
|
||||
type_Parentheses -> type_Expression [style=dotted]
|
||||
type_PrefixOperation -> type_PrefixOperator [style=dotted]
|
||||
type_PrefixOperation -> type_Expression [style=dotted]
|
||||
type_SuffixOperation -> type_SuffixOperator [style=dotted]
|
||||
type_SuffixOperation -> type_SymbolReference [style=dotted]
|
||||
type_SymbolReference -> type_Symbol [style=dotted]
|
||||
type_While -> type_Expression [style=dotted]
|
||||
type_While -> type_Block [style=dotted]
|
||||
|
@ -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