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:
@@ -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)))
|
||||
}
|
||||
Reference in New Issue
Block a user