renderDocComments
end_token is the token one past the last doc comment token. This function searches backwards from there.
Function parameters
Parameters
- r:*Render
- end_token:Ast.TokenIndex
Type definitions in this namespace
Types
Functions in this namespace
Functions
Error sets in this namespace
Error Sets
Source
Implementation
fn renderDocComments(r: *Render, end_token: Ast.TokenIndex) Error!void {
const tree = r.tree;
// Search backwards for the first doc comment.
if (end_token == 0) return;
var tok = end_token - 1;
while (tree.tokenTag(tok) == .doc_comment) {
if (tok == 0) break;
tok -= 1;
} else {
tok += 1;
}
const first_tok = tok;
if (first_tok == end_token) return;
if (first_tok != 0) {
const prev_token_tag = tree.tokenTag(first_tok - 1);
// Prevent accidental use of `renderDocComments` for a function argument doc comment
assert(prev_token_tag != .l_paren);
if (prev_token_tag != .l_brace) {
try renderExtraNewlineToken(r, first_tok);
}
}
while (tree.tokenTag(tok) == .doc_comment) : (tok += 1) {
try renderToken(r, tok, .newline);
}
}