annotate trunk/src/main.d @ 714:140469ecb90e

Added code and applied fixes. Added getDDocText() and isLineComment(). Renamed getDocComments() to getDocTokens(). Fixed it as well. printSymbolTable() is called recursively now. Fixed genAnonymousID().
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Thu, 31 Jan 2008 01:10:30 +0100
parents d75aad38d1b2
children ca7607226caa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
1 /++
8ba2570de175 Initial import.
aziz
parents:
diff changeset
2 Author: Aziz Köksal
249
32d354584b28 - Upgraded license notices to GPL3.
aziz
parents: 213
diff changeset
3 License: GPL3
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
4 +/
347
73f81f21f870 - Changed module name of main.d from dparser to main.
aziz
parents: 343
diff changeset
5 module main;
513
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
6
578
c769bc239006 Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 576
diff changeset
7 import dil.parser.Parser;
618
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
8 import dil.lexer.Lexer,
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
9 dil.lexer.Token;
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
10 import dil.ast.Declarations,
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
11 dil.ast.Expressions,
635
b2fc028d8b55 Added class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 631
diff changeset
12 dil.ast.Node,
b2fc028d8b55 Added class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 631
diff changeset
13 dil.ast.Visitor;
670
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
14 import dil.semantic.Module;
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
15 import dil.semantic.Symbols;
684
10b314bf37e3 Added module dil.semantic.Pass2.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 683
diff changeset
16 import dil.semantic.Pass1,
687
f14cd41fc87d Added new module dil.semantic.Interpreter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 684
diff changeset
17 dil.semantic.Pass2,
f14cd41fc87d Added new module dil.semantic.Interpreter.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 684
diff changeset
18 dil.semantic.Interpreter;
670
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
19 import dil.translator.German;
676
c4e3a34e40f1 Added new module dil.doc.Doc.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 672
diff changeset
20 import dil.doc.Doc;
327
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 323
diff changeset
21 import dil.Messages;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 323
diff changeset
22 import dil.Settings;
513
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
23 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
24 import dil.CompilerInfo;
520
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
25 import dil.Information;
351
97a9a2d7d46d - Added module File.
aziz
parents: 347
diff changeset
26 import dil.File;
618
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
27
363
2b387a3c6b58 - Added package cmd.
aziz
parents: 358
diff changeset
28 import cmd.Generate;
2b387a3c6b58 - Added package cmd.
aziz
parents: 358
diff changeset
29 import cmd.Statistics;
364
1059295c2727 - Every command module has an execute method now.
aziz
parents: 363
diff changeset
30 import cmd.ImportGraph;
391
33b566df6af4 Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 375
diff changeset
31 import common;
33b566df6af4 Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 375
diff changeset
32
33b566df6af4 Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 375
diff changeset
33 import Integer = tango.text.convert.Integer;
513
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
34 import tango.io.File;
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
35 import tango.text.Util;
575
dd3fe62c8a96 Compiles with Tango 0.99.4 now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 564
diff changeset
36 import tango.time.StopWatch;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
37
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
38 void main(char[][] args)
8ba2570de175 Initial import.
aziz
parents:
diff changeset
39 {
513
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
40 dil.SettingsLoader.loadSettings();
309
b4d842b0d2c7 - Added new files Settings.d, config.d and lang_en.d
aziz
parents: 308
diff changeset
41
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
42 if (args.length <= 1)
391
33b566df6af4 Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 375
diff changeset
43 return Stdout(helpMain()).newline;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
44
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
45 string command = args[1];
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
46 switch (command)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
47 {
520
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
48 case "c", "compile":
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
49 if (args.length < 2)
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
50 return printHelp("compile");
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
51
532
50e64bab9c7a Renamed InformationManager to InfoManager.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 520
diff changeset
52 auto infoMan = new InfoManager();
520
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
53 auto filePaths = args[2..$];
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
54 foreach (filePath; filePaths)
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
55 {
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
56 auto mod = new Module(filePath, infoMan);
564
3c867a683258 Fixed VariableDeclaration.semantic().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 545
diff changeset
57 // Parse the file.
520
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
58 mod.parse();
649
3ebe76ad680e Using SemanticPass1 in main.d do start semantic analysis.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 635
diff changeset
59 if (mod.hasErrors)
3ebe76ad680e Using SemanticPass1 in main.d do start semantic analysis.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 635
diff changeset
60 continue;
670
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
61
564
3c867a683258 Fixed VariableDeclaration.semantic().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 545
diff changeset
62 // Start semantic analysis.
649
3ebe76ad680e Using SemanticPass1 in main.d do start semantic analysis.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 635
diff changeset
63 auto pass1 = new SemanticPass1(mod);
3ebe76ad680e Using SemanticPass1 in main.d do start semantic analysis.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 635
diff changeset
64 pass1.start();
618
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
65
714
140469ecb90e Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 705
diff changeset
66 void printSymbolTable(ScopeSymbol scopeSym, char[] indent)
618
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
67 {
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
68 foreach (member; scopeSym.members)
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
69 {
714
140469ecb90e Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 705
diff changeset
70 auto tokens = getDocTokens(member.node);
618
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
71 char[] docText;
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
72 foreach (token; tokens)
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
73 docText ~= token.srcText;
714
140469ecb90e Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 705
diff changeset
74 Stdout(indent).formatln("Id:{}, Symbol:{}, DocText:{}", member.name.str, member.classinfo.name, docText);
140469ecb90e Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 705
diff changeset
75 if (auto s = cast(ScopeSymbol)member)
140469ecb90e Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 705
diff changeset
76 printSymbolTable(s, indent ~ "→ ");
618
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
77 }
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
78 }
07946b379006 Refactored the way dot expressions are parsed.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 596
diff changeset
79
714
140469ecb90e Added code and applied fixes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 705
diff changeset
80 printSymbolTable(mod, "");
520
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
81 }
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
82
670
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
83 printErrors(infoMan);
520
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
84 break;
329
17f43b0d6106 - Renamed command highlight to generate.
aziz
parents: 328
diff changeset
85 case "gen", "generate":
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
86 char[] fileName;
329
17f43b0d6106 - Renamed command highlight to generate.
aziz
parents: 328
diff changeset
87 DocOption options = DocOption.Tokens;
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
88 foreach (arg; args[2..$])
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
89 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
90 switch (arg)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
91 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
92 case "--syntax":
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
93 options |= DocOption.Syntax; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
94 case "--xml":
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
95 options |= DocOption.XML; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
96 case "--html":
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
97 options |= DocOption.HTML; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
98 default:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
99 fileName = arg;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
100 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
101 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
102 if (!(options & (DocOption.XML | DocOption.HTML)))
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
103 options |= DocOption.XML; // Default to XML.
364
1059295c2727 - Every command module has an execute method now.
aziz
parents: 363
diff changeset
104 cmd.Generate.execute(fileName, options);
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
105 break;
366
dcbd3bf9bf74 - Added command importgraph/igraph to main.d.
aziz
parents: 364
diff changeset
106 case "importgraph", "igraph":
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
107 string filePath;
366
dcbd3bf9bf74 - Added command importgraph/igraph to main.d.
aziz
parents: 364
diff changeset
108 string[] includePaths;
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
109 string[] regexps;
703
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
110 string siStyle = "dashed"; // static import style
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
111 string piStyle = "bold"; // public import style
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
112 uint levels;
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
113 IGraphOption options;
366
dcbd3bf9bf74 - Added command importgraph/igraph to main.d.
aziz
parents: 364
diff changeset
114 foreach (arg; args[2..$])
dcbd3bf9bf74 - Added command importgraph/igraph to main.d.
aziz
parents: 364
diff changeset
115 {
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
116 if (strbeg(arg, "-I"))
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
117 includePaths ~= arg[2..$];
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
118 else if(strbeg(arg, "-r"))
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
119 regexps ~= arg[2..$];
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
120 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
121 levels = Integer.toInt(arg[2..$]);
703
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
122 else if(strbeg(arg, "-si"))
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
123 siStyle = arg[3..$];
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
124 else if(strbeg(arg, "-pi"))
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
125 piStyle = arg[3..$];
366
dcbd3bf9bf74 - Added command importgraph/igraph to main.d.
aziz
parents: 364
diff changeset
126 else
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
127 switch (arg)
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
128 {
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
129 case "--dot":
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
130 options |= IGraphOption.PrintDot; break;
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
131 case "--paths":
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
132 options |= IGraphOption.PrintPaths; break;
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
133 case "--list":
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
134 options |= IGraphOption.PrintList; break;
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
135 case "-i":
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
136 options |= IGraphOption.IncludeUnlocatableModules; break;
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
137 case "-hle":
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
138 options |= IGraphOption.HighlightCyclicEdges; break;
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
139 case "-hlv":
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
140 options |= IGraphOption.HighlightCyclicVertices; break;
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
141 case "-gbp":
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
142 options |= IGraphOption.GroupByPackageNames; break;
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
143 case "-gbf":
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
144 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
145 case "-m":
e2bbc6406a14 Added a new option '-m' to the igraph command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
146 options |= IGraphOption.MarkCyclicModules; break;
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
147 default:
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
148 filePath = arg;
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
149 }
366
dcbd3bf9bf74 - Added command importgraph/igraph to main.d.
aziz
parents: 364
diff changeset
150 }
703
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
151 cmd.ImportGraph.execute(filePath, includePaths, regexps, levels, siStyle, piStyle, options);
366
dcbd3bf9bf74 - Added command importgraph/igraph to main.d.
aziz
parents: 364
diff changeset
152 break;
363
2b387a3c6b58 - Added package cmd.
aziz
parents: 358
diff changeset
153 case "stats", "statistics":
545
0bac0bb506ca Added '--table' option to 'stats' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
154 char[][] filePaths;
0bac0bb506ca Added '--table' option to 'stats' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
155 bool printTokensTable;
672
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 670
diff changeset
156 bool printNodesTable;
545
0bac0bb506ca Added '--table' option to 'stats' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
157 foreach (arg; args[2..$])
672
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 670
diff changeset
158 if (arg == "--toktable")
545
0bac0bb506ca Added '--table' option to 'stats' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
159 printTokensTable = true;
672
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 670
diff changeset
160 else if (arg == "--asttable")
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 670
diff changeset
161 printNodesTable = true;
545
0bac0bb506ca Added '--table' option to 'stats' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
162 else
0bac0bb506ca Added '--table' option to 'stats' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
163 filePaths ~= arg;
672
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 670
diff changeset
164 cmd.Statistics.execute(filePaths, printTokensTable, printNodesTable);
363
2b387a3c6b58 - Added package cmd.
aziz
parents: 358
diff changeset
165 break;
487
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
166 case "tok", "tokenize":
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
167 char[] filePath;
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
168 char[] sourceText;
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
169 char[] separator;
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
170 bool ignoreWSToks;
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
171 bool printWS;
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
172
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
173 foreach (arg; args[2..$])
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
174 {
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
175 if (strbeg(arg, "-t"))
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
176 sourceText = arg[2..$];
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
177 else if (strbeg(arg, "-s"))
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
178 separator = arg[2..$];
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
179 else if (arg == "-i")
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
180 ignoreWSToks = true;
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
181 else if (arg == "-ws")
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
182 printWS = true;
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
183 else
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
184 filePath = arg;
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
185 }
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
186
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
187 separator || (separator = "\n");
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
188 sourceText || (sourceText = loadFile(filePath));
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
189
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
190 auto lx = new Lexer(sourceText, null);
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
191 lx.scanAll();
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
192 auto token = lx.firstToken();
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
193
679
ff6971637f88 Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 676
diff changeset
194 for (; token.kind != TOK.EOF; token = token.next)
487
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
195 {
679
ff6971637f88 Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 676
diff changeset
196 if (token.kind == TOK.Newline || ignoreWSToks && token.isWhitespace)
487
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
197 continue;
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
198 if (printWS && token.ws)
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
199 Stdout(token.wsChars);
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
200 Stdout(token.srcText)(separator);
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
201 }
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
202 break;
670
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
203 case "trans", "translate":
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
204 if (args.length < 3)
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
205 return printHelp("trans");
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
206
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
207 if (args[2] != "German")
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
208 return Stdout.formatln("Error: unrecognized target language \"{}\"", args[2]);
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
209
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
210 auto infoMan = new InfoManager();
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
211 auto filePath = args[3];
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
212 auto mod = new Module(filePath, infoMan);
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
213 // Parse the file.
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
214 mod.parse();
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
215 if (!mod.hasErrors)
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
216 { // Translate
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
217 auto german = new GermanTranslator(Stdout, " ");
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
218 german.translate(mod.root);
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
219 }
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
220 printErrors(infoMan);
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
221 break;
513
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
222 case "profile":
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
223 if (args.length < 3)
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
224 break;
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
225 char[][] filePaths;
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
226 if (args[2] == "dstress")
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
227 {
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
228 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
229 filePaths = split(text, "\0");
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
230 }
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
231 else
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
232 filePaths = args[2..$];
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
233
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
234 StopWatch swatch;
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
235 swatch.start;
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
236
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
237 foreach (filePath; filePaths)
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
238 (new Lexer(loadFile(filePath), null)).scanAll();
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
239
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
240 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
241 break;
312
fa0b6f32c1ae - Added Special to enum TOK.
aziz
parents: 309
diff changeset
242 case "parse":
fa0b6f32c1ae - Added Special to enum TOK.
aziz
parents: 309
diff changeset
243 if (args.length == 3)
fa0b6f32c1ae - Added Special to enum TOK.
aziz
parents: 309
diff changeset
244 parse(args[2]);
fa0b6f32c1ae - Added Special to enum TOK.
aziz
parents: 309
diff changeset
245 break;
338
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
246 case "?", "help":
520
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
247 printHelp(args.length >= 3 ? args[2] : "");
338
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
248 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
249 default:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
250 }
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
251 }
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
252
338
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
253 const char[] COMMANDS =
520
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
254 " compile (c)\n"
338
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
255 " generate (gen)\n"
363
2b387a3c6b58 - Added package cmd.
aziz
parents: 358
diff changeset
256 " help (?)\n"
366
dcbd3bf9bf74 - Added command importgraph/igraph to main.d.
aziz
parents: 364
diff changeset
257 " importgraph (igraph)\n"
487
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
258 " statistics (stats)\n"
670
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
259 " tokenize (tok)\n"
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
260 " translate (trans)\n";
338
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
261
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
262 bool strbeg(char[] str, char[] begin)
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
263 {
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
264 if (str.length >= begin.length)
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
265 {
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
266 if (str[0 .. begin.length] == begin)
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
267 return true;
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
268 }
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
269 return false;
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
270 }
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
271
670
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
272 void printErrors(InfoManager infoMan)
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
273 {
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
274 foreach (info; infoMan.info)
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
275 {
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
276 char[] errorFormat;
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
277 if (info.classinfo is LexerError.classinfo)
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
278 errorFormat = GlobalSettings.lexerErrorFormat;
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
279 else if (info.classinfo is ParserError.classinfo)
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
280 errorFormat = GlobalSettings.parserErrorFormat;
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
281 else if (info.classinfo is SemanticError.classinfo)
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
282 errorFormat = GlobalSettings.semanticErrorFormat;
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
283 else
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
284 continue;
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
285 auto err = cast(Problem)info;
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
286 Stderr.formatln(errorFormat, err.filePath, err.loc, err.col, err.getMsg);
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
287 }
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
288 }
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
289
338
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
290 char[] helpMain()
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
291 {
391
33b566df6af4 Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 375
diff changeset
292 return FormatMsg(MID.HelpMain, VERSION, COMMANDS, COMPILED_WITH, COMPILED_VERSION, COMPILED_DATE);
338
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
293 }
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
294
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
295 void printHelp(char[] command)
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
296 {
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
297 char[] msg;
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
298 switch (command)
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
299 {
520
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
300 case "c", "compile":
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
301 msg = "Compile D source files.
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
302 Usage:
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
303 dil compile file.d [file2.d, ...] [Options]
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
304
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
305 This command only parses the source files and does little semantic analysis.
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
306 Errors are printed to standard error output.
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
307
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
308 Options:
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
309
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
310 Example:
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
311 dil c src/main.d";
f203c5248d0b Added 'compile' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 513
diff changeset
312 break;
338
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
313 case "gen", "generate":
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
314 msg = GetMsg(MID.HelpGenerate);
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
315 break;
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
316 case "importgraph", "igraph":
703
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
317 // msg = GetMsg(MID.HelpImportGraph);
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
318 msg = `Parse a module and build a module dependency graph based on its imports.
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
319 Usage:
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
320 dil igraph file.d Format [Options]
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
321
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
322 The directory of file.d is implicitly added to the list of import paths.
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
323
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
324 Format:
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
325 --dot : generate a dot document
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
326 Options related to --dot:
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
327 -gbp : Group modules by package names
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
328 -gbf : Group modules by full package name
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
329 -hle : highlight cyclic edges in the graph
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
330 -hlv : highlight modules in cyclic relationships
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
331 -siSTYLE : the edge style to use for static imports
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
332 -piSTYLE : the edge style to use for public imports
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
333 STYLE can be: "dashed", "dotted", "solid", "invis" or "bold"
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
334
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
335 --paths : print the file paths of the modules in the graph
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
336
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
337 --list : print the names of the module in the graph
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
338 Options common to --paths and --list:
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
339 -lN : print N levels.
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
340 -m : use '*' to mark modules in cyclic relationships
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
341
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
342 Options:
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
343 -Ipath : add 'path' to the list of import paths where modules are
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
344 looked for
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
345 -rREGEXP : exclude modules whose names match the regular expression
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
346 REGEXP
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
347 -i : include unlocatable modules
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
348
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
349 Example:
bf10602159c1 Added static and public import styles to 'igraph' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 687
diff changeset
350 dil igraph src/main.d`;
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 368
diff changeset
351 break;
487
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
352 case "tok", "tokenize":
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
353 msg = `Print the tokens of a D source file.
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
354 Usage:
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
355 dil tok file.d [Options]
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
356
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
357 Options:
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
358 -tTEXT : tokenize TEXT instead of a file.
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
359 -sSEPARATOR : print SEPARATOR instead of newline between tokens.
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
360 -i : ignore whitespace tokens (e.g. comments, shebang etc.)
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
361 -ws : print a token's preceding whitespace characters.
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
362
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
363 Example:
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
364 dil tok -t"module foo; void func(){}"
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
365 dil tok main.d | grep ^[0-9]`;
bccca748d745 Added 'tokenize' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 485
diff changeset
366 break;
513
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
367 case "stats", "statistics":
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
368 msg = "Gather statistics about D source files.
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
369 Usage:
545
0bac0bb506ca Added '--table' option to 'stats' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
370 dil stat file.d [file2.d, ...] [Options]
0bac0bb506ca Added '--table' option to 'stats' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
371
0bac0bb506ca Added '--table' option to 'stats' command.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 532
diff changeset
372 Options:
672
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 670
diff changeset
373 --toktable : print the count of all kinds of tokens in a table.
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 670
diff changeset
374 --asttable : print the count of all kinds of nodes in a table.
513
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
375
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
376 Example:
6160ab7b1816 Refactored code related to settings.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 487
diff changeset
377 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
378 break;
670
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
379 case "trans", "translate":
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
380 msg = `Translate a D source file to another language.
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
381 Usage:
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
382 dil translate Language file.d
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
383
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
384 Languages that are supported:
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
385 *) German
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
386
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
387 Example:
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
388 dil trans German src/main.d`;
d8c32113afde Added command 'translate'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 649
diff changeset
389 break;
338
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
390 default:
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
391 msg = helpMain();
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
392 }
391
33b566df6af4 Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 375
diff changeset
393 Stdout(msg).newline;
338
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
394 }
63c6afb915f7 - Made some corrections to the message catalogs.
aziz
parents: 334
diff changeset
395
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
396 void parse(string fileName)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
397 {
578
c769bc239006 Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 576
diff changeset
398 auto mod = new Module(fileName);
c769bc239006 Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 576
diff changeset
399 mod.parse();
299
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
400
578
c769bc239006 Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 576
diff changeset
401 void print(Node[] decls, char[] indent)
299
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
402 {
578
c769bc239006 Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 576
diff changeset
403 foreach(decl; decls)
c769bc239006 Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 576
diff changeset
404 {
c769bc239006 Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 576
diff changeset
405 assert(decl !is null);
c769bc239006 Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 576
diff changeset
406 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");
c769bc239006 Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 576
diff changeset
407 print(decl.children, indent ~ " ");
c769bc239006 Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 576
diff changeset
408 }
299
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
409 }
578
c769bc239006 Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 576
diff changeset
410 print(mod.root.children, "");
299
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
411 }