authorgravatar for codroid@gmail.comStevie Hryciw <codroid@gmail.com> 2022-11-09 00:29:50-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-09 14:00:35-07:00
log7748d2bb44dabbf60bfd7f65b1c5e2ebf0b49207
tree05ff9784f8843f54b6598f956e23c0bf41b9f2ca
parent56195aa73cc903d3b14e05431deb5ef33cc3dec7

langref: add appendix and explain 'container' terminology


1 files changed, 21 insertions(+), 7 deletions(-)

doc/langref.html.in+21-7
......@@ -536,7 +536,7 @@ const Timestamp = struct {
536536 {#header_close#}
537537 {#header_open|Top-Level Doc Comments#}
538538 <p>User documentation that doesn't belong to whatever
539 immediately follows it, like container-level documentation, goes
539 immediately follows it, like {#link|container|Containers#}-level documentation, goes
540540 in top-level doc comments. A top-level doc comment is one that
541541 begins with two slashes and an exclamation point:
542542 {#syntax#}//!{#endsyntax#}.</p>
......@@ -1080,7 +1080,7 @@ fn addOne(number: i32) i32 {
10801080 <p>
10811081 When the <kbd>zig test</kbd> tool is building a test runner, only resolved {#syntax#}test{#endsyntax#}
10821082 declarations are included in the build. Initially, only the given Zig source file's top-level
1083 declarations are resolved. Unless nested containers are referenced from a top-level test declaration,
1083 declarations are resolved. Unless nested {#link|containers|Containers#} are referenced from a top-level test declaration,
10841084 nested container tests will not be resolved.
10851085 </p>
10861086 <p>
......@@ -1328,7 +1328,7 @@ const color: Color = .@"really red";
13281328
13291329 {#header_open|Container Level Variables#}
13301330 <p>
1331 Container level variables have static lifetime and are order-independent and lazily analyzed.
1331 {#link|Container|Containers#} level variables have static lifetime and are order-independent and lazily analyzed.
13321332 The initialization value of container level variables is implicitly
13331333 {#link|comptime#}. If a container level variable is {#syntax#}const{#endsyntax#} then its value is
13341334 {#syntax#}comptime{#endsyntax#}-known, otherwise it is runtime-known.
......@@ -1350,7 +1350,7 @@ const std = @import("std");
13501350const expect = std.testing.expect;
13511351 {#code_end#}
13521352 <p>
1353 Container level variables may be declared inside a {#link|struct#}, {#link|union#}, or {#link|enum#}:
1353 Container level variables may be declared inside a {#link|struct#}, {#link|union#}, {#link|enum#}, or {#link|opaque#}:
13541354 </p>
13551355 {#code_begin|test|namespaced_container_level_variable#}
13561356const std = @import("std");
......@@ -7066,7 +7066,7 @@ test "fibonacci" {
70667066 {#code_end#}
70677067
70687068 <p>
7069 At container level (outside of any function), all expressions are implicitly
7069 At {#link|container|Containers#} level (outside of any function), all expressions are implicitly
70707070 {#syntax#}comptime{#endsyntax#} expressions. This means that we can use functions to
70717071 initialize complex static data. For example:
70727072 </p>
......@@ -7538,7 +7538,7 @@ volatile (
75387538
75397539 {#header_open|Global Assembly#}
75407540 <p>
7541 When an assembly expression occurs in a container level {#link|comptime#} block, this is
7541 When an assembly expression occurs in a {#link|container|Containers#} level {#link|comptime#} block, this is
75427542 <strong>global assembly</strong>.
75437543 </p>
75447544 <p>
......@@ -8843,7 +8843,7 @@ fn func() void {
88438843 {#header_open|@hasDecl#}
88448844 <pre>{#syntax#}@hasDecl(comptime Container: type, comptime name: []const u8) bool{#endsyntax#}</pre>
88458845 <p>
8846 Returns whether or not a {#link|struct#}, {#link|enum#}, or {#link|union#} has a declaration
8846 Returns whether or not a {#link|container|Containers#} has a declaration
88478847 matching {#syntax#}name{#endsyntax#}.
88488848 </p>
88498849 {#code_begin|test|hasDecl#}
......@@ -12436,6 +12436,19 @@ fn readU32Be() u32 {}
1243612436 </div>
1243712437 {#header_close#}
1243812438
12439 {#header_open|Appendix#}
12440 {#header_open|Containers#}
12441 <p>
12442 A <em>container</em> in Zig is any syntactical construct that acts as a namespace to hold {#link|variable|Container Level Variables#} and {#link|function|Functions#} declarations.
12443 Containers are also type definitions which can be instantiated.
12444 {#link|Structs|struct#}, {#link|enums|enum#}, {#link|unions|union#}, {#link|opaques|opaque#}, and even Zig source files themselves are containers.
12445 </p>
12446 <p>
12447 Although containers (except Zig source files) use curly braces to surround their definition, they should not be confused with {#link|blocks|Blocks#} or functions.
12448 Containers do not contain statements.
12449 </p>
12450 {#header_close#}
12451
1243912452 {#header_open|Grammar#}
1244012453 {#syntax_block|peg|grammar.y#}Root <- skip container_doc_comment? ContainerMembers eof
1244112454
......@@ -13001,6 +13014,7 @@ keyword <- KEYWORD_align / KEYWORD_allowzero / KEYWORD_and / KEYWORD_anyframe
1300113014 <li>Together we serve the users.</li>
1300213015 </ul>
1300313016 {#header_close#}
13017 {#header_close#}
1300413018 </main></div>
1300513019 </div>
1300613020 </body>