authorgravatar for mdsteele@alum.mit.eduMatthew D. Steele <mdsteele@alum.mit.edu> 2018-07-30 22:27:07-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-30 22:27:07-04:00
log0db33e9c86ff43d3fe7f7f8fb2e29333c2fad2af
tree1c5e34b23fe050cc829081eb36253507054fa771
parent5d4a02c350a18a70cf1f92f6638b5d26689c16b4

Add "Comments" section to language reference (#1309)

The contents of this section come from the discussion on issue #1305.

1 files changed, 52 insertions(+), 0 deletions(-)

doc/langref.html.in+52
...@@ -134,6 +134,58 @@ pub fn main() void {...@@ -134,6 +134,58 @@ pub fn main() void {
134 </p>134 </p>
135 {#see_also|Values|@import|Errors|Root Source File#}135 {#see_also|Values|@import|Errors|Root Source File#}
136 {#header_close#}136 {#header_close#}
137 {#header_open|Comments#}
138 {#code_begin|test|comments#}
139const assert = @import("std").debug.assert;
140
141test "comments" {
142 // Comments in Zig start with "//" and end at the next LF byte (end of line).
143 // The below line is a comment, and won't be executed.
144
145 //assert(false);
146
147 const x = true; // another comment
148 assert(x);
149}
150 {#code_end#}
151 <p>
152 There are no multiline comments in Zig (e.g. like <code>/* */</code>
153 comments in C). This helps allow Zig to have the property that each line
154 of code can be tokenized out of context.
155 </p>
156 {#header_open|Doc comments#}
157 <p>
158 A doc comment is one that begins with exactly three slashes (i.e.
159 <code class="zig">///</code> but not <code class="zig">////</code>);
160 multiple doc comments in a row are merged together to form a multiline
161 doc comment. The doc comment documents whatever immediately follows it.
162 </p>
163 {#code_begin|syntax|doc_comments#}
164/// A structure for storing a timestamp, with nanosecond precision (this is a
165/// multiline doc comment).
166const Timestamp = struct {
167 /// The number of seconds since the epoch (this is also a doc comment).
168 seconds: i64, // signed so we can represent pre-1970 (not a doc comment)
169 /// The number of nanoseconds past the second (doc comment again).
170 nanos: u32,
171
172 /// Returns a `Timestamp` struct representing the Unix epoch; that is, the
173 /// moment of 1970 Jan 1 00:00:00 UTC (this is a doc comment too).
174 pub fn unixEpoch() Timestamp {
175 return Timestamp{
176 .seconds = 0,
177 .nanos = 0,
178 };
179 }
180};
181 {#code_end#}
182 <p>
183 Doc comments are only allowed in certain places; eventually, it will
184 become a compile error have a doc comment in an unexpected place, such as
185 in the middle of an expression, or just before a non-doc comment.
186 </p>
187 {#header_close#}
188 {#header_close#}
137 {#header_open|Values#}189 {#header_open|Values#}
138 {#code_begin|exe|values#}190 {#code_begin|exe|values#}
139const std = @import("std");191const std = @import("std");