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