compiler: Add Ability to Annotate Preprocessed Source

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-05-11 07:24:03 -04:00
parent a0c6b7730c
commit f0f7a660a6
7 changed files with 108 additions and 4 deletions
@@ -156,6 +156,35 @@ import TreeSitterP4
== SourceLocation(48..<166))
}
@Test func test_preprocessor_nested_includes_annotated_source() async throws {
let sm = SourceManager(["./TestData/Sources/"])
let prep = SourceCodePreprocessor(sm)
let file = FilePath.init(stringLiteral: "./TestData/Sources/annotate.p4")
let expected = """
<struct Testing {
< bool yesno;
int count;>
};
<parser main_parser() {
< state start {
Testing ts;
ts.yesno = true;
ts.count = 5;
transition select (ts.count == 5) {
true: accept;
false: reject;
};
}
>
}>>
"""
#expect(#RequireOkResult(prep.preprocess(file)))
let source = try! (#UseOkResult(prep.preprocess(file)))
#expect(source.getSource(annotated: true) == expected)
}
@Test func test_source_location_contains() async throws {
let outer = SourceLocation(0..<500)