mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 21:21:33 +00:00
pork: it's got it all, ffi, state machine tokenizer, and better IDE support
This commit is contained in:
@ -178,13 +178,20 @@ types:
|
||||
type: Block
|
||||
- name: elseBlock
|
||||
type: Block?
|
||||
ImportPath:
|
||||
parent: Node
|
||||
referencedElementValue: components
|
||||
referencedElementType: CompilationUnit
|
||||
values:
|
||||
- name: components
|
||||
type: List<Symbol>
|
||||
ImportDeclaration:
|
||||
parent: Declaration
|
||||
values:
|
||||
- name: form
|
||||
type: Symbol
|
||||
- name: components
|
||||
type: List<Symbol>
|
||||
- name: path
|
||||
type: ImportPath
|
||||
IntegerLiteral:
|
||||
parent: Expression
|
||||
values:
|
||||
|
@ -18,6 +18,7 @@ digraph A {
|
||||
type_FunctionDefinition [shape=box,label="FunctionDefinition"]
|
||||
type_LetDefinition [shape=box,label="LetDefinition"]
|
||||
type_If [shape=box,label="If"]
|
||||
type_ImportPath [shape=box,label="ImportPath"]
|
||||
type_ImportDeclaration [shape=box,label="ImportDeclaration"]
|
||||
type_IntegerLiteral [shape=box,label="IntegerLiteral"]
|
||||
type_LongLiteral [shape=box,label="LongLiteral"]
|
||||
@ -45,6 +46,7 @@ digraph A {
|
||||
type_Node -> type_Block
|
||||
type_Node -> type_CompilationUnit
|
||||
type_Node -> type_ArgumentSpec
|
||||
type_Node -> type_ImportPath
|
||||
type_Node -> type_ForInItem
|
||||
type_Node -> type_Native
|
||||
type_Expression -> type_LetAssignment
|
||||
@ -98,7 +100,9 @@ digraph A {
|
||||
type_LetDefinition -> type_Expression [style=dotted]
|
||||
type_If -> type_Expression [style=dotted]
|
||||
type_If -> type_Block [style=dotted]
|
||||
type_ImportPath -> type_Symbol [style=dotted]
|
||||
type_ImportDeclaration -> type_Symbol [style=dotted]
|
||||
type_ImportDeclaration -> type_ImportPath [style=dotted]
|
||||
type_ListLiteral -> type_Expression [style=dotted]
|
||||
type_Parentheses -> type_Expression [style=dotted]
|
||||
type_PrefixOperation -> type_PrefixOperator [style=dotted]
|
||||
|
@ -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