parser: port test "top-level bare asterisk+asterisk+identifier"

Implement ** (double pointer) type parsing in parseTypeExpr.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-02-10 14:37:40 +00:00
parent fcfa3f3b4a
commit cd5ebdb904
2 changed files with 26 additions and 4 deletions

View File

@@ -839,10 +839,25 @@ static AstNodeIndex parseTypeExpr(Parser* p) {
.data = { .lhs = 0, .rhs = child_type },
});
}
case TOKEN_ASTERISK_ASTERISK:
fprintf(stderr, "parseTypeExpr not supported for %s\n",
tokenizerGetTagString(tok));
exit(1);
case TOKEN_ASTERISK_ASTERISK: {
// ** is two nested pointer types sharing the same token
const AstTokenIndex asterisk = nextToken(p);
// Inner pointer: parse modifiers and child type
const AstNodeIndex inner_child = parseTypeExpr(p);
const AstNodeIndex inner = addNode(&p->nodes,
(AstNodeItem) {
.tag = AST_NODE_PTR_TYPE_ALIGNED,
.main_token = asterisk,
.data = { .lhs = 0, .rhs = inner_child },
});
// Outer pointer wraps the inner
return addNode(&p->nodes,
(AstNodeItem) {
.tag = AST_NODE_PTR_TYPE_ALIGNED,
.main_token = asterisk,
.data = { .lhs = 0, .rhs = inner },
});
}
case TOKEN_L_BRACKET: {
const AstTokenIndex lbracket = nextToken(p);
if (p->token_tags[p->tok_i] == TOKEN_ASTERISK) {

View File

@@ -1812,3 +1812,10 @@ test "zig fmt: top-level bare asterisk+identifier" {
\\
);
}
test "zig fmt: top-level bare asterisk+asterisk+identifier" {
try testCanonical(
\\**x
\\
);
}