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
@@ -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)
}