Source
pub fn extraData(tree: Ast, index: ExtraIndex, comptime T: type) T {
const fields = std.meta.fields(T);
var result: T = undefined;
inline for (fields, 0..) |field, i| {
@field(result, field.name) = switch (field.type) {
Node.Index,
Node.OptionalIndex,
OptionalTokenIndex,
ExtraIndex,
=> @enumFromInt(tree.extra_data[@intFromEnum(index) + i]),
TokenIndex => tree.extra_data[@intFromEnum(index) + i],
else => @compileError("unexpected field type: " ++ @typeName(field.type)),
};
}
return result;
}