Debian Codegraph @

test/syntax/source/code/d

raw
1 #!/usr/bin/rdmd
2 // Computes average line length for standard input.
3 import std.stdio;
4
5 /+
6 this is a /+ nesting +/ comment
7 +/
8
9 enum COMPILED_ON = __TIMESTAMP__; // special token
10
11 enum character = '©';
12 enum copy_valid = '©';
13 enum backslash_escaped = '\\';
14
15 // string literals
16 enum str = `hello "world"!`;
17 enum multiline = r"lorem
18 ipsum
19 dolor"; // wysiwyg string, no escapes here allowed
20 enum multiline2 = "sit
21 amet
22 \"adipiscing\"
23 elit.";
24 enum hex = x"66 6f 6f"; // same as "foo"
25
26 #line 5
27
28 // float literals
29 enum f = [3.14f, .1, 1., 1e100, 0xc0de.01p+100];
30
31 static if (something == true) {
32 import std.algorithm;
33 }
34
35 void main() pure nothrow @safe {
36 ulong lines = 0;
37 double sumLength = 0;
38 foreach (line; stdin.byLine()) {
39 ++lines;
40 sumLength += line.length;
41 }
42 writeln("Average line length: ",
43 lines ? sumLength / lines : 0);
44 }