runtime: Parameterize Runtime

Parameterize Runtime (nee ParserRuntime) so that it can run anything
that is LibraryCallable. TODO: Refactor its API -- left mostly as
it was because changing unit tests will be laborious.
This commit is contained in:
Will Hawkins
2026-04-30 18:37:21 -04:00
parent b97aa1af72
commit bd262e5b73
19 changed files with 147 additions and 153 deletions
+22 -28
View File
@@ -19,67 +19,61 @@ import Common
import P4Lang import P4Lang
/// The runtime for a parser /// The runtime for a parser
public struct ParserRuntime: CustomStringConvertible { public struct Runtime<U, T: LibraryCallable<U>>: CustomStringConvertible {
public var parser: Parser public var callable: T
let initialValues: VarValueScopes? let initialValues: VarValueScopes?
init(parser: Parser) { init(callable: T) {
self.parser = parser self.callable = callable
self.initialValues = .none self.initialValues = .none
} }
init(parser: Parser, withGlobalValues initial: VarValueScopes?) { init(callable: T, withGlobalValues initial: VarValueScopes?) {
self.parser = parser self.callable = callable
self.initialValues = initial self.initialValues = initial
} }
/// Create a parser runtime from a P4 program /// Create a parser runtime from a P4 program
public static func create(program: P4Lang.Program) -> Result<ParserRuntime> { public static func create(program: P4Lang.Program) -> Result<Runtime<InstantiatedParserState, Parser>> {
return ParserRuntime.create(program: program, withGlobalValues: .none) return Runtime.create(program: program, withGlobalValues: .none)
} }
public static func create( public static func create(
program: P4Lang.Program, withGlobalValues initial: VarValueScopes? program: P4Lang.Program, withGlobalValues initial: VarValueScopes?
) -> Result<ParserRuntime> { ) -> Result<Runtime<InstantiatedParserState, Parser>> {
return switch program.starting_parser() { return switch program.starting_parser() {
case .Ok(let parser): case .Ok(let parser):
.Ok(P4Runtime.ParserRuntime(parser: parser, withGlobalValues: initial)) .Ok(P4Runtime.Runtime<InstantiatedParserState, Parser>(callable: parser, withGlobalValues: initial))
case .Error(let error): .Error(error) case .Error(let error): .Error(error)
} }
} }
public static func create(
control: P4Lang.Control, withGlobalValues initial: VarValueScopes?
) -> Result<Runtime<P4TableHitMissValue, Control>> {
return .Ok(P4Runtime.Runtime<P4TableHitMissValue, Control>(callable: control, withGlobalValues: initial))
}
/// Run a P4 parser with no arguments /// Run a P4 parser with no arguments
public func run() -> Result<(ParserState, ProgramExecution)> { public func run() -> Result<(U, ProgramExecution)> {
return self.run(withArguments: ArgumentList([])) return self.run(withArguments: ArgumentList([]))
} }
public func run(withArguments arguments: ArgumentList) -> Result<(ParserState, ProgramExecution)>
{
let pe =
if let initial = initialValues {
ProgramExecution().setGlobalValues(initial)
} else {
ProgramExecution()
}
return self.run(withArguments: arguments, inExecution: pe)
}
/// Run the P4 parser on a given packet /// Run the P4 parser on a given packet
public func run( public func run(
withArguments arguments: ArgumentList, inExecution pe: ProgramExecution withArguments arguments: ArgumentList, inExecution pe: ProgramExecution = ProgramExecution()
) -> Result<(ParserState, ProgramExecution)> { ) -> Result<(U, ProgramExecution)> {
let pe = let npe =
if let globals = initialValues { if let globals = initialValues {
pe.setGlobalValues(globals) pe.setGlobalValues(globals)
} else { } else {
pe pe
} }
let (end_state, execution) = parser.call(execution: pe, arguments: arguments) let (end_state, execution) = callable.call(execution: npe, arguments: arguments)
if let error = execution.getError() { if let error = execution.getError() {
return .Error(error) return .Error(error)
} }
@@ -87,6 +81,6 @@ public struct ParserRuntime: CustomStringConvertible {
} }
public var description: String { public var description: String {
return "Runtime:\nExecution: \(parser)" return "Runtime:\nExecution: \(callable)"
} }
} }
+7 -7
View File
@@ -49,7 +49,7 @@ import TreeSitterP4
]))) ])))
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -101,7 +101,7 @@ import TreeSitterP4
]))) ])))
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -128,7 +128,7 @@ import TreeSitterP4
]))) ])))
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -155,7 +155,7 @@ import TreeSitterP4
]))) ])))
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -187,7 +187,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -216,7 +216,7 @@ import TreeSitterP4
]))) ])))
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -249,7 +249,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -42,7 +42,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -61,7 +61,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -80,7 +80,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -99,7 +99,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -118,7 +118,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -137,7 +137,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -156,7 +156,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -175,7 +175,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -194,7 +194,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -213,7 +213,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
+14 -14
View File
@@ -42,7 +42,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -61,7 +61,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -80,7 +80,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -99,7 +99,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -118,7 +118,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -137,7 +137,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -156,7 +156,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -175,7 +175,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -194,7 +194,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -213,7 +213,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -232,7 +232,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -251,7 +251,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -270,7 +270,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -289,7 +289,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -42,7 +42,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -61,7 +61,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -80,7 +80,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -99,7 +99,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -118,7 +118,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -137,7 +137,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -156,7 +156,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -175,7 +175,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -194,7 +194,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -213,7 +213,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -232,7 +232,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -251,7 +251,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -270,7 +270,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -289,7 +289,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -311,7 +311,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -395,7 +395,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -480,7 +480,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -564,7 +564,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -42,7 +42,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -61,7 +61,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -80,7 +80,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -99,7 +99,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -118,7 +118,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -137,7 +137,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -156,7 +156,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -175,7 +175,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -194,7 +194,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -213,7 +213,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple)) let program = try #UseOkResult(Program.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -52,7 +52,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations, withGlobalTypes: test_types)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -85,7 +85,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations, withGlobalTypes: test_types)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
} }
@@ -119,7 +119,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations, withGlobalTypes: test_types)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -156,7 +156,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations, withGlobalTypes: test_types)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -193,7 +193,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations, withGlobalTypes: test_types)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
} }
+2 -2
View File
@@ -46,7 +46,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -74,7 +74,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
+5 -5
View File
@@ -47,7 +47,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration)) Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -72,7 +72,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration)) Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -95,7 +95,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration)) Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -118,7 +118,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration)) Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -142,7 +142,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration)) Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
} }
+3 -3
View File
@@ -41,7 +41,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -61,7 +61,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -81,7 +81,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -46,7 +46,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -75,7 +75,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -103,7 +103,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -130,7 +130,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -156,7 +156,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -41,7 +41,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -63,7 +63,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -85,7 +85,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -107,7 +107,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -151,7 +151,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -172,7 +172,7 @@ import TreeSitterP4
}; };
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let args = ArgumentList([ let args = ArgumentList([
Argument(P4Value(P4BooleanValue(withValue: false)), atIndex: 1), Argument(P4Value(P4StringValue(withValue: "Testing")), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3), Argument(P4Value(P4BooleanValue(withValue: false)), atIndex: 1), Argument(P4Value(P4StringValue(withValue: "Testing")), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3),
@@ -193,7 +193,7 @@ import TreeSitterP4
}; };
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let args = ArgumentList([ let args = ArgumentList([
Argument(P4Value(P4BooleanValue(withValue: false)), atIndex: 1), Argument(P4Value(P4StringValue(withValue: "Testing")), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3), Argument(P4Value(P4BooleanValue(withValue: false)), atIndex: 1), Argument(P4Value(P4StringValue(withValue: "Testing")), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3),
+2 -2
View File
@@ -89,7 +89,7 @@ public struct Return6: P4FFI {
simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: .none, simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: .none,
withFFIs: [externally])) withFFIs: [externally]))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -117,7 +117,7 @@ public struct Return6: P4FFI {
simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: .none, simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: .none,
withFFIs: [externally])) withFFIs: [externally]))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
+2 -2
View File
@@ -47,7 +47,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
var statements_executed: [String] = Array() var statements_executed: [String] = Array()
@@ -86,7 +86,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
var expressions_evaluated: [String] = Array() var expressions_evaluated: [String] = Array()
+11 -11
View File
@@ -38,7 +38,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
// We should be in the accept state. // We should be in the accept state.
@@ -56,7 +56,7 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
// We should be in the accept state. // We should be in the accept state.
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -73,10 +73,10 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
#expect( #expect(
#RequireErrorResult<(ParserState, ProgramExecution)>( #RequireErrorResult<(InstantiatedParserState, ProgramExecution)>(
Error(withMessage: "Could not find the start state"), Error(withMessage: "Could not find the start state"),
runtime.run())) runtime.run()))
} }
@@ -93,7 +93,7 @@ import TreeSitterP4
}; };
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let args = ArgumentList([ let args = ArgumentList([
Argument(P4Value(P4BooleanValue(withValue: true)), atIndex: 1), Argument(P4Value(P4StringValue(withValue: "Testing")), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3), Argument(P4Value(P4BooleanValue(withValue: true)), atIndex: 1), Argument(P4Value(P4StringValue(withValue: "Testing")), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3),
@@ -115,14 +115,14 @@ import TreeSitterP4
}; };
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let args = ArgumentList([ let args = ArgumentList([
Argument(P4Value(P4BooleanValue(withValue: true)), atIndex: 1), Argument(P4Value(P4BooleanValue(withValue: false)), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3), Argument(P4Value(P4BooleanValue(withValue: true)), atIndex: 1), Argument(P4Value(P4BooleanValue(withValue: false)), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3),
]) ])
#expect( #expect(
#RequireErrorResult<(ParserState, ProgramExecution)>( #RequireErrorResult<(InstantiatedParserState, ProgramExecution)>(
Error(withMessage: "Cannot call parser: Argument 2's type (Boolean) is incompatible with the parameter type (String)"), Error(withMessage: "Cannot call parser: Argument 2's type (Boolean) is incompatible with the parameter type (String)"),
runtime.run(withArguments: args))) runtime.run(withArguments: args)))
} }
@@ -139,14 +139,14 @@ import TreeSitterP4
}; };
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let args = ArgumentList([ let args = ArgumentList([
Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 1), Argument(P4Value(P4StringValue(withValue: "Testing")), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 1), Argument(P4Value(P4StringValue(withValue: "Testing")), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3),
]) ])
#expect( #expect(
#RequireErrorResult<(ParserState, ProgramExecution)>( #RequireErrorResult<(InstantiatedParserState, ProgramExecution)>(
Error(withMessage: "Cannot call parser: Argument 1's type (Int) is incompatible with the parameter type (Boolean)"), Error(withMessage: "Cannot call parser: Argument 1's type (Int) is incompatible with the parameter type (Boolean)"),
runtime.run(withArguments: args))) runtime.run(withArguments: args)))
} }
@@ -163,11 +163,11 @@ import TreeSitterP4
}; };
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let args = ArgumentList([Argument(P4Value(P4BooleanValue(withValue: true)), atIndex: 0)]) let args = ArgumentList([Argument(P4Value(P4BooleanValue(withValue: true)), atIndex: 0)])
#expect( #expect(
#RequireErrorResult<(ParserState, ProgramExecution)>( #RequireErrorResult<(InstantiatedParserState, ProgramExecution)>(
Error(withMessage: "Cannot call parser: 1 arguments found but 3 required"), Error(withMessage: "Cannot call parser: 1 arguments found but 3 required"),
runtime.run(withArguments: args))) runtime.run(withArguments: args)))
} }
+5 -5
View File
@@ -43,7 +43,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -69,7 +69,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
@@ -97,7 +97,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -121,7 +121,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
@@ -152,7 +152,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
+10 -10
View File
@@ -57,7 +57,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -86,7 +86,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -116,7 +116,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -151,7 +151,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
} }
@@ -186,7 +186,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -220,7 +220,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
} }
@@ -266,7 +266,7 @@ import TreeSitterP4
]))) ])))
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -302,7 +302,7 @@ import TreeSitterP4
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -375,7 +375,7 @@ import TreeSitterP4
]))) ])))
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
@@ -423,7 +423,7 @@ import TreeSitterP4
]))) ])))
let program = try #UseOkResult( let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
} }
+4 -4
View File
@@ -41,7 +41,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -63,7 +63,7 @@ import TreeSitterP4
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(parser.states.count() == 1) #expect(parser.states.count() == 1)
@@ -82,10 +82,10 @@ import TreeSitterP4
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
#expect( #expect(
#RequireErrorResult<(ParserState, ProgramExecution)>( #RequireErrorResult<(InstantiatedParserState, ProgramExecution)>(
Error(withMessage: "No key matched the selector"), Error(withMessage: "No key matched the selector"),
runtime.run())) runtime.run()))
} }
+5 -5
View File
@@ -141,7 +141,7 @@ import TreeSitterP4
}; };
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
// 5 == 5 == true // 5 == 5 == true
@@ -163,7 +163,7 @@ import TreeSitterP4
}; };
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
// 5 == 5 == true // 5 == 5 == true
@@ -185,7 +185,7 @@ import TreeSitterP4
}; };
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
// 6 == 5 == true // 6 == 5 == true
@@ -207,7 +207,7 @@ import TreeSitterP4
}; };
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
// 6 == 5 == false // 6 == 5 == false
@@ -229,7 +229,7 @@ import TreeSitterP4
}; };
""" """
let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run()) let (state_result, _) = try! #UseOkResult(runtime.run())
// TODO: This test should throw an error. // TODO: This test should throw an error.