Merge pull request #18644 from ziglang/langref

This commit is contained in:
Andrew Kelley 2024-01-22 02:26:46 -08:00 committed by GitHub
commit b0c8a3f316
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 245 additions and 396 deletions

File diff suppressed because it is too large Load Diff

View File

@ -102,14 +102,34 @@ pub const ReduceOp = enum {
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const AtomicRmwOp = enum {
/// Exchange - store the operand unmodified.
/// Supports enums, integers, and floats.
Xchg,
/// Add operand to existing value.
/// Supports integers and floats.
/// For integers, two's complement wraparound applies.
Add,
/// Subtract operand from existing value.
/// Supports integers and floats.
/// For integers, two's complement wraparound applies.
Sub,
/// Perform bitwise AND on existing value with operand.
/// Supports integers.
And,
/// Perform bitwise NAND on existing value with operand.
/// Supports integers.
Nand,
/// Perform bitwise OR on existing value with operand.
/// Supports integers.
Or,
/// Perform bitwise XOR on existing value with operand.
/// Supports integers.
Xor,
/// Store operand if it is larger than the existing value.
/// Supports integers and floats.
Max,
/// Store operand if it is smaller than the existing value.
/// Supports integers and floats.
Min,
};

View File

@ -40,9 +40,9 @@ pub const FormatOptions = struct {
/// - when using a field name, you are required to enclose the field name (an identifier) in square
/// brackets, e.g. {[score]...} as opposed to the numeric index form which can be written e.g. {2...}
/// - *specifier* is a type-dependent formatting option that determines how a type should formatted (see below)
/// - *fill* is a single character which is used to pad the formatted text
/// - *alignment* is one of the three characters `<`, `^`, or `>` to make the text left-, center-, or right-aligned, respectively
/// - *width* is the total width of the field in characters
/// - *fill* is a single unicode codepoint which is used to pad the formatted text
/// - *alignment* is one of the three bytes '<', '^', or '>' to make the text left-, center-, or right-aligned, respectively
/// - *width* is the total width of the field in unicode codepoints
/// - *precision* specifies how many decimals a formatted number should have
///
/// Note that most of the parameters are optional and may be omitted. Also you can leave out separators like `:` and `.` when

View File

@ -947,19 +947,8 @@ fn isType(name: []const u8) bool {
return false;
}
const start_line = "<span class=\"line\">";
const end_line = "</span>";
fn writeEscapedLines(out: anytype, text: []const u8) !void {
for (text) |char| {
if (char == '\n') {
try out.writeAll(end_line);
try out.writeAll("\n");
try out.writeAll(start_line);
} else {
try writeEscaped(out, &[_]u8{char});
}
}
return writeEscaped(out, text);
}
fn tokenizeAndPrintRaw(
@ -972,7 +961,7 @@ fn tokenizeAndPrintRaw(
const src_non_terminated = mem.trim(u8, raw_src, " \r\n");
const src = try allocator.dupeZ(u8, src_non_terminated);
try out.writeAll("<code>" ++ start_line);
try out.writeAll("<code>");
var tokenizer = std.zig.Tokenizer.init(src);
var index: usize = 0;
var next_tok_is_fn = false;
@ -1062,6 +1051,7 @@ fn tokenizeAndPrintRaw(
},
.string_literal,
.multiline_string_literal_line,
.char_literal,
=> {
try out.writeAll("<span class=\"tok-str\">");
@ -1069,18 +1059,6 @@ fn tokenizeAndPrintRaw(
try out.writeAll("</span>");
},
.multiline_string_literal_line => {
if (src[token.loc.end - 1] == '\n') {
try out.writeAll("<span class=\"tok-str\">");
try writeEscaped(out, src[token.loc.start .. token.loc.end - 1]);
try out.writeAll("</span>" ++ end_line ++ "\n" ++ start_line);
} else {
try out.writeAll("<span class=\"tok-str\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try out.writeAll("</span>");
}
},
.builtin => {
try out.writeAll("<span class=\"tok-builtin\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
@ -1211,7 +1189,7 @@ fn tokenizeAndPrintRaw(
}
index = token.loc.end;
}
try out.writeAll(end_line ++ "</code>");
try out.writeAll("</code>");
}
fn tokenizeAndPrint(
@ -1234,9 +1212,9 @@ fn printSourceBlock(allocator: Allocator, docgen_tokenizer: *Tokenizer, out: any
const raw_source = docgen_tokenizer.buffer[syntax_block.source_token.start..syntax_block.source_token.end];
const trimmed_raw_source = mem.trim(u8, raw_source, " \r\n");
try out.writeAll("<code>" ++ start_line);
try out.writeAll("<code>");
try writeEscapedLines(out, trimmed_raw_source);
try out.writeAll(end_line ++ "</code>");
try out.writeAll("</code>");
},
}
try out.writeAll("</pre></figure>");