mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
std.zig.Ast: store lbrace and rbrace token in data of .error_set_decl
This makes the `.data` field the better choice over the `.main_token` for this tag.
This commit is contained in:
parent
d84055f9c6
commit
4129f7ff5a
@ -444,9 +444,7 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void {
|
||||
},
|
||||
|
||||
.error_set_decl => {
|
||||
const error_token = ast.nodeMainToken(node);
|
||||
const lbrace = error_token + 1;
|
||||
const rbrace = ast.nodeData(node).token;
|
||||
const lbrace, const rbrace = ast.nodeData(node).token_and_token;
|
||||
|
||||
var i = lbrace + 1;
|
||||
while (i < rbrace) : (i += 1) {
|
||||
|
||||
@ -996,9 +996,8 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
|
||||
.unwrap_optional,
|
||||
.asm_simple,
|
||||
=> return tree.nodeData(n).node_and_token[1] + end_offset,
|
||||
.error_set_decl => return tree.nodeData(n).token + end_offset,
|
||||
.grouped_expression, .asm_input => return tree.nodeData(n).node_and_token[1] + end_offset,
|
||||
.multiline_string_literal => return tree.nodeData(n).token_and_token[1] + end_offset,
|
||||
.multiline_string_literal, .error_set_decl => return tree.nodeData(n).token_and_token[1] + end_offset,
|
||||
.asm_output => return tree.nodeData(n).opt_node_and_token[1] + end_offset,
|
||||
.error_value => return tree.nodeMainToken(n) + 2 + end_offset,
|
||||
|
||||
@ -3758,7 +3757,9 @@ pub const Node = struct {
|
||||
builtin_call_comma,
|
||||
/// `error{a, b}`.
|
||||
///
|
||||
/// The `data` field is a `.token` to the '}'.
|
||||
/// The `data` field is a `.token_and_token`:
|
||||
/// 1. a `TokenIndex` to the `{` token.
|
||||
/// 2. a `TokenIndex` to the `}` token.
|
||||
///
|
||||
/// The `main_token` field is the `error`.
|
||||
error_set_decl,
|
||||
|
||||
@ -5974,9 +5974,9 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi
|
||||
var idents: std.AutoHashMapUnmanaged(Zir.NullTerminatedString, Ast.TokenIndex) = .empty;
|
||||
defer idents.deinit(gpa);
|
||||
|
||||
const error_token = tree.nodeMainToken(node);
|
||||
var tok_i = error_token + 2;
|
||||
while (true) : (tok_i += 1) {
|
||||
const lbrace, const rbrace = tree.nodeData(node).token_and_token;
|
||||
for (lbrace + 1..rbrace) |i| {
|
||||
const tok_i: Ast.TokenIndex = @intCast(i);
|
||||
switch (tree.tokenTag(tok_i)) {
|
||||
.doc_comment, .comma => {},
|
||||
.identifier => {
|
||||
@ -6003,7 +6003,6 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi
|
||||
try astgen.extra.append(gpa, @intFromEnum(str_index));
|
||||
fields_len += 1;
|
||||
},
|
||||
.r_brace => break,
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
@ -2763,7 +2763,12 @@ fn parsePrimaryTypeExpr(p: *Parse) !?Node.Index {
|
||||
return try p.addNode(.{
|
||||
.tag = .error_set_decl,
|
||||
.main_token = error_token,
|
||||
.data = .{ .token = p.tok_i - 1 }, // rbrace
|
||||
.data = .{
|
||||
.token_and_token = .{
|
||||
error_token + 1, // lbrace
|
||||
p.tok_i - 1, // rbrace
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
else => {
|
||||
|
||||
@ -739,8 +739,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
|
||||
|
||||
.error_set_decl => {
|
||||
const error_token = tree.nodeMainToken(node);
|
||||
const lbrace = error_token + 1;
|
||||
const rbrace = tree.nodeData(node).token;
|
||||
const lbrace, const rbrace = tree.nodeData(node).token_and_token;
|
||||
|
||||
try renderToken(r, error_token, .none);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user