fn fullIfComponents(tree: Ast, info: full.If.Components) full.If tree: Astinfo: full.If.Components2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043fn fullIfComponents(tree: Ast, info: full.If.Components) full.If {
var result: full.If = .{
.ast = info,
.payload_token = null,
.error_token = null,
.else_token = undefined,
};
// if (cond_expr) |x|
// ^ ^
const payload_pipe = tree.lastToken(info.cond_expr) + 2;
if (tree.tokenTag(payload_pipe) == .pipe) {
result.payload_token = payload_pipe + 1;
}
if (info.else_expr != .none) {
// then_expr else |x|
// ^ ^
result.else_token = tree.lastToken(info.then_expr) + 1;
if (tree.tokenTag(result.else_token + 1) == .pipe) {
result.error_token = result.else_token + 2;
}
}
return result;
}