anon struct, union...
This commit is contained in:
@@ -266,6 +266,18 @@ pub const Parser = struct {
|
||||
|
||||
return try self.createNode(start, .{ .type_expr = .{ .name = name } });
|
||||
}
|
||||
// Inline struct type in type position: struct { ... }
|
||||
if (self.current.tag == .kw_struct) {
|
||||
return try self.parseStructDecl("__anon", start);
|
||||
}
|
||||
// Inline union type in type position: union { ... }
|
||||
if (self.current.tag == .kw_union) {
|
||||
return try self.parseUnionDecl("__anon", start);
|
||||
}
|
||||
// Inline enum type in type position: enum { ... }
|
||||
if (self.current.tag == .kw_enum) {
|
||||
return try self.parseEnumDecl("__anon", start);
|
||||
}
|
||||
return self.fail("expected type name");
|
||||
}
|
||||
|
||||
@@ -843,6 +855,22 @@ pub const Parser = struct {
|
||||
// Expression type: Vec(3, f32).{ ... }
|
||||
expr = try self.parseStructLiteral(null, expr, expr.span.start);
|
||||
}
|
||||
} else if (self.current.tag == .l_bracket) {
|
||||
// Typed array/vector literal: Type.[elem, ...]
|
||||
self.advance(); // skip '['
|
||||
var elements = std.ArrayList(*Node).empty;
|
||||
while (self.current.tag != .r_bracket and self.current.tag != .eof) {
|
||||
if (elements.items.len > 0) {
|
||||
try self.expect(.comma);
|
||||
}
|
||||
const elem = try self.parseExpr();
|
||||
try elements.append(self.allocator, elem);
|
||||
}
|
||||
try self.expect(.r_bracket);
|
||||
expr = try self.createNode(expr.span.start, .{ .array_literal = .{
|
||||
.elements = try elements.toOwnedSlice(self.allocator),
|
||||
.type_expr = expr,
|
||||
} });
|
||||
} else {
|
||||
// Field access
|
||||
if (self.current.tag != .identifier) {
|
||||
|
||||
Reference in New Issue
Block a user