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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user