Mercurial > projects > dil
annotate trunk/src/main.d @ 513:6160ab7b1816
Refactored code related to settings.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Fri, 14 Dec 2007 19:08:21 +0100 |
parents | bccca748d745 |
children | f203c5248d0b |
rev | line source |
---|---|
0 | 1 /++ |
2 Author: Aziz Köksal | |
249 | 3 License: GPL3 |
0 | 4 +/ |
347 | 5 module main; |
513
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
6 |
327 | 7 import dil.Parser; |
8 import dil.Lexer; | |
9 import dil.Token; | |
10 import dil.Messages; | |
11 import dil.Settings; | |
513
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
12 import dil.SettingsLoader; |
464
325714d8aa6c
Added new module with compiler constants to resolve import cycle.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
445
diff
changeset
|
13 import dil.CompilerInfo; |
327 | 14 import dil.Declarations, dil.Expressions, dil.SyntaxTree; |
351 | 15 import dil.File; |
363 | 16 import cmd.Generate; |
17 import cmd.Statistics; | |
364 | 18 import cmd.ImportGraph; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
19 import common; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
20 |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
21 import Integer = tango.text.convert.Integer; |
513
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
22 import tango.io.File; |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
23 import tango.text.Util; |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
24 import tango.util.time.StopWatch; |
306 | 25 |
0 | 26 void main(char[][] args) |
27 { | |
513
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
28 dil.SettingsLoader.loadSettings(); |
309 | 29 |
306 | 30 if (args.length <= 1) |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
31 return Stdout(helpMain()).newline; |
306 | 32 |
33 string command = args[1]; | |
34 switch (command) | |
35 { | |
329 | 36 case "gen", "generate": |
322
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
37 char[] fileName; |
329 | 38 DocOption options = DocOption.Tokens; |
322
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
39 foreach (arg; args[2..$]) |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
40 { |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
41 switch (arg) |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
42 { |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
43 case "--syntax": |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
44 options |= DocOption.Syntax; break; |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
45 case "--xml": |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
46 options |= DocOption.XML; break; |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
47 case "--html": |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
48 options |= DocOption.HTML; break; |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
49 default: |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
50 fileName = arg; |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
51 } |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
52 } |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
53 if (!(options & (DocOption.XML | DocOption.HTML))) |
ed4ef0173793
- Moved out large TOK switch case to function printToken().
aziz
parents:
315
diff
changeset
|
54 options |= DocOption.XML; // Default to XML. |
364 | 55 cmd.Generate.execute(fileName, options); |
306 | 56 break; |
366 | 57 case "importgraph", "igraph": |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
58 string filePath; |
366 | 59 string[] includePaths; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
60 string[] regexps; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
61 uint levels; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
62 IGraphOption options; |
366 | 63 foreach (arg; args[2..$]) |
64 { | |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
65 if (strbeg(arg, "-I")) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
66 includePaths ~= arg[2..$]; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
67 else if(strbeg(arg, "-r")) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
68 regexps ~= arg[2..$]; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
69 else if(strbeg(arg, "-l")) |
392
bb935c6f9b7a
Applied fixes and improvements to the Lexer class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
70 levels = Integer.toInt(arg[2..$]); |
366 | 71 else |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
72 switch (arg) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
73 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
74 case "--dot": |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
75 options |= IGraphOption.PrintDot; break; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
76 case "--paths": |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
77 options |= IGraphOption.PrintPaths; break; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
78 case "--list": |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
79 options |= IGraphOption.PrintList; break; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
80 case "-i": |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
81 options |= IGraphOption.IncludeUnlocatableModules; break; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
82 case "-hle": |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
83 options |= IGraphOption.HighlightCyclicEdges; break; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
84 case "-hlv": |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
85 options |= IGraphOption.HighlightCyclicVertices; break; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
86 case "-gbp": |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
87 options |= IGraphOption.GroupByPackageNames; break; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
88 case "-gbf": |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
89 options |= IGraphOption.GroupByFullPackageName; break; |
427
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
90 case "-m": |
e2bbc6406a14
Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
91 options |= IGraphOption.MarkCyclicModules; break; |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
92 default: |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
93 filePath = arg; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
94 } |
366 | 95 } |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
96 cmd.ImportGraph.execute(filePath, includePaths, regexps, levels, options); |
366 | 97 break; |
363 | 98 case "stats", "statistics": |
401
fcdf7ac5ad27
Improved statistics generation.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
392
diff
changeset
|
99 cmd.Statistics.execute(args[2..$]); |
363 | 100 break; |
487
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
101 case "tok", "tokenize": |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
102 char[] filePath; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
103 char[] sourceText; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
104 char[] separator; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
105 bool ignoreWSToks; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
106 bool printWS; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
107 |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
108 foreach (arg; args[2..$]) |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
109 { |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
110 if (strbeg(arg, "-t")) |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
111 sourceText = arg[2..$]; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
112 else if (strbeg(arg, "-s")) |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
113 separator = arg[2..$]; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
114 else if (arg == "-i") |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
115 ignoreWSToks = true; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
116 else if (arg == "-ws") |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
117 printWS = true; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
118 else |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
119 filePath = arg; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
120 } |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
121 |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
122 separator || (separator = "\n"); |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
123 sourceText || (sourceText = loadFile(filePath)); |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
124 |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
125 auto lx = new Lexer(sourceText, null); |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
126 lx.scanAll(); |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
127 auto token = lx.firstToken(); |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
128 |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
129 for (; token.type != TOK.EOF; token = token.next) |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
130 { |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
131 if (token.type == TOK.Newline || ignoreWSToks && token.isWhitespace) |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
132 continue; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
133 if (printWS && token.ws) |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
134 Stdout(token.wsChars); |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
135 Stdout(token.srcText)(separator); |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
136 } |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
137 break; |
513
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
138 case "profile": |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
139 if (args.length < 3) |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
140 break; |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
141 char[][] filePaths; |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
142 if (args[2] == "dstress") |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
143 { |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
144 auto text = cast(char[])(new File("dstress_files")).read(); |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
145 filePaths = split(text, "\0"); |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
146 } |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
147 else |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
148 filePaths = args[2..$]; |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
149 |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
150 StopWatch swatch; |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
151 swatch.start; |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
152 |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
153 foreach (filePath; filePaths) |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
154 (new Lexer(loadFile(filePath), null)).scanAll(); |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
155 |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
156 Stdout.formatln("Scanned in {:f10}s.", swatch.stop); |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
157 break; |
312 | 158 case "parse": |
159 if (args.length == 3) | |
160 parse(args[2]); | |
161 break; | |
338 | 162 case "?", "help": |
163 if (args.length == 3) | |
164 printHelp(args[2]); | |
165 else | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
166 Stdout(helpMain()); |
338 | 167 break; |
306 | 168 default: |
169 } | |
170 } | |
171 | |
338 | 172 const char[] COMMANDS = |
173 " generate (gen)\n" | |
363 | 174 " help (?)\n" |
366 | 175 " importgraph (igraph)\n" |
487
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
176 " statistics (stats)\n" |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
177 " tokenize (tok)\n"; |
338 | 178 |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
179 bool strbeg(char[] str, char[] begin) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
180 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
181 if (str.length >= begin.length) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
182 { |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
183 if (str[0 .. begin.length] == begin) |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
184 return true; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
185 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
186 return false; |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
187 } |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
188 |
338 | 189 char[] helpMain() |
190 { | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
191 return FormatMsg(MID.HelpMain, VERSION, COMMANDS, COMPILED_WITH, COMPILED_VERSION, COMPILED_DATE); |
338 | 192 } |
193 | |
194 void printHelp(char[] command) | |
195 { | |
196 char[] msg; | |
197 switch (command) | |
198 { | |
199 case "gen", "generate": | |
200 msg = GetMsg(MID.HelpGenerate); | |
201 break; | |
375
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
202 case "importgraph", "igraph": |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
203 msg = GetMsg(MID.HelpImportGraph); |
0bd21b746a04
- Added code to main() for recognizing options to the importgraph command.
aziz
parents:
368
diff
changeset
|
204 break; |
487
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
205 case "tok", "tokenize": |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
206 msg = `Print the tokens of a D source file. |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
207 Usage: |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
208 dil tok file.d [Options] |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
209 |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
210 Options: |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
211 -tTEXT : tokenize TEXT instead of a file. |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
212 -sSEPARATOR : print SEPARATOR instead of newline between tokens. |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
213 -i : ignore whitespace tokens (e.g. comments, shebang etc.) |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
214 -ws : print a token's preceding whitespace characters. |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
215 |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
216 Example: |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
217 dil tok -t"module foo; void func(){}" |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
218 dil tok main.d | grep ^[0-9]`; |
bccca748d745
Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
219 break; |
513
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
220 case "stats", "statistics": |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
221 msg = "Gather statistics about D source files. |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
222 Usage: |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
223 dil stat file.d [file2.d, ...] |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
224 |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
225 Example: |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
226 dil stat src/dil/Parser.d src/dil/Lexer.d"; |
6160ab7b1816
Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
487
diff
changeset
|
227 break; |
338 | 228 default: |
229 msg = helpMain(); | |
230 } | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
375
diff
changeset
|
231 Stdout(msg).newline; |
338 | 232 } |
233 | |
306 | 234 void parse(string fileName) |
235 { | |
358
0faf57d99c1c
- Replaced calls to std.file.read() with dil.loadFile().
aziz
parents:
351
diff
changeset
|
236 auto sourceText = loadFile(fileName); |
306 | 237 auto parser = new Parser(sourceText, fileName); |
368 | 238 auto root = parser.start(); |
299
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
249
diff
changeset
|
239 |
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
249
diff
changeset
|
240 void print(Node[] decls, char[] indent) |
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
249
diff
changeset
|
241 { |
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
249
diff
changeset
|
242 foreach(decl; decls) |
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
249
diff
changeset
|
243 { |
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
249
diff
changeset
|
244 assert(decl !is null); |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
464
diff
changeset
|
245 Stdout.formatln("{}{}: begin={} end={}", indent, decl.classinfo.name, decl.begin ? decl.begin.srcText : "\33[31mnull\33[0m", decl.end ? decl.end.srcText : "\33[31mnull\33[0m"); |
299
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
249
diff
changeset
|
246 print(decl.children, indent ~ " "); |
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
249
diff
changeset
|
247 } |
559d5d62e0c1
- Added checks for null before adding member to Node.children.
aziz
parents:
249
diff
changeset
|
248 } |
305 | 249 print(root.children, ""); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
112
diff
changeset
|
250 foreach (error; parser.errors) |
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
112
diff
changeset
|
251 { |
422
ad7977fe315a
Added support for column numbers in error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
401
diff
changeset
|
252 Stdout.format(`{0}({1})P: {2}`, error.filePath, error.loc, error.getMsg); |
213
b0ebde88d2d4
- Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents:
112
diff
changeset
|
253 } |
306 | 254 } |