implements PLN-0094
This commit is contained in:
+6
@@ -78,6 +78,7 @@ public final class PbsAst {
|
||||
}
|
||||
|
||||
public sealed interface AttributeValue permits AttributeStringValue,
|
||||
AttributeDocTextBlockValue,
|
||||
AttributeIntValue,
|
||||
AttributeBoolValue,
|
||||
AttributeErrorValue {
|
||||
@@ -89,6 +90,11 @@ public final class PbsAst {
|
||||
Span span) implements AttributeValue {
|
||||
}
|
||||
|
||||
public record AttributeDocTextBlockValue(
|
||||
String value,
|
||||
Span span) implements AttributeValue {
|
||||
}
|
||||
|
||||
public record AttributeIntValue(
|
||||
long value,
|
||||
Span span) implements AttributeValue {
|
||||
|
||||
+4
@@ -84,6 +84,10 @@ final class PbsAttributeParser {
|
||||
final var token = cursor.previous();
|
||||
return new PbsAst.AttributeStringValue(token.lexeme(), context.span(token.start(), token.end()));
|
||||
}
|
||||
if (cursor.match(PbsTokenKind.DOC_TEXT_BLOCK)) {
|
||||
final var token = cursor.previous();
|
||||
return new PbsAst.AttributeDocTextBlockValue(token.lexeme(), context.span(token.start(), token.end()));
|
||||
}
|
||||
if (cursor.match(PbsTokenKind.INT_LITERAL)) {
|
||||
final var token = cursor.previous();
|
||||
final var parsedLong = parseLongOrNull(token.lexeme());
|
||||
|
||||
+38
@@ -339,6 +339,44 @@ class PbsParserTest {
|
||||
assertEquals(1, constDecl.attributes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldParseDocumentationTextBlockAttributeValuesInInterfaceModuleMode() {
|
||||
final var source = """
|
||||
[Doc(markdown = \"""
|
||||
Represents a packed color.
|
||||
\""")]
|
||||
[BuiltinType(name = "color", version = 1)]
|
||||
declare builtin type Color(
|
||||
pub raw: int
|
||||
) {
|
||||
[Doc(markdown = \"""
|
||||
Packs this color into an integer.
|
||||
\""")]
|
||||
[IntrinsicCall(name = "color.pack", version = 1)]
|
||||
fn pack() -> int;
|
||||
}
|
||||
""";
|
||||
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.ParseMode.INTERFACE_MODULE);
|
||||
|
||||
assertTrue(diagnostics.isEmpty(), "Parser should accept documentation text block attribute values");
|
||||
final var builtinType = assertInstanceOf(PbsAst.BuiltinTypeDecl.class, ast.topDecls().getFirst());
|
||||
final var typeDoc = builtinType.attributes().getFirst().arguments().getFirst().value();
|
||||
assertInstanceOf(PbsAst.AttributeDocTextBlockValue.class, typeDoc);
|
||||
assertTrue(((PbsAst.AttributeDocTextBlockValue) typeDoc).value().contains("Represents a packed color."));
|
||||
|
||||
final var signatureDoc = builtinType.signatures().getFirst().attributes().getFirst().arguments().getFirst().value();
|
||||
assertInstanceOf(PbsAst.AttributeDocTextBlockValue.class, signatureDoc);
|
||||
assertTrue(((PbsAst.AttributeDocTextBlockValue) signatureDoc).value().startsWith("\"\"\""));
|
||||
assertTrue(((PbsAst.AttributeDocTextBlockValue) signatureDoc).value().endsWith("\"\"\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRecoverFromMalformedReservedDeclarationsInInterfaceModuleMode() {
|
||||
final var source = """
|
||||
|
||||
Reference in New Issue
Block a user