Mercurial > projects > dil
annotate trunk/src/cmd/Statistics.d @ 391:33b566df6af4
Migrated project to Tango.
Decremented the numbers of the format placeholders in the localized messages
by one.
Replaced all instances of writef/ln with Stdout.
Added module common.d with string aliases and a global Layout!(char) instance.
Replaced %s format specifiers with index placeholders in html/xml_tags.
Changed member Information.arguments to string message.
Copied std.metastring, std.uni and std.utf from Phobos.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 15 Sep 2007 17:12:26 +0200 |
parents | 1059295c2727 |
children | fcdf7ac5ad27 |
rev | line source |
---|---|
363 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL3 | |
4 +/ | |
5 module cmd.Statistics; | |
6 import dil.Token; | |
7 import dil.File; | |
8 import dil.Lexer; | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
9 import common; |
363 | 10 |
11 struct Statistics | |
12 { | |
13 uint whitespaceCount; | |
14 uint wsTokenCount; | |
15 uint keywordCount; | |
16 uint identCount; | |
17 uint numberCount; | |
18 uint commentCount; | |
19 } | |
20 | |
364 | 21 void execute(string fileName) |
363 | 22 { |
23 auto sourceText = loadFile(fileName); | |
24 auto lx = new Lexer(sourceText, fileName); | |
25 | |
26 auto token = lx.getTokens(); | |
27 | |
28 Statistics stats; | |
29 // Traverse linked list. | |
30 while (token.type != TOK.EOF) | |
31 { | |
32 token = token.next; | |
33 | |
34 // Count whitespace characters | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
35 if (token.ws) |
363 | 36 { |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
37 // TODO: naive method doesn't account for \r\n, LS and PS. |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
38 stats.whitespaceCount += token.start - token.ws; |
363 | 39 } |
40 | |
41 switch (token.type) | |
42 { | |
43 case TOK.Identifier: | |
44 stats.identCount++; | |
45 break; | |
46 case TOK.Comment: | |
47 stats.commentCount++; | |
48 break; | |
49 case TOK.Int32, TOK.Int64, TOK.Uint32, TOK.Uint64, | |
50 TOK.Float32, TOK.Float64, TOK.Float80, | |
51 TOK.Imaginary32, TOK.Imaginary64, TOK.Imaginary80: | |
52 stats.numberCount++; | |
53 break; | |
54 default: | |
55 if (token.isKeyword) | |
56 stats.keywordCount++; | |
57 } | |
58 | |
59 if (token.isWhitespace) | |
60 stats.wsTokenCount++; | |
61 } | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
62 Stdout.formatln( |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
63 "Whitespace character count: {0}\n" |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
64 "Whitespace token count: {1}\n" |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
65 "Keyword count: {2}\n" |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
66 "Identifier count: {3}\n" |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
67 "Number count: {4}\n" |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
68 "Comment count: {5}\n" |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
69 "Lines of code: {6}", |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
70 stats.whitespaceCount, |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
71 stats.wsTokenCount, |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
72 stats.keywordCount, |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
73 stats.identCount, |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
74 stats.numberCount, |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
75 stats.commentCount, |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
364
diff
changeset
|
76 lx.loc); |
363 | 77 } |