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:
Will Hawkins
2026-03-30 05:16:48 -04:00
parent fda9858680
commit 7c9ecc2438
21 changed files with 199 additions and 264 deletions
+7 -7
View File
@@ -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)
}
@@ -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)
}
+14 -14
View File
@@ -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)
}
@@ -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 {
@@ -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)
}
@@ -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)
}
+2 -2
View File
@@ -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)
}
+5 -5
View File
@@ -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)
}
+3 -3
View File
@@ -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)
}
@@ -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)))
}
+1 -1
View File
@@ -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)
}
+2 -2
View File
@@ -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 {
+5 -5
View File
@@ -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)
}
+10 -10
View File
@@ -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 {
+2 -2
View File
@@ -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 {
+5 -5
View File
@@ -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 {