Refactor Names of Scope Types

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-03-20 04:23:53 -04:00
parent 6a9a138afe
commit f0d816b99f
12 changed files with 144 additions and 163 deletions
+16 -6
View File
@@ -29,10 +29,20 @@ import TreeSitterP4
@Test func test_invalid_types() async throws {
for invalid_type_name in ["boo", "str", "in"] {
#expect(
#RequireErrorResult(
Error(withMessage: "Type name not recognized"),
Types.CompileBasicType(type: invalid_type_name)))
let simple_parser_declaration = """
parser main_parser() {
state start {
\(invalid_type_name) v = 1;
transition reject;
}
};
""";
let err = Program.Compile(simple_parser_declaration)
guard case Result.Error(let e) = err else {
assert(false, "Expected an error, but had success")
}
#expect(e.msg.contains("Failed to parse a statement element: Could not parse a P4 type from \(invalid_type_name)"))
}
}
@@ -242,7 +252,7 @@ import TreeSitterP4
}
};
"""
var test_types = LexicalScopes().enter()
var test_types = VarTypeScopes().enter()
test_types = test_types.declare(identifier: Identifier(name: "ta"), withValue: P4Array(withValueType: P4Int()))
#expect(
#RequireErrorResult(
@@ -250,5 +260,5 @@ import TreeSitterP4
withMessage:
"{49, 22}: Failed to parse a statement element: Cannot initialize where_to (with type Boolean) from rvalue with type Int"
),
Program.Compile(simple_parser_declaration, withGlobalTypes: test_types)))
Program.Compile(simple_parser_declaration, withGlobalInstances: test_types)))
}