mirror of
				https://github.com/GayPizzaSpecifications/pork.git
				synced 2025-11-04 09:59:39 +00:00 
			
		
		
		
	language: introduce the requirement to use return to return a value from a function
This commit is contained in:
		@ -300,6 +300,11 @@ types:
 | 
			
		||||
  Continue:
 | 
			
		||||
    parent: Expression
 | 
			
		||||
    values: []
 | 
			
		||||
  Return:
 | 
			
		||||
    parent: Expression
 | 
			
		||||
    values:
 | 
			
		||||
    - name: value
 | 
			
		||||
      type: Expression
 | 
			
		||||
  NoneLiteral:
 | 
			
		||||
    parent: Expression
 | 
			
		||||
    values: []
 | 
			
		||||
 | 
			
		||||
@ -36,6 +36,7 @@ digraph A {
 | 
			
		||||
  type_ForIn [shape=box,label="ForIn"]
 | 
			
		||||
  type_Break [shape=box,label="Break"]
 | 
			
		||||
  type_Continue [shape=box,label="Continue"]
 | 
			
		||||
  type_Return [shape=box,label="Return"]
 | 
			
		||||
  type_NoneLiteral [shape=box,label="NoneLiteral"]
 | 
			
		||||
  type_NativeFunctionDescriptor [shape=box,label="NativeFunctionDescriptor"]
 | 
			
		||||
  type_IndexedBy [shape=box,label="IndexedBy"]
 | 
			
		||||
@ -69,6 +70,7 @@ digraph A {
 | 
			
		||||
  type_Expression -> type_ForIn
 | 
			
		||||
  type_Expression -> type_Break
 | 
			
		||||
  type_Expression -> type_Continue
 | 
			
		||||
  type_Expression -> type_Return
 | 
			
		||||
  type_Expression -> type_NoneLiteral
 | 
			
		||||
  type_Expression -> type_IndexedBy
 | 
			
		||||
  type_Definition -> type_FunctionDefinition
 | 
			
		||||
@ -116,6 +118,7 @@ digraph A {
 | 
			
		||||
  type_ForIn -> type_ForInItem [style=dotted]
 | 
			
		||||
  type_ForIn -> type_Expression [style=dotted]
 | 
			
		||||
  type_ForIn -> type_Block [style=dotted]
 | 
			
		||||
  type_Return -> type_Expression [style=dotted]
 | 
			
		||||
  type_NativeFunctionDescriptor -> type_Symbol [style=dotted]
 | 
			
		||||
  type_NativeFunctionDescriptor -> type_StringLiteral [style=dotted]
 | 
			
		||||
  type_IndexedBy -> type_Expression [style=dotted]
 | 
			
		||||
 | 
			
		||||
@ -77,6 +77,9 @@ class NodeCoalescer(val followChildren: Boolean = true, val handler: (Node) -> U
 | 
			
		||||
  override fun visitPrefixOperation(node: PrefixOperation): Unit =
 | 
			
		||||
    handle(node)
 | 
			
		||||
 | 
			
		||||
  override fun visitReturn(node: Return): Unit =
 | 
			
		||||
    handle(node)
 | 
			
		||||
 | 
			
		||||
  override fun visitSetAssignment(node: SetAssignment): Unit =
 | 
			
		||||
    handle(node)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -58,6 +58,8 @@ interface NodeParser {
 | 
			
		||||
 | 
			
		||||
  fun parsePrefixOperation(): PrefixOperation
 | 
			
		||||
 | 
			
		||||
  fun parseReturn(): Return
 | 
			
		||||
 | 
			
		||||
  fun parseSetAssignment(): SetAssignment
 | 
			
		||||
 | 
			
		||||
  fun parseStringLiteral(): StringLiteral
 | 
			
		||||
 | 
			
		||||
@ -35,6 +35,7 @@ fun NodeParser.parse(type: NodeType): Node =
 | 
			
		||||
    NodeType.ForIn -> parseForIn()
 | 
			
		||||
    NodeType.Break -> parseBreak()
 | 
			
		||||
    NodeType.Continue -> parseContinue()
 | 
			
		||||
    NodeType.Return -> parseReturn()
 | 
			
		||||
    NodeType.NoneLiteral -> parseNoneLiteral()
 | 
			
		||||
    NodeType.NativeFunctionDescriptor -> parseNativeFunctionDescriptor()
 | 
			
		||||
    NodeType.IndexedBy -> parseIndexedBy()
 | 
			
		||||
 | 
			
		||||
@ -31,6 +31,7 @@ enum class NodeType(val parent: NodeType? = null) {
 | 
			
		||||
  NoneLiteral(Expression),
 | 
			
		||||
  Parentheses(Expression),
 | 
			
		||||
  PrefixOperation(Expression),
 | 
			
		||||
  Return(Expression),
 | 
			
		||||
  SetAssignment(Expression),
 | 
			
		||||
  StringLiteral(Expression),
 | 
			
		||||
  SuffixOperation(Expression),
 | 
			
		||||
 | 
			
		||||
@ -52,6 +52,8 @@ interface NodeVisitor<T> {
 | 
			
		||||
 | 
			
		||||
  fun visitPrefixOperation(node: PrefixOperation): T
 | 
			
		||||
 | 
			
		||||
  fun visitReturn(node: Return): T
 | 
			
		||||
 | 
			
		||||
  fun visitSetAssignment(node: SetAssignment): T
 | 
			
		||||
 | 
			
		||||
  fun visitStringLiteral(node: StringLiteral): T
 | 
			
		||||
 | 
			
		||||
@ -32,6 +32,7 @@ fun <T> NodeVisitor<T>.visit(node: Node): T =
 | 
			
		||||
    is ForIn -> visitForIn(node)
 | 
			
		||||
    is Break -> visitBreak(node)
 | 
			
		||||
    is Continue -> visitContinue(node)
 | 
			
		||||
    is Return -> visitReturn(node)
 | 
			
		||||
    is NoneLiteral -> visitNoneLiteral(node)
 | 
			
		||||
    is NativeFunctionDescriptor -> visitNativeFunctionDescriptor(node)
 | 
			
		||||
    is IndexedBy -> visitIndexedBy(node)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										28
									
								
								ast/src/main/kotlin/gay/pizza/pork/ast/gen/Return.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								ast/src/main/kotlin/gay/pizza/pork/ast/gen/Return.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("return")
 | 
			
		||||
class Return(val value: Expression) : Expression() {
 | 
			
		||||
  override val type: NodeType = NodeType.Return
 | 
			
		||||
 | 
			
		||||
  override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
 | 
			
		||||
    visitor.visitNodes(value)
 | 
			
		||||
 | 
			
		||||
  override fun <T> visit(visitor: NodeVisitor<T>): T =
 | 
			
		||||
    visitor.visitReturn(this)
 | 
			
		||||
 | 
			
		||||
  override fun equals(other: Any?): Boolean {
 | 
			
		||||
    if (other !is Return) return false
 | 
			
		||||
    return other.value == value
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  override fun hashCode(): Int {
 | 
			
		||||
    var result = value.hashCode()
 | 
			
		||||
    result = 31 * result + type.hashCode()
 | 
			
		||||
    return result
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user