compiler: Refactor Compiler To Remove Ambiguities
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:
@@ -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))
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user