renderSpace
Function parameters
Parameters
Type definitions in this namespace
Types
Functions in this namespace
Functions
Error sets in this namespace
Error Sets
Source
Implementation
fn renderSpace(r: *Render, token_index: Ast.TokenIndex, lexeme_len: usize, space: Space) Error!void {
const tree = r.tree;
const ais = r.ais;
const next_token_tag = tree.tokenTag(token_index + 1);
if (space == .skip) return;
if (space == .comma and next_token_tag != .comma) {
try ais.writeByte(',');
}
if (space == .semicolon or space == .comma) ais.enableSpaceMode(space);
defer ais.disableSpaceMode();
const comment = try renderComments(
r,
tree.tokenStart(token_index) + lexeme_len,
tree.tokenStart(token_index + 1),
);
switch (space) {
.none => {},
.space => if (!comment) try ais.writeByte(' '),
.newline => if (!comment) try ais.insertNewline(),
.comma => if (next_token_tag == .comma) {
try renderToken(r, token_index + 1, .newline);
} else if (!comment) {
try ais.insertNewline();
},
.comma_space => if (next_token_tag == .comma) {
try renderToken(r, token_index + 1, .space);
} else if (!comment) {
try ais.writeByte(' ');
},
.semicolon => if (next_token_tag == .semicolon) {
try renderToken(r, token_index + 1, .newline);
} else if (!comment) {
try ais.insertNewline();
},
.skip => unreachable,
}
}