compiler: Refactor Compiler To Remove Ambiguities
Continuous Integration / Grammar Tests (push) Successful in 39s
Continuous Integration / Library Format Tests (push) Successful in 1m51s
Continuous Integration / Library Tests (push) Failing after 4m44s

There were significant overlaps in the names of data structures
between the compiler and the language that made it necessary
to litter the code with P4Lang.xxxx. This refactor removes that
requirement in most places (Parser is ambiguous wherever TreeSitter
is used -- cannot avoid that!)

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-05-27 12:59:29 -04:00
parent 61d8f601e8
commit 294f76acd4
39 changed files with 735 additions and 699 deletions
+8 -8
View File
@@ -56,7 +56,7 @@ import TreeSitterP4
P4Value(P4IntValue(withValue: 3)),
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -87,7 +87,7 @@ import TreeSitterP4
withMessage:
"{49, 22}: Failed to parse a statement element: {65, 2}: ta does not name an array type"
),
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
)
}
@@ -119,7 +119,7 @@ import TreeSitterP4
P4Value(P4IntValue(withValue: 3)),
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -155,7 +155,7 @@ import TreeSitterP4
P4Value(P4IntValue(withValue: 3)),
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -190,7 +190,7 @@ import TreeSitterP4
P4Value(P4IntValue(withValue: 3)),
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -237,7 +237,7 @@ import TreeSitterP4
withValue: [nested])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -276,7 +276,7 @@ import TreeSitterP4
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -325,7 +325,7 @@ import TreeSitterP4
withValue: [nested])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -41,7 +41,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -60,7 +60,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -79,7 +79,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -98,7 +98,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -117,7 +117,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -136,7 +136,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -155,7 +155,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -174,7 +174,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -193,7 +193,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -212,7 +212,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
+14 -14
View File
@@ -41,7 +41,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -60,7 +60,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -79,7 +79,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -98,7 +98,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -117,7 +117,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -136,7 +136,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -155,7 +155,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -174,7 +174,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -193,7 +193,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -212,7 +212,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -231,7 +231,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -250,7 +250,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -269,7 +269,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -288,7 +288,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -41,7 +41,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -60,7 +60,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -79,7 +79,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -98,7 +98,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -117,7 +117,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -136,7 +136,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -155,7 +155,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -174,7 +174,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -193,7 +193,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -212,7 +212,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -231,7 +231,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -250,7 +250,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -269,7 +269,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -288,7 +288,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -310,7 +310,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -335,7 +335,7 @@ import TreeSitterP4
withMessage:
"{72, 12}: Could not parse transition select expression selector expression: Mathematical operation on operands with non-int type is not allowed"
),
Program.Compile(simple)))
SpecialCompilers.ProgramCompiler.Compile(simple)))
}
@Test func test_simple_parser_binary_operator_add_non_integer2() async throws {
@@ -356,7 +356,7 @@ import TreeSitterP4
withMessage:
"{72, 9}: Could not parse transition select expression selector expression: Types of values used with binary expression are not the same"
),
Program.Compile(simple)))
SpecialCompilers.ProgramCompiler.Compile(simple)))
}
// Subtract Integers
@@ -373,7 +373,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -398,7 +398,7 @@ import TreeSitterP4
withMessage:
"{72, 12}: Could not parse transition select expression selector expression: Mathematical operation on operands with non-int type is not allowed"
),
Program.Compile(simple)))
SpecialCompilers.ProgramCompiler.Compile(simple)))
}
@Test func test_simple_parser_binary_operator_subtract_non_integer2() async throws {
@@ -419,7 +419,7 @@ import TreeSitterP4
withMessage:
"{72, 9}: Could not parse transition select expression selector expression: Types of values used with binary expression are not the same"
),
Program.Compile(simple)))
SpecialCompilers.ProgramCompiler.Compile(simple)))
}
// Multiply Integers
@@ -436,7 +436,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -461,7 +461,7 @@ import TreeSitterP4
withMessage:
"{72, 12}: Could not parse transition select expression selector expression: Mathematical operation on operands with non-int type is not allowed"
),
Program.Compile(simple)))
SpecialCompilers.ProgramCompiler.Compile(simple)))
}
@Test func test_simple_parser_binary_operator_multiply_non_integer2() async throws {
@@ -482,7 +482,7 @@ import TreeSitterP4
withMessage:
"{72, 9}: Could not parse transition select expression selector expression: Types of values used with binary expression are not the same"
),
Program.Compile(simple)))
SpecialCompilers.ProgramCompiler.Compile(simple)))
}
// Divide Integers
@@ -499,7 +499,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -524,7 +524,7 @@ import TreeSitterP4
withMessage:
"{72, 12}: Could not parse transition select expression selector expression: Mathematical operation on operands with non-int type is not allowed"
),
Program.Compile(simple)))
SpecialCompilers.ProgramCompiler.Compile(simple)))
}
@Test func test_simple_parser_binary_operator_divide_non_integer2() async throws {
@@ -545,5 +545,5 @@ import TreeSitterP4
withMessage:
"{72, 9}: Could not parse transition select expression selector expression: Types of values used with binary expression are not the same"
),
Program.Compile(simple)))
SpecialCompilers.ProgramCompiler.Compile(simple)))
}
@@ -41,7 +41,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -60,7 +60,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -79,7 +79,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -98,7 +98,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -117,7 +117,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -136,7 +136,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -155,7 +155,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -174,7 +174,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -193,7 +193,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -212,7 +212,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -49,7 +49,7 @@ import TreeSitterP4
test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type)
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -81,7 +81,7 @@ import TreeSitterP4
test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type)
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -114,7 +114,7 @@ import TreeSitterP4
test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type)
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -150,7 +150,7 @@ import TreeSitterP4
test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type)
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -186,7 +186,7 @@ import TreeSitterP4
test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type)
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
+2 -2
View File
@@ -41,7 +41,7 @@ func shrink(_ from: String) -> String {
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let cg = try #UseOkResult(CodeGenerator().codeGen(program))
let expected = shrink(
@@ -73,7 +73,7 @@ func shrink(_ from: String) -> String {
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let cg = try #UseOkResult(CodeGenerator().codeGen(program))
/// TODO: Fix this test.
+2 -2
View File
@@ -45,7 +45,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -73,7 +73,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
+14 -14
View File
@@ -47,7 +47,7 @@ import TreeSitterP4
default: false
}
}
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
#expect(program.TypesWithTypes(x).count == 1)
}
@@ -85,7 +85,7 @@ import TreeSitterP4
default: false
}
}
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
#expect(program.TypesWithTypes(filter).count == 2)
}
@@ -112,7 +112,7 @@ import TreeSitterP4
default: false
}
}
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
#expect(program.TypesWithTypes(x).count == 1)
}
@@ -139,7 +139,7 @@ import TreeSitterP4
withMessage:
"{54, 63}: Error(s) parsing property list: {91, 26}: Error(s) parsing table actions: Cannot find b in lexical scope."
),
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
)
}
@@ -167,7 +167,7 @@ import TreeSitterP4
withMessage:
"{54, 72}: Error(s) parsing property list: {91, 35}: Error(s) parsing table actions: Cannot find b in lexical scope."
),
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
)
}
@@ -195,7 +195,7 @@ import TreeSitterP4
withMessage:
"{64, 63}: Error(s) parsing property list: {101, 26}: Error(s) parsing table actions: {101, 26}: a does not name an action"
),
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
)
}
@@ -214,7 +214,7 @@ import TreeSitterP4
}
};
"""
#expect(#RequireOkResult(Program.Compile(simple_parser_declaration)))
#expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@Test func test_simple_control_declaration_with_multiple_tables() async throws {
@@ -243,7 +243,7 @@ import TreeSitterP4
Error(
withMessage: "{0, 215}: More than one table in control declaration"
),
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
)
}
@@ -263,7 +263,7 @@ import TreeSitterP4
}
};
"""
#expect(#RequireOkResult(Program.Compile(simple_parser_declaration)))
#expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@Test func test_simple_control_declaration_with_action_using_parameter_wrong_type() async throws {
@@ -288,7 +288,7 @@ import TreeSitterP4
withMessage:
"{57, 10}: Failed to parse a statement element: {57, 1}: Cannot assign value with type Boolean to identifier z with type Int (width: Infinite)"
),
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
)
}
@@ -320,7 +320,7 @@ import TreeSitterP4
withMessage:
"Could not compile the P4 program"
),
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
)
}
@@ -347,7 +347,7 @@ import TreeSitterP4
default: false
}
}
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
#expect(program.TypesWithTypes(x).count == 1)
}
@@ -372,7 +372,7 @@ import TreeSitterP4
ErrorWithLocation(
sourceLocation: SourceLocation(41, 23),
withError: "All parameters with direction must precede directionless parameters"),
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
)
}
@@ -397,6 +397,6 @@ import TreeSitterP4
ErrorWithLocation(
sourceLocation: SourceLocation(41, 38),
withError: "All parameters with direction must precede directionless parameters"),
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
)
}
+7 -7
View File
@@ -50,7 +50,7 @@ import TreeSitterP4
};
"""
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
// Pull the control out of the compiled program.
let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in
@@ -125,7 +125,7 @@ import TreeSitterP4
};
"""
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
// Pull the control out of the compiled program.
let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in
@@ -200,7 +200,7 @@ import TreeSitterP4
};
"""
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
// Pull the control out of the compiled program.
let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in
@@ -274,7 +274,7 @@ import TreeSitterP4
};
"""
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
// Pull the control out of the compiled program.
let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in
@@ -349,7 +349,7 @@ import TreeSitterP4
};
"""
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
// Pull the control out of the compiled program.
let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in
@@ -429,7 +429,7 @@ import TreeSitterP4
};
"""
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
// Pull the control out of the compiled program.
let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in
@@ -557,7 +557,7 @@ import TreeSitterP4
};
"""
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
// Pull the control out of the compiled program.
let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in
+9 -9
View File
@@ -46,7 +46,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(state_result == P4Lang.accept)
@@ -71,7 +71,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(state_result == P4Lang.accept)
@@ -94,7 +94,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(state_result == P4Lang.accept)
@@ -117,7 +117,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(state_result == P4Lang.accept)
@@ -141,7 +141,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(state_result == P4Lang.reject)
@@ -153,7 +153,7 @@ import TreeSitterP4
int count;
};
"""
#expect(#RequireOkResult(Program.Compile(simple_parser_declaration)))
#expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@@ -163,7 +163,7 @@ import TreeSitterP4
x = true;
};
"""
#expect(#RequireOkResult(Program.Compile(simple_parser_declaration)))
#expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@Test func test_function_declaration_with_parameters_and_direction() async throws {
@@ -178,7 +178,7 @@ import TreeSitterP4
withMessage:
"{63, 9}: Failed to parse a statement element: {63, 1}: Cannot assign value with type Boolean to identifier x that is in parameter"
),
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
)
}
@@ -198,7 +198,7 @@ import TreeSitterP4
withMessage:
"{120, 15}: Failed to parse a statement element: {120, 7}: Cannot assign to field yesno of x that is in parameter"
),
Program.Compile(simple_parser_declaration))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
)
}
+3 -3
View File
@@ -40,7 +40,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -60,7 +60,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -80,7 +80,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -44,7 +44,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -73,7 +73,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -101,7 +101,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -128,7 +128,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -154,7 +154,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -180,7 +180,7 @@ import TreeSitterP4
};
"""
let error = try #UseErrorResult(Program.Compile(simple_parser_declaration))
let error = try #UseErrorResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
#expect(error.msg().contains("{29, 12}: Type of expression in return statement (Boolean) is not compatible with function return type (Int (width: Infinite))"))
}
@@ -39,7 +39,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -61,7 +61,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -83,7 +83,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -105,7 +105,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -134,7 +134,7 @@ import TreeSitterP4
withMessage:
"Error(s) parsing select cases: {81, 4}: Key expression of type Boolean is not compatible with selector type Int (width: Infinite)"
),
Program.Compile(simple_parser_declaration)))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@Test func test_select_expression_selection_order() async throws {
@@ -149,7 +149,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -171,7 +171,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let args = ArgumentList([
@@ -192,7 +192,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let args = ArgumentList([
+2 -2
View File
@@ -85,7 +85,7 @@ public struct Return6: P4FFI {
let externally = Return5()
let program = try! #UseOkResult(
Program.Compile(
SpecialCompilers.ProgramCompiler.Compile(
simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: .none,
withFFIs: [externally]))
@@ -113,7 +113,7 @@ public struct Return6: P4FFI {
let externally = Return6()
let program = try! #UseOkResult(
Program.Compile(
SpecialCompilers.ProgramCompiler.Compile(
simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: .none,
withFFIs: [externally]))
+2 -2
View File
@@ -46,7 +46,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
var statements_executed: [String] = Array()
@@ -87,7 +87,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
var expressions_evaluated: [String] = Array()
+20 -7
View File
@@ -38,7 +38,7 @@ import P4Lang
#expect(
#RequireErrorResult(
Error(withMessage: "Could not compile the P4 program"),
Program.Compile(simple_parser_declaration)))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@Test func test_simple_compilation_with_statement() async throws {
@@ -51,7 +51,7 @@ import P4Lang
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
#expect(parser.states.count() == 1)
@@ -73,7 +73,7 @@ import P4Lang
};
"""
let compilation_error = try #UseErrorResult(Program.Compile(simple_parser_declaration))
let compilation_error = try #UseErrorResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
#expect(compilation_error.msg().contains("asde"))
#expect(compilation_error.msg().contains("asdf"))
@@ -110,7 +110,7 @@ import P4Lang
};
"""
let program = try! #UseOkResult(Program.Compile(simple))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let parser = try! #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let parameters = parser.parameters
@@ -130,7 +130,7 @@ import P4Lang
};
"""
let program = try! #UseOkResult(Program.Compile(simple))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let parser = try! #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let parameters = parser.parameters
@@ -153,7 +153,7 @@ import P4Lang
};
"""
let program = try! #UseOkResult(Program.Compile(simple))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))
let parser = try! #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let parameters = parser.parameters
@@ -180,5 +180,18 @@ import P4Lang
};
"""
#expect(#RequireOkResult(Program.Compile(simple)))
#expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)))
}
@Test func test_simple_compiler_with_instantiation() async throws {
let simple_instantiation_program = """
parser MainParser() {
state start {
transition accept;
}
};
MainParser() mp;
"""
#expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_instantiation_program)))
}
+7 -7
View File
@@ -37,7 +37,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -55,7 +55,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
// We should be in the accept state.
@@ -72,7 +72,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
#expect(
@@ -92,7 +92,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let args = ArgumentList([
@@ -114,7 +114,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let args = ArgumentList([
@@ -138,7 +138,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let args = ArgumentList([
@@ -162,7 +162,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let args = ArgumentList([Argument(P4Value(P4BooleanValue(withValue: true)), atIndex: 0)])
+5 -5
View File
@@ -42,7 +42,7 @@ import TreeSitterP4
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -68,7 +68,7 @@ import TreeSitterP4
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -96,7 +96,7 @@ import TreeSitterP4
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -120,7 +120,7 @@ import TreeSitterP4
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -151,7 +151,7 @@ import TreeSitterP4
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
+13 -13
View File
@@ -60,7 +60,7 @@ import TreeSitterP4
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -91,7 +91,7 @@ import TreeSitterP4
test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type)
let program = try #UseOkResult(
Program.Compile(
SpecialCompilers.ProgramCompiler.Compile(
simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
@@ -124,7 +124,7 @@ import TreeSitterP4
identifier: Identifier(name: "Testing"), withValue: struct_type)
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
@@ -165,7 +165,7 @@ import TreeSitterP4
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -205,7 +205,7 @@ import TreeSitterP4
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -245,7 +245,7 @@ import TreeSitterP4
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -298,7 +298,7 @@ import TreeSitterP4
]))
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -340,7 +340,7 @@ import TreeSitterP4
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -372,7 +372,7 @@ import TreeSitterP4
withMessage:
"{49, 13}: Failed to parse a statement element: {49, 8}: Cannot assign value of type Int (width: Infinite) to field yesno of type Boolean"
),
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
)
}
@@ -422,7 +422,7 @@ import TreeSitterP4
]))
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -477,7 +477,7 @@ import TreeSitterP4
]))
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(
program: program, withGlobalValues: test_values))
@@ -520,7 +520,7 @@ import TreeSitterP4
withMessage:
"{49, 20}: Failed to parse a statement element: {49, 11}: Cannot assign value of type Boolean to field count of type Int (width: Infinite)"
),
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
)
}
@@ -551,6 +551,6 @@ import TreeSitterP4
withMessage:
"{68, 21}: Could not parse transition select expression selector expression: Types of values used with binary expression are not the same"
),
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
)
}
@@ -34,7 +34,7 @@ import TreeSitterP4
let file = FilePath.init(stringLiteral: "simple.p4")
let source = try! (#UseOkResult(prep.preprocess(file)))
let program = try! #UseOkResult(Program.Compile(source.getSource()))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(source.getSource()))
#expect(#RequireOkResult((program.find_parser(withName: Identifier(name: "main_parser")))))
#expect(source.getLocations().getPath() == file)
}
@@ -45,7 +45,7 @@ import TreeSitterP4
let file = FilePath.init(stringLiteral: "simple.p4")
let source = try! (#UseOkResult(prep.preprocess(file)))
let program = try! #UseOkResult(Program.Compile(source.getSource()))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(source.getSource()))
#expect(#RequireOkResult((program.find_parser(withName: Identifier(name: "main_parser")))))
#expect(source.getLocations().getPath() == file)
}
@@ -58,7 +58,7 @@ import TreeSitterP4
#expect(#RequireOkResult(prep.preprocess(file)))
let source = try! (#UseOkResult(prep.preprocess(file)))
let program = try! #UseOkResult(Program.Compile(source.getSource()))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(source.getSource()))
#expect(#RequireOkResult((program.find_parser(withName: Identifier(name: "main_parser")))))
#expect(source.getLocations().getPath() == file)
}
@@ -71,7 +71,7 @@ import TreeSitterP4
#expect(#RequireOkResult(prep.preprocess(file)))
let source = try! (#UseOkResult(prep.preprocess(file)))
let program = try! #UseOkResult(Program.Compile(source.getSource()))
let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(source.getSource()))
#expect(#RequireOkResult((program.find_parser(withName: Identifier(name: "main_parser")))))
#expect(source.getLocations().getPath() == file)
}
+3 -3
View File
@@ -39,7 +39,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -61,7 +61,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser")))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -81,7 +81,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
#expect(
+2 -2
View File
@@ -38,7 +38,7 @@ import TreeSitterP4
#expect(
#RequireErrorResult(
Error(withMessage: "{0, 8}: Annotations in parser type are not yet handled."),
Program.Compile(simple_annotated_parser_declaration)))
SpecialCompilers.ProgramCompiler.Compile(simple_annotated_parser_declaration)))
}
@Test func test_unsupported_annotations_state() async throws {
@@ -52,5 +52,5 @@ import TreeSitterP4
#expect(
#RequireErrorResult(
Error(withMessage: "{26, 8}: Annotations in parser state are not yet handled."),
Program.Compile(simple_annotated_parser_declaration)))
SpecialCompilers.ProgramCompiler.Compile(simple_annotated_parser_declaration)))
}
+16 -16
View File
@@ -38,7 +38,7 @@ import TreeSitterP4
};
"""
let err = Program.Compile(simple_parser_declaration)
let err = SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)
guard case Result.Error(let e) = err else {
assert(false, "Expected an error, but had success")
}
@@ -66,7 +66,7 @@ import TreeSitterP4
withMessage:
"{112, 16}: Failed to parse a statement element: {112, 8}: Cannot assign value with type Boolean to identifier where_to with type String"
),
Program.Compile(simple_parser_declaration)))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@Test func test_invalid_type_in_assignment2() async throws {
@@ -87,7 +87,7 @@ import TreeSitterP4
withMessage:
"{114, 22}: Failed to parse a statement element: {114, 8}: Cannot assign value with type String to identifier where_to with type Boolean"
),
Program.Compile(simple_parser_declaration)))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@Test func test_invalid_type_in_declaration() async throws {
@@ -107,7 +107,7 @@ import TreeSitterP4
withMessage:
"{86, 27}: Failed to parse a statement element: Cannot initialize where_to (with type Boolean) from expression with type String"
),
Program.Compile(simple_parser_declaration)))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@Test func test_invalid_type_in_declaration2() async throws {
@@ -127,7 +127,7 @@ import TreeSitterP4
withMessage:
"{77, 29}: Failed to parse a statement element: Cannot initialize where_from (with type String) from expression with type Boolean"
),
Program.Compile(simple_parser_declaration)))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@Test func test_invalid_type_in_declaration3() async throws {
@@ -141,7 +141,7 @@ import TreeSitterP4
};
"""
let error = try! #UseErrorResult(Program.Compile(simple_parser_declaration))
let error = try! #UseErrorResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
#expect(
error.msg().contains(
@@ -160,7 +160,7 @@ import TreeSitterP4
};
"""
#expect(#RequireOkResult(Program.Compile(simple_parser_declaration)))
#expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@Test func test_expression_in_declaration_initializer_specific_width_int_type() async throws {
@@ -177,7 +177,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -202,7 +202,7 @@ import TreeSitterP4
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -225,7 +225,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -248,7 +248,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -271,7 +271,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -294,7 +294,7 @@ import TreeSitterP4
}
};
"""
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))
let runtime = try #UseOkResult(
P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
@@ -324,7 +324,7 @@ import TreeSitterP4
withMessage:
"{49, 35}: Failed to parse a statement element: Types of values used with binary expression are not the same"
),
Program.Compile(simple_parser_declaration)))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}
@@ -351,7 +351,7 @@ import TreeSitterP4
withMessage:
"{49, 22}: Failed to parse a statement element: Cannot initialize where_to (with type Boolean) from expression with type Int (width: Infinite)"
),
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)))
}
@Test func test_simple_compiler_parser_parameters_invalid_types() async throws {
@@ -369,5 +369,5 @@ import TreeSitterP4
withMessage:
"{85, 9}: Failed to parse a statement element: {85, 4}: Cannot assign value with type Int (width: Infinite) to identifier pmtr with type Boolean"
),
Program.Compile(simple_parser_declaration)))
SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)))
}