compiler, language, runtime: Separate Parser Type From Instances
Continuous Integration / Grammar Tests (push) Successful in 4m2s
Continuous Integration / Library Format Tests (push) Successful in 5m0s
Continuous Integration / Library Tests (push) Successful in 8m1s

In P4, parsers are considered types. Those parsers are instantiated.
The instantiated parsers are values. Previously, gp4 treated a parser
type and a parser value as identical. This PR makes that difference
clear _and_ sets the stage for the future.

TODO: Make the same distinction between control and action types and
values.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-05-27 05:41:23 -04:00
parent 925f20a13b
commit 61d8f601e8
36 changed files with 1058 additions and 796 deletions
+12 -12
View File
@@ -41,14 +41,14 @@ import TreeSitterP4
}
};
"""
let x = { (tipe: P4QualifiedType) -> Bool in
switch tipe.baseType() {
let x = { (tipe: P4Type) -> Bool in
switch tipe {
case let c as Control: c.name == "simple"
default: false
}
}
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
#expect(program.InstancesWithTypes(x).count == 1)
#expect(program.TypesWithTypes(x).count == 1)
}
@Test func test_simple_control_declaration2() async throws {
@@ -79,14 +79,14 @@ import TreeSitterP4
};
"""
let filter = { (tipe: P4QualifiedType) -> Bool in
switch tipe.baseType() {
let filter = { (tipe: P4Type) -> Bool in
switch tipe {
case let c as Control: c.name == "simple" || c.name == "complex"
default: false
}
}
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
#expect(program.InstancesWithTypes(filter).count == 2)
#expect(program.TypesWithTypes(filter).count == 2)
}
@Test func test_simple_control_declaration_with_actions() async throws {
@@ -106,14 +106,14 @@ import TreeSitterP4
}
};
"""
let x = { (tipe: P4QualifiedType) -> Bool in
switch tipe.baseType() {
let x = { (tipe: P4Type) -> Bool in
switch tipe {
case let c as Control: c.name == "simple"
default: false
}
}
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
#expect(program.InstancesWithTypes(x).count == 1)
#expect(program.TypesWithTypes(x).count == 1)
}
@Test func test_simple_control_declaration_with_misnamed_actions() async throws {
@@ -341,14 +341,14 @@ import TreeSitterP4
};
"""
let x = { (tipe: P4QualifiedType) -> Bool in
switch tipe.baseType() {
let x = { (tipe: P4Type) -> Bool in
switch tipe {
case let c as Control: c.name == "simple"
default: false
}
}
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
#expect(program.InstancesWithTypes(x).count == 1)
#expect(program.TypesWithTypes(x).count == 1)
}
@Test func test_simple_control_declaration_with_action_with_params_wrong_order() async throws {