Skip to content

Commit

Permalink
Added Support for Statement Definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
theSalted committed Jun 26, 2024
1 parent f32b4de commit 0384e12
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
resources: [
.process("Resources/expression.json")
.process("Resources/expression.json"),
.process("Resources/statement.json")
]
),
.testTarget(name: "LoxTests", dependencies: [
Expand Down
File renamed without changes.
43 changes: 43 additions & 0 deletions Sources/Lox/Definitions/Statement.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Statement.swift
//
//
// Generated by SyntaxDefinitionGenerator on 06/26/24
//


public protocol Statement {
func accept<V: StatementVisitor, R>(visitor: V) -> R where R == V.StatementVisitorReturn
}

public protocol StatementVisitor {
associatedtype StatementVisitorReturn

func visit(_ expr: Expr) -> StatementVisitorReturn
func visit(_ expr: Print) -> StatementVisitorReturn
}

public struct Expr: Statement {
let expression: Expression

init(expression: Expression) {
self.expression = expression
}

public func accept<V: StatementVisitor, R>(visitor: V) -> R where R == V.StatementVisitorReturn {
return visitor.visit(self)
}
}

public struct Print: Statement {
let expression: Expression

init(expression: Expression) {
self.expression = expression
}

public func accept<V: StatementVisitor, R>(visitor: V) -> R where R == V.StatementVisitorReturn {
return visitor.visit(self)
}
}

File renamed without changes.
14 changes: 14 additions & 0 deletions Sources/SyntaxDefinitionGenerator/Resources/statement.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

{
"baseName": "Statement",
"types": [
{
"name": "Expr",
"parameterField": "expression: Expression"
},
{
"name": "Print",
"parameterField": "expression: Expression"
}
]
}

0 comments on commit 0384e12

Please sign in to comment.