diff --git a/Sources/P4Runtime/Runtime.swift b/Sources/P4Runtime/Runtime.swift index fc54dc1..91974b5 100644 --- a/Sources/P4Runtime/Runtime.swift +++ b/Sources/P4Runtime/Runtime.swift @@ -19,67 +19,61 @@ import Common import P4Lang /// The runtime for a parser -public struct ParserRuntime: CustomStringConvertible { - public var parser: Parser +public struct Runtime>: CustomStringConvertible { + public var callable: T let initialValues: VarValueScopes? - init(parser: Parser) { - self.parser = parser + init(callable: T) { + self.callable = callable self.initialValues = .none } - init(parser: Parser, withGlobalValues initial: VarValueScopes?) { - self.parser = parser + init(callable: T, withGlobalValues initial: VarValueScopes?) { + self.callable = callable self.initialValues = initial } /// Create a parser runtime from a P4 program - public static func create(program: P4Lang.Program) -> Result { - return ParserRuntime.create(program: program, withGlobalValues: .none) + public static func create(program: P4Lang.Program) -> Result> { + return Runtime.create(program: program, withGlobalValues: .none) } public static func create( program: P4Lang.Program, withGlobalValues initial: VarValueScopes? - ) -> Result { + ) -> Result> { return switch program.starting_parser() { case .Ok(let parser): - .Ok(P4Runtime.ParserRuntime(parser: parser, withGlobalValues: initial)) + .Ok(P4Runtime.Runtime(callable: parser, withGlobalValues: initial)) case .Error(let error): .Error(error) } } + public static func create( + control: P4Lang.Control, withGlobalValues initial: VarValueScopes? + ) -> Result> { + return .Ok(P4Runtime.Runtime(callable: control, withGlobalValues: initial)) + } + /// Run a P4 parser with no arguments - public func run() -> Result<(ParserState, ProgramExecution)> { + public func run() -> Result<(U, ProgramExecution)> { 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 public func run( - withArguments arguments: ArgumentList, inExecution pe: ProgramExecution - ) -> Result<(ParserState, ProgramExecution)> { + withArguments arguments: ArgumentList, inExecution pe: ProgramExecution = ProgramExecution() + ) -> Result<(U, ProgramExecution)> { - let pe = + let npe = if let globals = initialValues { pe.setGlobalValues(globals) } else { 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() { return .Error(error) } @@ -87,6 +81,6 @@ public struct ParserRuntime: CustomStringConvertible { } public var description: String { - return "Runtime:\nExecution: \(parser)" + return "Runtime:\nExecution: \(callable)" } } diff --git a/Tests/p4rseTests/ArrayTests.swift b/Tests/p4rseTests/ArrayTests.swift index b71d537..1790d61 100644 --- a/Tests/p4rseTests/ArrayTests.swift +++ b/Tests/p4rseTests/ArrayTests.swift @@ -49,7 +49,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -101,7 +101,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -128,7 +128,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -155,7 +155,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -187,7 +187,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -216,7 +216,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -249,7 +249,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) diff --git a/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift b/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift index f6d3f14..ecf610e 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift @@ -42,7 +42,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -61,7 +61,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -80,7 +80,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -99,7 +99,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -118,7 +118,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -137,7 +137,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -156,7 +156,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -175,7 +175,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -194,7 +194,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -213,7 +213,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) diff --git a/Tests/p4rseTests/BinaryOperatorTests/Bool.swift b/Tests/p4rseTests/BinaryOperatorTests/Bool.swift index 15a36c0..77ffe2b 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/Bool.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/Bool.swift @@ -42,7 +42,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -61,7 +61,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -80,7 +80,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -99,7 +99,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -118,7 +118,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -137,7 +137,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -156,7 +156,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -175,7 +175,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -194,7 +194,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -213,7 +213,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -232,7 +232,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -251,7 +251,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -270,7 +270,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -289,7 +289,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) diff --git a/Tests/p4rseTests/BinaryOperatorTests/Integer.swift b/Tests/p4rseTests/BinaryOperatorTests/Integer.swift index 6abbfe3..9a826d0 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/Integer.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/Integer.swift @@ -42,7 +42,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -61,7 +61,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -80,7 +80,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -99,7 +99,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -118,7 +118,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -137,7 +137,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -156,7 +156,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -175,7 +175,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -194,7 +194,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -213,7 +213,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -232,7 +232,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -251,7 +251,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -270,7 +270,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -289,7 +289,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -311,7 +311,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -395,7 +395,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -480,7 +480,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -564,7 +564,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) diff --git a/Tests/p4rseTests/BinaryOperatorTests/String.swift b/Tests/p4rseTests/BinaryOperatorTests/String.swift index e8b3bbf..a8160ba 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/String.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/String.swift @@ -42,7 +42,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -61,7 +61,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -80,7 +80,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -99,7 +99,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -118,7 +118,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -137,7 +137,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -156,7 +156,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -175,7 +175,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -194,7 +194,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -213,7 +213,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) diff --git a/Tests/p4rseTests/BinaryOperatorTests/Struct.swift b/Tests/p4rseTests/BinaryOperatorTests/Struct.swift index 6372776..e7c12a6 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/Struct.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/Struct.swift @@ -52,7 +52,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -85,7 +85,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @@ -119,7 +119,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -156,7 +156,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -193,7 +193,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } diff --git a/Tests/p4rseTests/ConditionalTests.swift b/Tests/p4rseTests/ConditionalTests.swift index d0d6ff6..cb2b68a 100644 --- a/Tests/p4rseTests/ConditionalTests.swift +++ b/Tests/p4rseTests/ConditionalTests.swift @@ -46,7 +46,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -74,7 +74,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) diff --git a/Tests/p4rseTests/Declarations.swift b/Tests/p4rseTests/Declarations.swift index 9f27284..2dd9ca8 100644 --- a/Tests/p4rseTests/Declarations.swift +++ b/Tests/p4rseTests/Declarations.swift @@ -47,7 +47,7 @@ import TreeSitterP4 """ let program = try #UseOkResult( Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -72,7 +72,7 @@ import TreeSitterP4 """ let program = try #UseOkResult( Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -95,7 +95,7 @@ import TreeSitterP4 """ let program = try #UseOkResult( Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -118,7 +118,7 @@ import TreeSitterP4 """ let program = try #UseOkResult( Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -142,7 +142,7 @@ import TreeSitterP4 """ let program = try #UseOkResult( Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } diff --git a/Tests/p4rseTests/ExpressionTests.swift b/Tests/p4rseTests/ExpressionTests.swift index 817172d..7ac037b 100644 --- a/Tests/p4rseTests/ExpressionTests.swift +++ b/Tests/p4rseTests/ExpressionTests.swift @@ -41,7 +41,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -61,7 +61,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -81,7 +81,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) diff --git a/Tests/p4rseTests/ExpressionTests/FunctionCall.swift b/Tests/p4rseTests/ExpressionTests/FunctionCall.swift index c8a6e37..5d7ee20 100644 --- a/Tests/p4rseTests/ExpressionTests/FunctionCall.swift +++ b/Tests/p4rseTests/ExpressionTests/FunctionCall.swift @@ -46,7 +46,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) @@ -75,7 +75,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) @@ -103,7 +103,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) @@ -130,7 +130,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) @@ -156,7 +156,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) diff --git a/Tests/p4rseTests/ExpressionTests/SelectExpression.swift b/Tests/p4rseTests/ExpressionTests/SelectExpression.swift index ea2c9ad..486bc6e 100644 --- a/Tests/p4rseTests/ExpressionTests/SelectExpression.swift +++ b/Tests/p4rseTests/ExpressionTests/SelectExpression.swift @@ -41,7 +41,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) @@ -63,7 +63,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) @@ -85,7 +85,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) @@ -107,7 +107,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) @@ -151,7 +151,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) @@ -172,7 +172,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([ 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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([ Argument(P4Value(P4BooleanValue(withValue: false)), atIndex: 1), Argument(P4Value(P4StringValue(withValue: "Testing")), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3), diff --git a/Tests/p4rseTests/ExternDeclarations.swift b/Tests/p4rseTests/ExternDeclarations.swift index 84706e9..b883d7e 100644 --- a/Tests/p4rseTests/ExternDeclarations.swift +++ b/Tests/p4rseTests/ExternDeclarations.swift @@ -89,7 +89,7 @@ public struct Return6: P4FFI { simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: .none, withFFIs: [externally])) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -117,7 +117,7 @@ public struct Return6: P4FFI { simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: .none, withFFIs: [externally])) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) diff --git a/Tests/p4rseTests/InterloperTests.swift b/Tests/p4rseTests/InterloperTests.swift index da19c87..4fd8dc9 100644 --- a/Tests/p4rseTests/InterloperTests.swift +++ b/Tests/p4rseTests/InterloperTests.swift @@ -47,7 +47,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) var statements_executed: [String] = Array() @@ -86,7 +86,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) var expressions_evaluated: [String] = Array() diff --git a/Tests/p4rseTests/RuntimeTests.swift b/Tests/p4rseTests/RuntimeTests.swift index 17016ff..e393f43 100644 --- a/Tests/p4rseTests/RuntimeTests.swift +++ b/Tests/p4rseTests/RuntimeTests.swift @@ -38,7 +38,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) // We should be in the accept state. @@ -56,7 +56,7 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) // We should be in the accept state. #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -73,10 +73,10 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) #expect( - #RequireErrorResult<(ParserState, ProgramExecution)>( + #RequireErrorResult<(InstantiatedParserState, ProgramExecution)>( Error(withMessage: "Could not find the start state"), runtime.run())) } @@ -93,7 +93,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([ 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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([ Argument(P4Value(P4BooleanValue(withValue: true)), atIndex: 1), Argument(P4Value(P4BooleanValue(withValue: false)), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3), ]) #expect( - #RequireErrorResult<(ParserState, ProgramExecution)>( + #RequireErrorResult<(InstantiatedParserState, ProgramExecution)>( Error(withMessage: "Cannot call parser: Argument 2's type (Boolean) is incompatible with the parameter type (String)"), runtime.run(withArguments: args))) } @@ -139,14 +139,14 @@ import TreeSitterP4 }; """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([ Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 1), Argument(P4Value(P4StringValue(withValue: "Testing")), atIndex: 2), Argument(P4Value(P4IntValue(withValue: 5)), atIndex: 3), ]) #expect( - #RequireErrorResult<(ParserState, ProgramExecution)>( + #RequireErrorResult<(InstantiatedParserState, ProgramExecution)>( Error(withMessage: "Cannot call parser: Argument 1's type (Int) is incompatible with the parameter type (Boolean)"), runtime.run(withArguments: args))) } @@ -163,11 +163,11 @@ import TreeSitterP4 }; """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([Argument(P4Value(P4BooleanValue(withValue: true)), atIndex: 0)]) #expect( - #RequireErrorResult<(ParserState, ProgramExecution)>( + #RequireErrorResult<(InstantiatedParserState, ProgramExecution)>( Error(withMessage: "Cannot call parser: 1 arguments found but 3 required"), runtime.run(withArguments: args))) } diff --git a/Tests/p4rseTests/ScopeRuntimeTests.swift b/Tests/p4rseTests/ScopeRuntimeTests.swift index 6d4a8bb..f0f2d7f 100644 --- a/Tests/p4rseTests/ScopeRuntimeTests.swift +++ b/Tests/p4rseTests/ScopeRuntimeTests.swift @@ -43,7 +43,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -69,7 +69,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) @@ -97,7 +97,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -121,7 +121,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) @@ -152,7 +152,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) diff --git a/Tests/p4rseTests/StructTests.swift b/Tests/p4rseTests/StructTests.swift index d4a15a1..90451bc 100644 --- a/Tests/p4rseTests/StructTests.swift +++ b/Tests/p4rseTests/StructTests.swift @@ -57,7 +57,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -86,7 +86,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -116,7 +116,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -151,7 +151,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @@ -186,7 +186,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -220,7 +220,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @@ -266,7 +266,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -302,7 +302,7 @@ import TreeSitterP4 let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -375,7 +375,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -423,7 +423,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( 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.create(program: program, withGlobalValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } diff --git a/Tests/p4rseTests/TransitionTests.swift b/Tests/p4rseTests/TransitionTests.swift index bdbeff3..d22ded7 100644 --- a/Tests/p4rseTests/TransitionTests.swift +++ b/Tests/p4rseTests/TransitionTests.swift @@ -41,7 +41,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) @@ -63,7 +63,7 @@ import TreeSitterP4 let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) 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.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) @@ -82,10 +82,10 @@ import TreeSitterP4 """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) #expect( - #RequireErrorResult<(ParserState, ProgramExecution)>( + #RequireErrorResult<(InstantiatedParserState, ProgramExecution)>( Error(withMessage: "No key matched the selector"), runtime.run())) } \ No newline at end of file diff --git a/Tests/p4rseTests/ValueTypeParserTests.swift b/Tests/p4rseTests/ValueTypeParserTests.swift index 231d83f..dd6364f 100644 --- a/Tests/p4rseTests/ValueTypeParserTests.swift +++ b/Tests/p4rseTests/ValueTypeParserTests.swift @@ -141,7 +141,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) // 5 == 5 == true @@ -163,7 +163,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) // 5 == 5 == true @@ -185,7 +185,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) // 6 == 5 == true @@ -207,7 +207,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) // 6 == 5 == false @@ -229,7 +229,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) - let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) + let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) // TODO: This test should throw an error.