PBS highlight colors

This commit is contained in:
2026-04-03 11:19:45 +01:00
parent 5bbd753ba0
commit f368ed94d2
12 changed files with 129 additions and 37 deletions
@@ -574,7 +574,7 @@ final class PbsDeclarationParser {
}
private PbsToken consumeCallableName() {
if (cursor.check(PbsTokenKind.IDENTIFIER) || cursor.check(PbsTokenKind.ERROR)) {
if (cursor.check(PbsTokenKind.IDENTIFIER)) {
return cursor.advance();
}
final var token = cursor.peek();
@@ -39,7 +39,7 @@ final class PbsExprParserContext {
}
PbsToken consumeMemberName(final String message) {
if (cursor.check(PbsTokenKind.IDENTIFIER) || cursor.check(PbsTokenKind.ERROR)) {
if (cursor.check(PbsTokenKind.IDENTIFIER)) {
return cursor.advance();
}
final var token = cursor.peek();
@@ -30,7 +30,7 @@ declare service Log
LowLog.write(3, msg);
}
fn error(msg: str) -> void
fn failure(msg: str) -> void
{
LowLog.write(4, msg);
}
@@ -55,7 +55,7 @@ declare service Log
LowLog.write_tag(3, tag, msg);
}
fn error(tag: int, msg: str) -> void
fn failure(tag: int, msg: str) -> void
{
LowLog.write_tag(4, tag, msg);
}
@@ -173,7 +173,7 @@ class PbsParserTest {
}
@Test
void shouldParseServiceAndMemberNamesUsingErrorKeyword() {
void shouldRejectErrorKeywordAsCallableAndMemberName() {
final var source = """
declare service Log {
fn error(msg: str) -> void { return; }
@@ -181,20 +181,17 @@ class PbsParserTest {
}
fn run() -> void {
Log.error("oops");
Log.error(7, "oops");
Log.failure("oops");
Log.failure(7, "oops");
return;
}
""";
final var diagnostics = DiagnosticSink.empty();
final var fileId = new FileId(0);
final PbsAst.File ast = PbsParser.parse(PbsLexer.lex(source, fileId, diagnostics), fileId, diagnostics);
PbsParser.parse(PbsLexer.lex(source, fileId, diagnostics), fileId, diagnostics);
assertTrue(diagnostics.isEmpty(), "Parser should accept 'error' as callable/member name");
final var service = assertInstanceOf(PbsAst.ServiceDecl.class, ast.topDecls().getFirst());
assertEquals(2, service.methods().size());
assertEquals("error", service.methods().getFirst().name());
assertFalse(diagnostics.isEmpty(), "Parser should reject reserved keyword 'error' as callable/member name");
}
@Test