mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-10-11 00:19:38 +00:00
pork: it's got it all, ffi, state machine tokenizer, and better IDE support
This commit is contained in:
@ -6,23 +6,23 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("importDeclaration")
|
||||
class ImportDeclaration(val form: Symbol, val components: List<Symbol>) : Declaration() {
|
||||
class ImportDeclaration(val form: Symbol, val path: ImportPath) : Declaration() {
|
||||
override val type: NodeType = NodeType.ImportDeclaration
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitAll(listOf(form), components)
|
||||
visitor.visitNodes(form, path)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitImportDeclaration(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is ImportDeclaration) return false
|
||||
return other.form == form && other.components == components
|
||||
return other.form == form && other.path == path
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = form.hashCode()
|
||||
result = 31 * result + components.hashCode()
|
||||
result = 31 * result + path.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
|
28
ast/src/main/kotlin/gay/pizza/pork/ast/gen/ImportPath.kt
Normal file
28
ast/src/main/kotlin/gay/pizza/pork/ast/gen/ImportPath.kt
Normal file
@ -0,0 +1,28 @@
|
||||
// GENERATED CODE FROM PORK AST CODEGEN
|
||||
package gay.pizza.pork.ast.gen
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@SerialName("importPath")
|
||||
class ImportPath(val components: List<Symbol>) : Node() {
|
||||
override val type: NodeType = NodeType.ImportPath
|
||||
|
||||
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
|
||||
visitor.visitAll(components)
|
||||
|
||||
override fun <T> visit(visitor: NodeVisitor<T>): T =
|
||||
visitor.visitImportPath(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is ImportPath) return false
|
||||
return other.components == components
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = components.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
@ -41,6 +41,9 @@ class NodeCoalescer(val followChildren: Boolean = true, val handler: (Node) -> U
|
||||
override fun visitImportDeclaration(node: ImportDeclaration): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitImportPath(node: ImportPath): Unit =
|
||||
handle(node)
|
||||
|
||||
override fun visitIndexedBy(node: IndexedBy): Unit =
|
||||
handle(node)
|
||||
|
||||
|
@ -34,6 +34,8 @@ interface NodeParser {
|
||||
|
||||
fun parseImportDeclaration(): ImportDeclaration
|
||||
|
||||
fun parseImportPath(): ImportPath
|
||||
|
||||
fun parseIndexedBy(): IndexedBy
|
||||
|
||||
fun parseInfixOperation(): InfixOperation
|
||||
|
@ -19,6 +19,7 @@ fun NodeParser.parse(type: NodeType): Node =
|
||||
NodeType.FunctionDefinition -> parseFunctionDefinition()
|
||||
NodeType.LetDefinition -> parseLetDefinition()
|
||||
NodeType.If -> parseIf()
|
||||
NodeType.ImportPath -> parseImportPath()
|
||||
NodeType.ImportDeclaration -> parseImportDeclaration()
|
||||
NodeType.IntegerLiteral -> parseIntegerLiteral()
|
||||
NodeType.LongLiteral -> parseLongLiteral()
|
||||
|
@ -19,6 +19,7 @@ enum class NodeType(val parent: NodeType? = null) {
|
||||
FunctionDefinition(Definition),
|
||||
If(Expression),
|
||||
ImportDeclaration(Declaration),
|
||||
ImportPath(Node),
|
||||
IndexedBy(Expression),
|
||||
InfixOperation(Expression),
|
||||
IntegerLiteral(Expression),
|
||||
|
@ -28,6 +28,8 @@ interface NodeVisitor<T> {
|
||||
|
||||
fun visitImportDeclaration(node: ImportDeclaration): T
|
||||
|
||||
fun visitImportPath(node: ImportPath): T
|
||||
|
||||
fun visitIndexedBy(node: IndexedBy): T
|
||||
|
||||
fun visitInfixOperation(node: InfixOperation): T
|
||||
|
@ -16,6 +16,7 @@ fun <T> NodeVisitor<T>.visit(node: Node): T =
|
||||
is FunctionDefinition -> visitFunctionDefinition(node)
|
||||
is LetDefinition -> visitLetDefinition(node)
|
||||
is If -> visitIf(node)
|
||||
is ImportPath -> visitImportPath(node)
|
||||
is ImportDeclaration -> visitImportDeclaration(node)
|
||||
is IntegerLiteral -> visitIntegerLiteral(node)
|
||||
is LongLiteral -> visitLongLiteral(node)
|
||||
|
Reference in New Issue
Block a user