runtime: Refactor Expression/Statement Evaluators

Allow the user to customize the evaluation/execution of expressions/
statements with something that implements functions that perform
those tasks. This additional functionality will make it possible for
the "classic" evaluator not to waste time checking for the presence
of interlopers and give implementers additional customization opportunities.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-04-20 16:28:01 -04:00
parent 47cc52ea44
commit a24571222b
8 changed files with 181 additions and 121 deletions
+5 -6
View File
@@ -51,11 +51,11 @@ import TreeSitterP4
var statements_executed: [String] = Array()
let pe = ProgramExecution().setStatementInterloper({ (statement, cf, execution) in
let ev = InterloperEvaluator().setStatementInterloper() { (statement, cf, execution) in
statements_executed.append("\(statement)")
})
}
let (state_result, _) = try! #UseOkResult(runtime.run(withArguments: ArgumentList(), inExecution: pe))
let (state_result, _) = try! #UseOkResult(runtime.run(withArguments: ArgumentList(), inExecution: ProgramExecution(ev)))
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -90,12 +90,11 @@ import TreeSitterP4
var expressions_evaluated: [String] = Array()
let pe = ProgramExecution().setExpressionInterloper() { expression, result, execution in
print("Expression: \(expression)")
let ev = InterloperEvaluator().setExpressionInterloper() { expression, result, execution in
expressions_evaluated.append("\(expression)")
}
let (state_result, _) = try! #UseOkResult(runtime.run(withArguments: ArgumentList(), inExecution: pe))
let (state_result, _) = try! #UseOkResult(runtime.run(withArguments: ArgumentList(), inExecution: ProgramExecution(ev)))
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)