Refactor Parser States
Refactor the class hierarchy for parser states so that there is a parser state that acts more like a type and one that acts more like a value (the latter, then, serves as the base class for the other instantiated parser states). Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -84,7 +84,7 @@ public struct Parser {
|
|||||||
static func Compile(
|
static func Compile(
|
||||||
node: Node, forState state_identifier: Common.Identifier,
|
node: Node, forState state_identifier: Common.Identifier,
|
||||||
withStatements stmts: [EvaluatableStatement], withContext context: CompilerContext
|
withStatements stmts: [EvaluatableStatement], withContext context: CompilerContext
|
||||||
) -> Result<(ParserState, CompilerContext)> {
|
) -> Result<(InstantiatedParserState, CompilerContext)> {
|
||||||
|
|
||||||
#RequireNodeType<Node, (EvaluatableStatement, CompilerContext)>(
|
#RequireNodeType<Node, (EvaluatableStatement, CompilerContext)>(
|
||||||
node: node, type: "parserTransitionStatement", nice_type_name: "parser transition statement"
|
node: node, type: "parserTransitionStatement", nice_type_name: "parser transition statement"
|
||||||
@@ -177,7 +177,7 @@ public struct Parser {
|
|||||||
public struct State {
|
public struct State {
|
||||||
static func Compile(
|
static func Compile(
|
||||||
node: Node, withContext context: CompilerContext
|
node: Node, withContext context: CompilerContext
|
||||||
) -> Result<(ParserState, CompilerContext)> {
|
) -> Result<(InstantiatedParserState, CompilerContext)> {
|
||||||
|
|
||||||
var currentChildIdx = 0
|
var currentChildIdx = 0
|
||||||
var currentChildIdxSafe = 1
|
var currentChildIdxSafe = 1
|
||||||
|
|||||||
+91
-15
@@ -40,9 +40,11 @@ public struct ParserAssignmentStatement {
|
|||||||
/// A P4 Parser State
|
/// A P4 Parser State
|
||||||
///
|
///
|
||||||
/// Note: A P4 Parser State is both a type and a value.
|
/// 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 class ParserState: P4Type, P4Value, Equatable, CustomStringConvertible {
|
||||||
public static func == (lhs: ParserState, rhs: ParserState) -> Bool {
|
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 {
|
public func eq(rhs: any Common.P4Type) -> Bool {
|
||||||
@@ -56,37 +58,106 @@ public class ParserState: P4Type, P4Value, Equatable, CustomStringConvertible {
|
|||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Any operation between two "bare" parser states is always true.
|
||||||
public func eq(rhs: any Common.P4Value) -> Bool {
|
public func eq(rhs: any Common.P4Value) -> Bool {
|
||||||
return switch rhs {
|
return switch rhs {
|
||||||
case let other as ParserState: self.state == other.state
|
case is ParserState: true
|
||||||
default: false
|
default: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func lt(rhs: any Common.P4Value) -> Bool {
|
public func lt(rhs: any Common.P4Value) -> Bool {
|
||||||
return switch rhs {
|
return switch rhs {
|
||||||
case let other as ParserState: self.state < other.state
|
case is ParserState: true
|
||||||
default: false
|
default: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func lte(rhs: any Common.P4Value) -> Bool {
|
public func lte(rhs: any Common.P4Value) -> Bool {
|
||||||
return switch rhs {
|
return switch rhs {
|
||||||
case let other as ParserState: self.state <= other.state
|
case is ParserState: true
|
||||||
default: false
|
default: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func gt(rhs: any Common.P4Value) -> Bool {
|
public func gt(rhs: any Common.P4Value) -> Bool {
|
||||||
return switch rhs {
|
return switch rhs {
|
||||||
case let other as ParserState: self.state > other.state
|
case is ParserState: true
|
||||||
default: false
|
default: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func gte(rhs: any Common.P4Value) -> Bool {
|
public func gte(rhs: any Common.P4Value) -> Bool {
|
||||||
return switch rhs {
|
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
|
default: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +165,7 @@ public class ParserState: P4Type, P4Value, Equatable, CustomStringConvertible {
|
|||||||
public private(set) var state: Identifier
|
public private(set) var state: Identifier
|
||||||
public private(set) var statements: [EvaluatableStatement]
|
public private(set) var statements: [EvaluatableStatement]
|
||||||
|
|
||||||
public var description: String {
|
public override var description: String {
|
||||||
return "Name: \(state)"
|
return "Name: \(state)"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,12 +185,12 @@ public class ParserState: P4Type, P4Value, Equatable, CustomStringConvertible {
|
|||||||
statements = Array()
|
statements = Array()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func def() -> any P4Value {
|
public override func def() -> any P4Value {
|
||||||
return ParserState(name: Identifier(name: ""))
|
return InstantiatedParserState(name: Identifier(name: ""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ParserStateDirectTransition: ParserState {
|
public class ParserStateDirectTransition: InstantiatedParserState {
|
||||||
|
|
||||||
private let next_state: Identifier
|
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]) {
|
public override init(name: Identifier, withStatements stmts: [any EvaluatableStatement]) {
|
||||||
super.init(name: name, withStatements: stmts)
|
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
|
public let selectExpression: SelectExpression
|
||||||
|
|
||||||
@@ -172,7 +243,7 @@ nonisolated(unsafe) public let reject = ParserStateNoTransition(
|
|||||||
name: Identifier(name: "reject"), withStatements: [])
|
name: Identifier(name: "reject"), withStatements: [])
|
||||||
|
|
||||||
public struct ParserStates {
|
public struct ParserStates {
|
||||||
public var states: [ParserState] = Array()
|
public var states: [InstantiatedParserState] = Array()
|
||||||
|
|
||||||
public func count() -> Int {
|
public func count() -> Int {
|
||||||
return states.count
|
return states.count
|
||||||
@@ -191,11 +262,11 @@ public struct ParserStates {
|
|||||||
self.states = Array()
|
self.states = Array()
|
||||||
}
|
}
|
||||||
|
|
||||||
private init(withStates states: [ParserState]) {
|
private init(withStates states: [InstantiatedParserState]) {
|
||||||
self.states = states
|
self.states = states
|
||||||
}
|
}
|
||||||
|
|
||||||
public func append(state: ParserState) -> ParserStates {
|
public func append(state: InstantiatedParserState) -> ParserStates {
|
||||||
var new_states = self.states
|
var new_states = self.states
|
||||||
new_states.append(state)
|
new_states.append(state)
|
||||||
return ParserStates(withStates: new_states)
|
return ParserStates(withStates: new_states)
|
||||||
@@ -278,3 +349,8 @@ public struct Parser: P4Type, P4Value {
|
|||||||
return Parser(withName: Identifier(name: ""))
|
return Parser(withName: Identifier(name: ""))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Launder a parser state into an instantiated parser state.
|
||||||
|
public func AsInstantiatedParserState(_ state: ParserState) -> InstantiatedParserState {
|
||||||
|
return state as! InstantiatedParserState
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ extension SelectCaseExpression: EvaluatableExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func type() -> any Common.P4Type {
|
public func type() -> any Common.P4Type {
|
||||||
// TODO
|
return ParserState()
|
||||||
return reject
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,9 +45,8 @@ extension SelectExpression: EvaluatableExpression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
public func type() -> any Common.P4Type {
|
public func type() -> any Common.P4Type {
|
||||||
return reject
|
return ParserState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,11 +118,11 @@ extension ParserStateSelectTransition: EvaluatableParserState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension Parser: ParserExecution {
|
extension Parser: ParserExecution {
|
||||||
public func execute(execution: ProgramExecution) -> (ParserState, ProgramExecution) {
|
public func execute(execution: ProgramExecution) -> (InstantiatedParserState, ProgramExecution) {
|
||||||
var execution = execution.enter_scope()
|
var execution = execution.enter_scope()
|
||||||
|
|
||||||
execution = execution.declare(identifier: accept.state().state, withValue: accept)
|
execution = execution.declare(identifier: AsInstantiatedParserState(accept.state()).state, withValue: accept)
|
||||||
execution = execution.declare(identifier: reject.state().state, withValue: reject)
|
execution = execution.declare(identifier: AsInstantiatedParserState(reject.state()).state, withValue: reject)
|
||||||
|
|
||||||
// Add initial values to the global scope
|
// Add initial values to the global scope
|
||||||
if let initial = execution.initial_values() {
|
if let initial = execution.initial_values() {
|
||||||
@@ -148,6 +148,6 @@ extension Parser: ParserExecution {
|
|||||||
while !current_state.done() && !execution.hasError() {
|
while !current_state.done() && !execution.hasError() {
|
||||||
(current_state, execution) = current_state.execute(program: execution)
|
(current_state, execution) = current_state.execute(program: execution)
|
||||||
}
|
}
|
||||||
return (current_state.state(), execution)
|
return (AsInstantiatedParserState(current_state.state()), execution)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,5 +35,5 @@ public protocol EvaluatableParserState: P4Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public protocol ParserExecution {
|
public protocol ParserExecution {
|
||||||
func execute(execution: ProgramExecution) -> (ParserState, ProgramExecution)
|
func execute(execution: ProgramExecution) -> (InstantiatedParserState, ProgramExecution)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
|
|
||||||
#expect(state_result == P4Lang.accept)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
|
|
||||||
#expect(state_result == P4Lang.reject)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
|
|
||||||
#expect(state_result == P4Lang.reject)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_simple_parser_binary_operator_divide_non_integer() async throws {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
|
|
||||||
#expect(state_result == P4Lang.reject)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ import TreeSitterP4
|
|||||||
|
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
#expect(state_result == P4Lang.reject)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
|
|
||||||
#expect(state_result == P4Lang.accept)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration))
|
Program.Compile(simple_parser_declaration))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_struct_declaration_and_field_write_field_read() async throws {
|
||||||
@@ -74,7 +74,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration))
|
Program.Compile(simple_parser_declaration))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_struct_declaration_and_field_read_defaults() async throws {
|
||||||
@@ -97,7 +97,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration))
|
Program.Compile(simple_parser_declaration))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_struct_declaration_and_field_read_defaults_sc() async throws {
|
||||||
@@ -120,7 +120,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration))
|
Program.Compile(simple_parser_declaration))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_struct_declaration_and_field_read_defaults_sc2() async throws {
|
||||||
@@ -144,5 +144,5 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration))
|
Program.Compile(simple_parser_declaration))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
#expect(state_result == P4Lang.reject)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_expression_grouped_or() async throws {
|
||||||
@@ -64,7 +64,7 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_expression_grouped_and() async throws {
|
||||||
@@ -84,5 +84,5 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
|
|
||||||
#expect(state_result == P4Lang.reject)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
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)))
|
|
||||||
}
|
|
||||||
@@ -56,7 +56,7 @@ import P4Lang
|
|||||||
|
|
||||||
#expect(parser.states.count() == 1)
|
#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.state == Identifier(name: "start"))
|
||||||
#expect(state.statements.count == 1)
|
#expect(state.statements.count == 1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import TreeSitterP4
|
|||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
|
|
||||||
// We should be in the accept state.
|
// We should be in the accept state.
|
||||||
#expect(state_result == P4Lang.accept)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func test_simple_runtime_to_accept() async throws {
|
@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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
// We should be in the accept state.
|
// We should be in the accept state.
|
||||||
#expect(state_result == P4Lang.reject)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func test_simple_runtime_no_start_state() async throws {
|
@Test func test_simple_runtime_no_start_state() async throws {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_simple_scope() async throws {
|
||||||
@@ -72,7 +72,7 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_simple_assignment() async throws {
|
||||||
@@ -124,7 +124,7 @@ import TreeSitterP4
|
|||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
|
|
||||||
#expect(state_result == P4Lang.reject)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_field_access_declared() async throws {
|
||||||
@@ -88,7 +88,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
|
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_field_access_declared2() async throws {
|
||||||
@@ -118,7 +118,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
|
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_field_access_opp() async throws {
|
||||||
@@ -153,7 +153,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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))
|
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_field_access2_opp() async throws {
|
||||||
@@ -222,7 +222,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_field_access_nested() async throws {
|
||||||
@@ -268,7 +268,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_field_write() async throws {
|
||||||
@@ -304,7 +304,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_field_write_invalid_type() async throws {
|
||||||
@@ -377,7 +377,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_field_write_nested2() async throws {
|
||||||
@@ -425,7 +425,7 @@ import TreeSitterP4
|
|||||||
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
|
||||||
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withInitialValues: test_values))
|
||||||
let (state_result, _) = try! #UseOkResult(runtime.run())
|
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 {
|
@Test func test_field_write_nested_invalid_type() async throws {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import TreeSitterP4
|
|||||||
|
|
||||||
#expect(parser.states.count() == 1)
|
#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 {
|
@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())
|
let (state_result, _) = try! #UseOkResult(runtime.run())
|
||||||
|
|
||||||
#expect(parser.states.count() == 1)
|
#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 {
|
@Test func test_no_matching_key_transition() async throws {
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ import TreeSitterP4
|
|||||||
// 5 == 5 == true
|
// 5 == 5 == true
|
||||||
// true == true
|
// true == true
|
||||||
// true
|
// true
|
||||||
#expect(state_result == P4Lang.accept)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func test_expression_in_declaration_initializer2() async throws {
|
@Test func test_expression_in_declaration_initializer2() async throws {
|
||||||
@@ -169,7 +169,7 @@ import TreeSitterP4
|
|||||||
// 5 == 5 == true
|
// 5 == 5 == true
|
||||||
// true == false
|
// true == false
|
||||||
// false
|
// false
|
||||||
#expect(state_result == P4Lang.reject)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func test_expression_in_declaration_initializer_false() async throws {
|
@Test func test_expression_in_declaration_initializer_false() async throws {
|
||||||
@@ -191,7 +191,7 @@ import TreeSitterP4
|
|||||||
// 6 == 5 == true
|
// 6 == 5 == true
|
||||||
// false == true
|
// false == true
|
||||||
// false
|
// false
|
||||||
#expect(state_result == P4Lang.reject)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func test_expression_in_declaration_initializer_false2() async throws {
|
@Test func test_expression_in_declaration_initializer_false2() async throws {
|
||||||
@@ -213,7 +213,7 @@ import TreeSitterP4
|
|||||||
// 6 == 5 == false
|
// 6 == 5 == false
|
||||||
// false == false
|
// false == false
|
||||||
// true
|
// true
|
||||||
#expect(state_result == P4Lang.accept)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func test_expression_in_declaration_initializer_invalid_types() async throws {
|
@Test func test_expression_in_declaration_initializer_invalid_types() async throws {
|
||||||
@@ -237,7 +237,7 @@ import TreeSitterP4
|
|||||||
// false == 5 == true
|
// false == 5 == true
|
||||||
// false == true
|
// false == true
|
||||||
// false
|
// false
|
||||||
#expect(state_result == P4Lang.reject)
|
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func test_expression_in_declaration_initializer_invalid_types2() async throws {
|
@Test func test_expression_in_declaration_initializer_invalid_types2() async throws {
|
||||||
|
|||||||
Reference in New Issue
Block a user