Function parseStrLit [src]
Parses the given node as a string literal.
Prototype
pub fn parseStrLit( tree: Ast, node: Ast.Node.Index, writer: anytype, ) error{OutOfMemory}!std.zig.string_literal.Result
Parameters
tree: Ast
node: Ast.Node.Index
Possible Errors
Source
pub fn parseStrLit(
tree: Ast,
node: Ast.Node.Index,
writer: anytype,
) error{OutOfMemory}!std.zig.string_literal.Result {
switch (tree.nodeTag(node)) {
.string_literal => {
const token = tree.nodeMainToken(node);
const raw_string = tree.tokenSlice(token);
return std.zig.string_literal.parseWrite(writer, raw_string);
},
.multiline_string_literal => {
const first_tok, const last_tok = tree.nodeData(node).token_and_token;
// First line: do not append a newline.
{
const line_bytes = tree.tokenSlice(first_tok)[2..];
try writer.writeAll(line_bytes);
}
// Following lines: each line prepends a newline.
for (first_tok + 1..last_tok + 1) |tok_idx| {
const line_bytes = tree.tokenSlice(@intCast(tok_idx))[2..];
try writer.writeByte('\n');
try writer.writeAll(line_bytes);
}
return .success;
},
// Node must represent a string
else => unreachable,
}
}