diff --git a/Sources/P4Compiler/Parser.swift b/Sources/P4Compiler/Parser.swift index 6293f0e..e79267f 100644 --- a/Sources/P4Compiler/Parser.swift +++ b/Sources/P4Compiler/Parser.swift @@ -84,7 +84,7 @@ public struct Parser { static func Compile( node: Node, forState state_identifier: Common.Identifier, withStatements stmts: [EvaluatableStatement], withContext context: CompilerContext - ) -> Result<(ParserState, CompilerContext)> { + ) -> Result<(InstantiatedParserState, CompilerContext)> { #RequireNodeType( node: node, type: "parserTransitionStatement", nice_type_name: "parser transition statement" @@ -177,7 +177,7 @@ public struct Parser { public struct State { static func Compile( node: Node, withContext context: CompilerContext - ) -> Result<(ParserState, CompilerContext)> { + ) -> Result<(InstantiatedParserState, CompilerContext)> { var currentChildIdx = 0 var currentChildIdxSafe = 1 diff --git a/Sources/P4Lang/Parser.swift b/Sources/P4Lang/Parser.swift index 1f7bf4e..9917d0e 100644 --- a/Sources/P4Lang/Parser.swift +++ b/Sources/P4Lang/Parser.swift @@ -40,9 +40,11 @@ public struct ParserAssignmentStatement { /// A P4 Parser State /// /// Note: A P4 Parser State is both a type and a value. +/// This "bare" parser state represents the state more as a type than a value. public class ParserState: P4Type, P4Value, Equatable, CustomStringConvertible { public static func == (lhs: ParserState, rhs: ParserState) -> Bool { - return lhs.state == rhs.state + // Two "bare" parser states are always equal. + return true } public func eq(rhs: any Common.P4Type) -> Bool { @@ -56,37 +58,106 @@ public class ParserState: P4Type, P4Value, Equatable, CustomStringConvertible { return self } + // Any operation between two "bare" parser states is always true. public func eq(rhs: any Common.P4Value) -> Bool { return switch rhs { - case let other as ParserState: self.state == other.state + case is ParserState: true default: false } } public func lt(rhs: any Common.P4Value) -> Bool { return switch rhs { - case let other as ParserState: self.state < other.state + case is ParserState: true default: false } } public func lte(rhs: any Common.P4Value) -> Bool { return switch rhs { - case let other as ParserState: self.state <= other.state + case is ParserState: true default: false } } public func gt(rhs: any Common.P4Value) -> Bool { return switch rhs { - case let other as ParserState: self.state > other.state + case is ParserState: true default: false } } public func gte(rhs: any Common.P4Value) -> Bool { return switch rhs { - case let other as ParserState: self.state >= other.state + case is ParserState: true + default: false + } + } + + public var description: String { + return "Bare Parser State" + } + + /// Construct a ParserState + public init() {} + + public func def() -> any P4Value { + return ParserState() + } +} + +/// Instantiated Parser State +/// +/// A parser state is both a type and a value. The Instantiated +/// Parser State is the base class for parser states that act more +/// as a value than a type. +public class InstantiatedParserState: ParserState { + public static func == (lhs: InstantiatedParserState, rhs: InstantiatedParserState) -> Bool { + return lhs.state == rhs.state + } + + public override func eq(rhs: any Common.P4Type) -> Bool { + return switch rhs { + case is ParserState: true + default: false + } + } + + public override func type() -> any Common.P4Type { + return self + } + + public override func eq(rhs: any Common.P4Value) -> Bool { + return switch rhs { + case let other as InstantiatedParserState: self.state == other.state + default: false + } + } + + public override func lt(rhs: any Common.P4Value) -> Bool { + return switch rhs { + case let other as InstantiatedParserState: self.state < other.state + default: false + } + } + + public override func lte(rhs: any Common.P4Value) -> Bool { + return switch rhs { + case let other as InstantiatedParserState: self.state <= other.state + default: false + } + } + + public override func gt(rhs: any Common.P4Value) -> Bool { + return switch rhs { + case let other as InstantiatedParserState: self.state > other.state + default: false + } + } + + public override func gte(rhs: any Common.P4Value) -> Bool { + return switch rhs { + case let other as InstantiatedParserState: self.state >= other.state default: false } } @@ -94,7 +165,7 @@ public class ParserState: P4Type, P4Value, Equatable, CustomStringConvertible { public private(set) var state: Identifier public private(set) var statements: [EvaluatableStatement] - public var description: String { + public override var description: String { return "Name: \(state)" } @@ -114,12 +185,12 @@ public class ParserState: P4Type, P4Value, Equatable, CustomStringConvertible { statements = Array() } - public func def() -> any P4Value { - return ParserState(name: Identifier(name: "")) + public override func def() -> any P4Value { + return InstantiatedParserState(name: Identifier(name: "")) } } -public class ParserStateDirectTransition: ParserState { +public class ParserStateDirectTransition: InstantiatedParserState { private let next_state: Identifier @@ -140,7 +211,7 @@ public class ParserStateDirectTransition: ParserState { } } -public class ParserStateNoTransition: ParserState { +public class ParserStateNoTransition: InstantiatedParserState { public override init(name: Identifier, withStatements stmts: [any EvaluatableStatement]) { super.init(name: name, withStatements: stmts) } @@ -149,7 +220,7 @@ public class ParserStateNoTransition: ParserState { } } -public class ParserStateSelectTransition: ParserState { +public class ParserStateSelectTransition: InstantiatedParserState { public let selectExpression: SelectExpression @@ -172,7 +243,7 @@ nonisolated(unsafe) public let reject = ParserStateNoTransition( name: Identifier(name: "reject"), withStatements: []) public struct ParserStates { - public var states: [ParserState] = Array() + public var states: [InstantiatedParserState] = Array() public func count() -> Int { return states.count @@ -191,11 +262,11 @@ public struct ParserStates { self.states = Array() } - private init(withStates states: [ParserState]) { + private init(withStates states: [InstantiatedParserState]) { self.states = states } - public func append(state: ParserState) -> ParserStates { + public func append(state: InstantiatedParserState) -> ParserStates { var new_states = self.states new_states.append(state) return ParserStates(withStates: new_states) @@ -278,3 +349,8 @@ public struct Parser: P4Type, P4Value { return Parser(withName: Identifier(name: "")) } } + +/// Launder a parser state into an instantiated parser state. +public func AsInstantiatedParserState(_ state: ParserState) -> InstantiatedParserState { + return state as! InstantiatedParserState +} diff --git a/Sources/P4Runtime/Expressions.swift b/Sources/P4Runtime/Expressions.swift index 6b16ec7..d28aede 100644 --- a/Sources/P4Runtime/Expressions.swift +++ b/Sources/P4Runtime/Expressions.swift @@ -24,8 +24,7 @@ extension SelectCaseExpression: EvaluatableExpression { } public func type() -> any Common.P4Type { - // TODO - return reject + return ParserState() } } @@ -46,9 +45,8 @@ extension SelectExpression: EvaluatableExpression { } } - // TODO public func type() -> any Common.P4Type { - return reject + return ParserState() } } diff --git a/Sources/P4Runtime/Parser.swift b/Sources/P4Runtime/Parser.swift index 43bc6f8..222f0e5 100644 --- a/Sources/P4Runtime/Parser.swift +++ b/Sources/P4Runtime/Parser.swift @@ -118,11 +118,11 @@ extension ParserStateSelectTransition: EvaluatableParserState { } extension Parser: ParserExecution { - public func execute(execution: ProgramExecution) -> (ParserState, ProgramExecution) { + public func execute(execution: ProgramExecution) -> (InstantiatedParserState, ProgramExecution) { var execution = execution.enter_scope() - execution = execution.declare(identifier: accept.state().state, withValue: accept) - execution = execution.declare(identifier: reject.state().state, withValue: reject) + execution = execution.declare(identifier: AsInstantiatedParserState(accept.state()).state, withValue: accept) + execution = execution.declare(identifier: AsInstantiatedParserState(reject.state()).state, withValue: reject) // Add initial values to the global scope if let initial = execution.initial_values() { @@ -148,6 +148,6 @@ extension Parser: ParserExecution { while !current_state.done() && !execution.hasError() { (current_state, execution) = current_state.execute(program: execution) } - return (current_state.state(), execution) + return (AsInstantiatedParserState(current_state.state()), execution) } } diff --git a/Sources/P4Runtime/Protocols.swift b/Sources/P4Runtime/Protocols.swift index dae3e98..e383a20 100644 --- a/Sources/P4Runtime/Protocols.swift +++ b/Sources/P4Runtime/Protocols.swift @@ -35,5 +35,5 @@ public protocol EvaluatableParserState: P4Value { } public protocol ParserExecution { - func execute(execution: ProgramExecution) -> (ParserState, ProgramExecution) + func execute(execution: ProgramExecution) -> (InstantiatedParserState, ProgramExecution) } diff --git a/Tests/p4rseTests/ArrayTests.swift b/Tests/p4rseTests/ArrayTests.swift index 8cb41d5..37c07cf 100644 --- a/Tests/p4rseTests/ArrayTests.swift +++ b/Tests/p4rseTests/ArrayTests.swift @@ -52,7 +52,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_array_access_invalid_type() async throws { @@ -103,7 +103,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_array_access3() async throws { @@ -130,7 +130,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_array_access4() async throws { @@ -157,7 +157,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_array_access_nested() async throws { @@ -189,7 +189,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_array_set() async throws { @@ -218,7 +218,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_array_set_nested() async throws { @@ -251,5 +251,5 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } diff --git a/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift b/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift index 9be81dd..f6d3f14 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift @@ -45,7 +45,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_and2() async throws { @@ -64,7 +64,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_and3() async throws { @@ -83,7 +83,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_and4() async throws { @@ -102,7 +102,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_or() async throws { @@ -121,7 +121,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_or2() async throws { @@ -140,7 +140,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_or3() async throws { @@ -159,7 +159,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_or4() async throws { @@ -178,7 +178,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_grouped() async throws { @@ -197,7 +197,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_grouped2() async throws { @@ -216,5 +216,5 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } diff --git a/Tests/p4rseTests/BinaryOperatorTests/Bool.swift b/Tests/p4rseTests/BinaryOperatorTests/Bool.swift index 13e3299..15a36c0 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/Bool.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/Bool.swift @@ -45,7 +45,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_equal_not_equal_bool() async throws { @@ -64,7 +64,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_less_than_bool() async throws { @@ -83,7 +83,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_less_than_equal_bool() async throws { @@ -102,7 +102,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_less_than_equal_bool2() async throws { @@ -121,7 +121,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_greater_than_bool() async throws { @@ -140,7 +140,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_greater_than_equal_bool() async throws { @@ -159,7 +159,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_greater_than_equal_bool2() async throws { @@ -178,7 +178,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_less_than_bool_not() async throws { @@ -197,7 +197,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_less_than_bool_not2() async throws { @@ -216,7 +216,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_less_than_equal_bool_not() async throws { @@ -235,7 +235,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_greater_than_bool_not() async throws { @@ -254,7 +254,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_greater_than_bool_not2() async throws { @@ -273,7 +273,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_greater_than_equal_bool_not() async throws { @@ -292,5 +292,5 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } diff --git a/Tests/p4rseTests/BinaryOperatorTests/Integer.swift b/Tests/p4rseTests/BinaryOperatorTests/Integer.swift index 1324fc9..6abbfe3 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/Integer.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/Integer.swift @@ -45,7 +45,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_equal_not_equal_integer() async throws { @@ -64,7 +64,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_less_than_integer() async throws { @@ -83,7 +83,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_less_than_equal_integer() async throws { @@ -102,7 +102,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_less_than_equal_integer2() async throws { @@ -121,7 +121,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_greater_than_integer() async throws { @@ -140,7 +140,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_greater_than_equal_integer() async throws { @@ -159,7 +159,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_greater_than_equal_integer2() async throws { @@ -178,7 +178,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_less_than_integer_not() async throws { @@ -197,7 +197,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_less_than_integer_not2() async throws { @@ -216,7 +216,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_less_than_equal_integer_not() async throws { @@ -235,7 +235,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_greater_than_integer_not() async throws { @@ -254,7 +254,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_greater_than_integer_not2() async throws { @@ -273,7 +273,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_greater_than_equal_integer_not() async throws { @@ -292,7 +292,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @@ -314,7 +314,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_add_non_integer() async throws { @@ -398,7 +398,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_subtract_non_integer() async throws { @@ -483,7 +483,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_multiply_non_integer() async throws { @@ -567,7 +567,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_divide_non_integer() async throws { diff --git a/Tests/p4rseTests/BinaryOperatorTests/String.swift b/Tests/p4rseTests/BinaryOperatorTests/String.swift index bf46ad1..e8b3bbf 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/String.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/String.swift @@ -45,7 +45,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_equal_not_equal_string() async throws { @@ -64,7 +64,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_less_than_string() async throws { @@ -83,7 +83,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_less_than_equal_string() async throws { @@ -102,7 +102,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_greater_than_string() async throws { @@ -121,7 +121,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_greater_than_equal_string() async throws { @@ -140,7 +140,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_binary_operator_less_than_string_not() async throws { @@ -159,7 +159,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_less_than_equal_string_not() async throws { @@ -178,7 +178,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_greater_than_string_not() async throws { @@ -197,7 +197,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_binary_operator_greater_than_equal_string_not() async throws { @@ -216,5 +216,5 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } diff --git a/Tests/p4rseTests/BinaryOperatorTests/Struct.swift b/Tests/p4rseTests/BinaryOperatorTests/Struct.swift index e89a60c..061652c 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/Struct.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/Struct.swift @@ -54,7 +54,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_struct_equality_one_empty() async throws { @@ -87,7 +87,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_struct_equality_neither_empty() async throws { @@ -121,7 +121,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_struct_equality_neither_empty2() async throws { @@ -158,7 +158,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_struct_equality_neither_empty3() async throws { @@ -195,7 +195,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } diff --git a/Tests/p4rseTests/ConditionalTests.swift b/Tests/p4rseTests/ConditionalTests.swift index 8101a9c..d0d6ff6 100644 --- a/Tests/p4rseTests/ConditionalTests.swift +++ b/Tests/p4rseTests/ConditionalTests.swift @@ -49,7 +49,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_parser_with_conditional_statement_and_else() async throws { @@ -77,6 +77,6 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } diff --git a/Tests/p4rseTests/Declarations.swift b/Tests/p4rseTests/Declarations.swift index c7206ef..3669c8c 100644 --- a/Tests/p4rseTests/Declarations.swift +++ b/Tests/p4rseTests/Declarations.swift @@ -49,7 +49,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_struct_declaration_and_field_write_field_read() async throws { @@ -74,7 +74,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_struct_declaration_and_field_read_defaults() async throws { @@ -97,7 +97,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_struct_declaration_and_field_read_defaults_sc() async throws { @@ -120,7 +120,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_struct_declaration_and_field_read_defaults_sc2() async throws { @@ -144,5 +144,5 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } diff --git a/Tests/p4rseTests/ExpressionTests.swift b/Tests/p4rseTests/ExpressionTests.swift index ed000cc..817172d 100644 --- a/Tests/p4rseTests/ExpressionTests.swift +++ b/Tests/p4rseTests/ExpressionTests.swift @@ -44,7 +44,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_expression_grouped_or() async throws { @@ -64,7 +64,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_expression_grouped_and() async throws { @@ -84,5 +84,5 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } diff --git a/Tests/p4rseTests/ExpressionTests/Keyset.swift b/Tests/p4rseTests/ExpressionTests/Keyset.swift deleted file mode 100644 index dbc750b..0000000 --- a/Tests/p4rseTests/ExpressionTests/Keyset.swift +++ /dev/null @@ -1,139 +0,0 @@ -// p4rse, Copyright 2026, Will Hawkins -// -// This file is part of p4rse. -// -// This file is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -import Common -import Foundation -import Macros -import P4Lang -import P4Runtime -import SwiftTreeSitter -import Testing -import TreeSitter -import TreeSitterP4 - -@testable import P4Compiler - -@Test func test_simple_parser_with_transition_select_case_nondefault_expressions() async throws { - let simple_parser_declaration = """ - parser main_parser() { - state start { - transition select (true) { - false: reject; - true: accept; - }; - } - }; - """ - - 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 (state_result, _) = try! #UseOkResult(runtime.run()) - - #expect(parser.states.count() == 1) - - #expect(state_result == P4Lang.accept) -} - -@Test func test_simple_parser_with_transition_select_case_default_expression() async throws { - let simple_parser_declaration = """ - parser main_parser() { - state start { - transition select (5) { - 5: reject; - _: accept; - }; - } - }; - """ - - 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 (state_result, _) = try! #UseOkResult(runtime.run()) - - #expect(parser.states.count() == 1) - - #expect(state_result == P4Lang.reject) -} - -@Test func test_simple_parser_with_transition_select_case_default_expression2() async throws { - let simple_parser_declaration = """ - parser main_parser() { - state start { - transition select (1) { - 5: reject; - _: accept; - }; - } - }; - """ - - 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 (state_result, _) = try! #UseOkResult(runtime.run()) - - #expect(parser.states.count() == 1) - - #expect(state_result == P4Lang.accept) -} - -@Test func test_simple_parser_with_transition_select_case_default_expression3() async throws { - let simple_parser_declaration = """ - parser main_parser() { - state start { - transition select (6) { - 5: reject; - 6: reject; - _: accept; - }; - } - }; - """ - - 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 (state_result, _) = try! #UseOkResult(runtime.run()) - - #expect(parser.states.count() == 1) - - #expect(state_result == P4Lang.reject) -} - -@Test func test_simple_parser_with_transition_select_case_invalid_type() async throws { - let simple_parser_declaration = """ - parser main_parser() { - state start { - transition select (6) { - true: reject; - 6: reject; - _: accept; - }; - } - }; - """ - - #expect( - #RequireErrorResult( - Error( - withMessage: - "Error(s) parsing select cases: {81, 12}: Keyset expression type does not match selector expression type" - ), - Program.Compile(simple_parser_declaration))) -} diff --git a/Tests/p4rseTests/ParserCompilerTests.swift b/Tests/p4rseTests/ParserCompilerTests.swift index 0b59392..a80bacd 100644 --- a/Tests/p4rseTests/ParserCompilerTests.swift +++ b/Tests/p4rseTests/ParserCompilerTests.swift @@ -56,7 +56,7 @@ import P4Lang #expect(parser.states.count() == 1) - let state = try! #require(parser.states.find(withIdentifier: Identifier(name: "start"))) + let state = AsInstantiatedParserState((try! #require(parser.states.find(withIdentifier: Identifier(name: "start"))))) #expect(state.state == Identifier(name: "start")) #expect(state.statements.count == 1) } diff --git a/Tests/p4rseTests/RuntimeTests.swift b/Tests/p4rseTests/RuntimeTests.swift index 8e37aa0..1be72c8 100644 --- a/Tests/p4rseTests/RuntimeTests.swift +++ b/Tests/p4rseTests/RuntimeTests.swift @@ -42,7 +42,7 @@ import TreeSitterP4 let (state_result, _) = try! #UseOkResult(runtime.run()) // We should be in the accept state. - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_runtime_to_accept() async throws { @@ -59,7 +59,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) // We should be in the accept state. - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_runtime_no_start_state() async throws { diff --git a/Tests/p4rseTests/ScopeRuntimeTests.swift b/Tests/p4rseTests/ScopeRuntimeTests.swift index 61c2a95..6d4a8bb 100644 --- a/Tests/p4rseTests/ScopeRuntimeTests.swift +++ b/Tests/p4rseTests/ScopeRuntimeTests.swift @@ -46,7 +46,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_scope() async throws { @@ -72,7 +72,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @@ -100,7 +100,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_simple_assignment() async throws { @@ -124,7 +124,7 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @@ -155,5 +155,5 @@ import TreeSitterP4 let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } \ No newline at end of file diff --git a/Tests/p4rseTests/StructTests.swift b/Tests/p4rseTests/StructTests.swift index 70e4f68..56ab83c 100644 --- a/Tests/p4rseTests/StructTests.swift +++ b/Tests/p4rseTests/StructTests.swift @@ -59,7 +59,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_field_access_declared() async throws { @@ -88,7 +88,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_field_access_declared2() async throws { @@ -118,7 +118,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_field_access_opp() async throws { @@ -153,7 +153,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @@ -188,7 +188,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_field_access2_opp() async throws { @@ -222,7 +222,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_field_access_nested() async throws { @@ -268,7 +268,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_field_write() async throws { @@ -304,7 +304,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_field_write_invalid_type() async throws { @@ -377,7 +377,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_field_write_nested2() async throws { @@ -425,7 +425,7 @@ import TreeSitterP4 Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values)) let (state_result, _) = try! #UseOkResult(runtime.run()) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_field_write_nested_invalid_type() async throws { diff --git a/Tests/p4rseTests/TransitionTests.swift b/Tests/p4rseTests/TransitionTests.swift index 591a944..bdbeff3 100644 --- a/Tests/p4rseTests/TransitionTests.swift +++ b/Tests/p4rseTests/TransitionTests.swift @@ -46,7 +46,7 @@ import TreeSitterP4 #expect(parser.states.count() == 1) - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_simple_parser_with_transition_select_expression_to_reject() async throws { @@ -67,7 +67,7 @@ import TreeSitterP4 let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(parser.states.count() == 1) - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_no_matching_key_transition() async throws { diff --git a/Tests/p4rseTests/ValueTypeParserTests.swift b/Tests/p4rseTests/ValueTypeParserTests.swift index f71586d..58eef72 100644 --- a/Tests/p4rseTests/ValueTypeParserTests.swift +++ b/Tests/p4rseTests/ValueTypeParserTests.swift @@ -147,7 +147,7 @@ import TreeSitterP4 // 5 == 5 == true // true == true // true - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_expression_in_declaration_initializer2() async throws { @@ -169,7 +169,7 @@ import TreeSitterP4 // 5 == 5 == true // true == false // false - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_expression_in_declaration_initializer_false() async throws { @@ -191,7 +191,7 @@ import TreeSitterP4 // 6 == 5 == true // false == true // false - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_expression_in_declaration_initializer_false2() async throws { @@ -213,7 +213,7 @@ import TreeSitterP4 // 6 == 5 == false // false == false // true - #expect(state_result == P4Lang.accept) + #expect(AsInstantiatedParserState(state_result) == P4Lang.accept) } @Test func test_expression_in_declaration_initializer_invalid_types() async throws { @@ -237,7 +237,7 @@ import TreeSitterP4 // false == 5 == true // false == true // false - #expect(state_result == P4Lang.reject) + #expect(AsInstantiatedParserState(state_result) == P4Lang.reject) } @Test func test_expression_in_declaration_initializer_invalid_types2() async throws {