annotate trunk/src/main.d @ 329:17f43b0d6106

- Renamed command highlight to generate. - Added message HelpGenerate. - Fix in getShortClassName(): added statement for removing package name.
author aziz
date Tue, 21 Aug 2007 19:44:03 +0000
parents 39f93a4ec416
children 44fc02d1eae6
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 +/
8ba2570de175 Initial import.
aziz
parents:
diff changeset
5 module dparser;
3
4bbce78bfb1e - Added TOK enum.
aziz
parents: 0
diff changeset
6 import std.stdio;
4
92df59b1ec4a - Started implementation of scan().
aziz
parents: 3
diff changeset
7 import std.file;
327
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 323
diff changeset
8 import dil.Parser;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 323
diff changeset
9 import dil.Lexer;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 323
diff changeset
10 import dil.Token;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 323
diff changeset
11 import dil.Messages;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 323
diff changeset
12 import dil.Settings;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 323
diff changeset
13 import dil.Declarations, dil.Expressions, dil.SyntaxTree;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
14
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
15 void main(char[][] args)
8ba2570de175 Initial import.
aziz
parents:
diff changeset
16 {
309
b4d842b0d2c7 - Added new files Settings.d, config.d and lang_en.d
aziz
parents: 308
diff changeset
17 GlobalSettings.load();
b4d842b0d2c7 - Added new files Settings.d, config.d and lang_en.d
aziz
parents: 308
diff changeset
18
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
19 if (args.length <= 1)
329
17f43b0d6106 - Renamed command highlight to generate.
aziz
parents: 328
diff changeset
20 return writefln(format(MID.HelpMain, VERSION, usageGenerate, COMPILED_WITH, COMPILED_VERSION, COMPILED_DATE));
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
21
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
22 string command = args[1];
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
23 switch (command)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
24 {
329
17f43b0d6106 - Renamed command highlight to generate.
aziz
parents: 328
diff changeset
25 case "gen", "generate":
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
26 char[] fileName;
329
17f43b0d6106 - Renamed command highlight to generate.
aziz
parents: 328
diff changeset
27 DocOption options = DocOption.Tokens;
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
28 foreach (arg; args[2..$])
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
29 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
30 switch (arg)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
31 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
32 case "--syntax":
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
33 options |= DocOption.Syntax; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
34 case "--xml":
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
35 options |= DocOption.XML; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
36 case "--html":
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
37 options |= DocOption.HTML; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
38 default:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
39 fileName = arg;
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 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
42 if (!(options & (DocOption.XML | DocOption.HTML)))
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
43 options |= DocOption.XML; // Default to XML.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
44 if (options & DocOption.Syntax)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
45 syntaxToDoc(fileName, options);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
46 else
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
47 tokensToDoc(fileName, options);
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
48 break;
312
fa0b6f32c1ae - Added Special to enum TOK.
aziz
parents: 309
diff changeset
49 case "parse":
fa0b6f32c1ae - Added Special to enum TOK.
aziz
parents: 309
diff changeset
50 if (args.length == 3)
fa0b6f32c1ae - Added Special to enum TOK.
aziz
parents: 309
diff changeset
51 parse(args[2]);
fa0b6f32c1ae - Added Special to enum TOK.
aziz
parents: 309
diff changeset
52 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
53 default:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
54 }
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
55 }
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
56
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
57 enum DocOption
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
58 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
59 Tokens,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
60 Syntax = 1<<1,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
61 HTML = 1<<2,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
62 XML = 1<<3
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
63 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
64
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
65 void parse(string fileName)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
66 {
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
67 auto sourceText = cast(char[]) std.file.read(fileName);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
68 auto parser = new Parser(sourceText, fileName);
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
69 parser.start();
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 303
diff changeset
70 auto root = parser.parseModule();
299
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
71
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
72 void print(Node[] decls, char[] indent)
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
73 {
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
74 foreach(decl; decls)
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
75 {
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
76 assert(decl !is null);
303
bc1112f7933d - Added keyword debug to some statements.
aziz
parents: 299
diff changeset
77 writefln(indent, decl.classinfo.name, ": begin=%s end=%s", 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
78 print(decl.children, indent ~ " ");
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
79 }
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
80 }
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 303
diff changeset
81 print(root.children, "");
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
82 foreach (error; parser.errors)
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
83 {
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
84 writefln(`%s(%d)P: %s`, parser.lx.fileName, error.loc, error.getMsg);
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
85 }
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
86 }
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
87
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
88 char[] xml_escape(char[] text)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
89 {
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
90 char[] result;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
91 foreach(c; text)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
92 switch(c)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
93 {
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
94 case '<': result ~= "&lt;"; break;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
95 case '>': result ~= "&gt;"; break;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
96 case '&': result ~= "&amp;"; break;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
97 default: result ~= c;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
98 }
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
99 return result;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
100 }
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
101
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
102 char[] getShortClassName(Node n)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
103 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
104 alias std.string.find find;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
105 char[] name = n.classinfo.name;
329
17f43b0d6106 - Renamed command highlight to generate.
aziz
parents: 328
diff changeset
106 name = name[find(name, ".")+1 .. $]; // Remove package name
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
107 name = name[find(name, ".")+1 .. $]; // Remove module name
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
108 char[] remove;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
109 switch (n.category)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
110 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
111 alias NodeCategory NC;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
112 case NC.Declaration: remove = "Declaration"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
113 case NC.Statement:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
114 if (n.kind == NodeKind.Statements)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
115 return name;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
116 remove = "Statement";
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
117 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
118 case NC.Expression: remove = "Expression"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
119 case NC.Type: remove = "Type"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
120 case NC.Other: return name;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
121 default:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
122 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
123 // Remove common suffix.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
124 auto idx = find(name, remove);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
125 if (idx != -1)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
126 name = name[0 .. idx];
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
127 return name;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
128 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
129
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
130 enum DocPart
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
131 {
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
132 Head,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
133 CompBegin,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
134 CompEnd,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
135 Error,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
136 SyntaxBegin,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
137 SyntaxEnd,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
138 SrcBegin,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
139 SrcEnd,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
140 Tail,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
141 // Tokens:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
142 Identifier,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
143 Comment,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
144 StringLiteral,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
145 CharLiteral,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
146 Operator,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
147 LorG,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
148 LessEqual,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
149 GreaterEqual,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
150 AndLogical,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
151 OrLogical,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
152 NotEqual,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
153 Not,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
154 Number,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
155 Bracket,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
156 SpecialToken,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
157 Shebang,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
158 Keyword,
328
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
159 HLineBegin,
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
160 HLineEnd,
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
161 Filespec,
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
162 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
163
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
164 auto html_tags = [
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
165 // Head
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
166 `<html>`\n
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
167 `<head>`\n
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
168 `<meta http-equiv="Content-Type" content="text/html; charset=utf-8">`\n
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
169 `<link href="dil_html.css" rel="stylesheet" type="text/css">`\n
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
170 `</head>`\n
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
171 `<body>`[],
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
172 // CompBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
173 `<div class="compilerinfo">`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
174 // CompEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
175 `</div>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
176 // Error
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
177 `<p class="error %s">%s(%d)%s: %s</p>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
178 // SyntaxBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
179 `<span class="%s %s">`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
180 // SyntaxEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
181 `</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
182 // SrcBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
183 `<pre class="sourcecode">`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
184 // SrcEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
185 `</pre>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
186 // Tail
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
187 `</html>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
188 // Identifier
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
189 `<span class="i">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
190 // Comment
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
191 `<span class="c%s">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
192 // StringLiteral
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
193 `<span class="sl">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
194 // CharLiteral
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
195 `<span class="cl">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
196 // Operator
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
197 `<span class="op">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
198 // LorG
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
199 `<span class="oplg">&lt;&gt;</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
200 // LessEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
201 `<span class="ople">&lt;=</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
202 // GreaterEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
203 `<span class="opge">&gt;=</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
204 // AndLogical
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
205 `<span class="opaa">&amp;&amp;</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
206 // OrLogical
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
207 `<span class="opoo">||</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
208 // NotEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
209 `<span class="opne">!=</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
210 // Not
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
211 `<span class="opn">!</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
212 // Number
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
213 `<span class="n">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
214 // Bracket
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
215 `<span class="br">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
216 // SpecialToken
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
217 `<span class="st">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
218 // Shebang
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
219 `<span class="shebang">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
220 // Keyword
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
221 `<span class="k">%s</span>`,
328
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
222 // HLineBegin
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
223 `<span class="hl">#line`,
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
224 // HLineEnd
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
225 "</span>",
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
226 // Filespec
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
227 `<span class="fs">%s</span>`,
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
228 ];
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
229
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
230 auto xml_tags = [
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
231 // Head
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
232 `<?xml version="1.0"?>`\n
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
233 `<?xml-stylesheet href="format.css" type="text/css"?>`\n
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
234 `<root>`[],
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
235 // CompBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
236 `<compilerinfo>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
237 // CompEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
238 `</compilerinfo>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
239 // Error
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
240 `<error t="%s">%s(%d)%s: %s</error>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
241 // SyntaxBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
242 `<%s t="%s">`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
243 // SyntaxEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
244 `</%s>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
245 // SrcBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
246 `<sourcecode>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
247 // SrcEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
248 `</sourcecode>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
249 // Tail
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
250 `</root>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
251 // Identifier
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
252 "<i>%s</i>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
253 // Comment
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
254 `<c t="%s">%s</c>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
255 // StringLiteral
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
256 "<sl>%s</sl>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
257 // CharLiteral
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
258 "<cl>%s</cl>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
259 // Operator
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
260 "<op>%s</op>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
261 // LorG
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
262 `<op t="lg">&lt;&gt;</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
263 // LessEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
264 `<op t="le">&lt;=</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
265 // GreaterEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
266 `<op t="ge">&gt;=</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
267 // AndLogical
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
268 `<op t="aa">&amp;&amp;</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
269 // OrLogical
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
270 `<op t="oo">||</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
271 // NotEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
272 `<op t="ne">!=</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
273 // Not
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
274 `<op t="n">!</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
275 // Number
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
276 "<n>%s</n>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
277 // Bracket
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
278 "<br>%s</br>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
279 // SpecialToken
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
280 "<st>%s</st>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
281 // Shebang
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
282 "<shebang>%s</shebang>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
283 // Keyword
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
284 "<k>%s</k>",
328
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
285 // HLineBegin
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
286 "<hl>#line",
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
287 // HLineEnd
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
288 "</hl>",
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
289 // Filespec
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
290 "<fs>%s</fs>",
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
291 ];
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
292
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
293 static assert(html_tags.length == DocPart.max+1);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
294 static assert(xml_tags.length == DocPart.max+1);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
295
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
296 void syntaxToDoc(string fileName, DocOption options)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
297 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
298 auto tags = options & DocOption.HTML ? html_tags : xml_tags;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
299 auto sourceText = cast(char[]) std.file.read(fileName);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
300 auto parser = new Parser(sourceText, fileName);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
301 parser.start();
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
302 auto root = parser.parseModule();
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
303 auto lx = parser.lx;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
304
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
305 auto token = lx.head;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
306 char* end = lx.text.ptr;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
307
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
308 writefln(tags[DocPart.Head]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
309 // Output error messages.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
310 if (lx.errors.length || parser.errors.length)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
311 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
312 writefln(tags[DocPart.CompBegin]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
313 foreach (error; lx.errors)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
314 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
315 writefln(tags[DocPart.Error], "L", lx.fileName, error.loc, "L", xml_escape(error.getMsg));
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
316 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
317 foreach (error; parser.errors)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
318 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
319 writefln(tags[DocPart.Error], "P", lx.fileName, error.loc, "P", xml_escape(error.getMsg));
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
320 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
321 writefln(tags[DocPart.CompEnd]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
322 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
323 writef(tags[DocPart.SrcBegin]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
324
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
325 Node[][Token*] beginNodes, endNodes;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
326
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
327 void populateAAs(Node[] nodes)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
328 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
329 foreach (node; nodes)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
330 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
331 auto begin = node.begin;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
332 if (begin)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
333 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
334 auto end = node.end;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
335 assert(end);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
336 beginNodes[begin] ~= node;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
337 endNodes[end] ~= node;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
338 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
339 if (node.children.length)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
340 populateAAs(node.children);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
341 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
342 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
343 populateAAs(root.children);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
344
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
345 char[] getTag(NodeCategory nc)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
346 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
347 char[] tag;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
348 switch (nc)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
349 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
350 alias NodeCategory NC;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
351 case NC.Declaration: tag = "d"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
352 case NC.Statement: tag = "s"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
353 case NC.Expression: tag = "e"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
354 case NC.Type: tag = "t"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
355 case NC.Other: tag = "o"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
356 default:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
357 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
358 return tag;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
359 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
360
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
361 // Traverse linked list and print tokens.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
362 while (token.type != TOK.EOF)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
363 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
364 token = token.next;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
365
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
366 // Print whitespace between previous and current token.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
367 if (end != token.start)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
368 writef("%s", end[0 .. token.start - end]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
369
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
370 Node[]* nodes = token in beginNodes;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
371
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
372 if (nodes)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
373 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
374 foreach (node; *nodes)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
375 writef(tags[DocPart.SyntaxBegin], getTag(node.category), getShortClassName(node));
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
376 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
377
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
378 printToken(token, tags);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
379
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
380 nodes = token in endNodes;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
381
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
382 if (nodes)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
383 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
384 foreach_reverse (node; *nodes)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
385 if (options & DocOption.HTML)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
386 writef(tags[DocPart.SyntaxEnd]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
387 else
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
388 writef(tags[DocPart.SyntaxEnd], getTag(node.category));
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
389 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
390
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
391 end = token.end;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
392 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
393 writef(tags[DocPart.SrcEnd], tags[DocPart.Tail]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
394 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
395
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
396 void tokensToDoc(string fileName, DocOption options)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
397 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
398 auto tags = options & DocOption.HTML ? html_tags : xml_tags;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
399 auto sourceText = cast(char[]) std.file.read(fileName);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
400 auto lx = new Lexer(sourceText, fileName);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
401
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
402 auto token = lx.getTokens();
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
403 char* end = lx.text.ptr;
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
404
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
405 writefln(tags[DocPart.Head]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
406
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
407 if (lx.errors.length)
51
cadd2bfe686c - Displaying error messages in XML.
aziz
parents: 44
diff changeset
408 {
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
409 writefln(tags[DocPart.CompBegin]);
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
410 foreach (error; lx.errors)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
411 {
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
412 writefln(tags[DocPart.Error], "L", lx.fileName, error.loc, "L", xml_escape(error.getMsg));
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
413 }
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
414 writefln(tags[DocPart.CompEnd]);
51
cadd2bfe686c - Displaying error messages in XML.
aziz
parents: 44
diff changeset
415 }
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
416 writef(tags[DocPart.SrcBegin]);
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
417
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
418 // Traverse linked list and print tokens.
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
419 while (token.type != TOK.EOF)
4
92df59b1ec4a - Started implementation of scan().
aziz
parents: 3
diff changeset
420 {
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
421 token = token.next;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
422
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
423 // Print whitespace between previous and current token.
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
424 if (end != token.start)
328
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
425 writef("%s", end[0 .. token.start - end]);
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
426 printToken(token, tags);
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
427 end = token.end;
4
92df59b1ec4a - Started implementation of scan().
aziz
parents: 3
diff changeset
428 }
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
429 writef(\n, tags[DocPart.SrcEnd], \n, tags[DocPart.Tail]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
430 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
431
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
432 void printToken(Token* token, string[] tags)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
433 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
434 alias DocPart DP;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
435 string srcText = xml_escape(token.srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
436
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
437 switch(token.type)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
438 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
439 case TOK.Identifier:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
440 writef(tags[DP.Identifier], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
441 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
442 case TOK.Comment:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
443 string t;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
444 switch (token.start[1])
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
445 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
446 case '/': t = "l"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
447 case '*': t = "b"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
448 case '+': t = "n"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
449 default:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
450 assert(0);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
451 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
452 writef(tags[DP.Comment], t, srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
453 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
454 case TOK.String:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
455 writef(tags[DP.StringLiteral], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
456 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
457 case TOK.CharLiteral, TOK.WCharLiteral, TOK.DCharLiteral:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
458 writef(tags[DP.CharLiteral], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
459 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
460 case TOK.Assign, TOK.Equal,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
461 TOK.Less, TOK.Greater,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
462 TOK.LShiftAssign, TOK.LShift,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
463 TOK.RShiftAssign, TOK.RShift,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
464 TOK.URShiftAssign, TOK.URShift,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
465 TOK.OrAssign, TOK.OrBinary,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
466 TOK.AndAssign, TOK.AndBinary,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
467 TOK.PlusAssign, TOK.PlusPlus, TOK.Plus,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
468 TOK.MinusAssign, TOK.MinusMinus, TOK.Minus,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
469 TOK.DivAssign, TOK.Div,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
470 TOK.MulAssign, TOK.Mul,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
471 TOK.ModAssign, TOK.Mod,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
472 TOK.XorAssign, TOK.Xor,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
473 TOK.CatAssign,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
474 TOK.Tilde,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
475 TOK.Unordered,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
476 TOK.UorE,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
477 TOK.UorG,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
478 TOK.UorGorE,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
479 TOK.UorL,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
480 TOK.UorLorE,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
481 TOK.LorEorG:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
482 writef(tags[DP.Operator], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
483 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
484 case TOK.LorG:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
485 writef(tags[DP.LorG]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
486 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
487 case TOK.LessEqual:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
488 writef(tags[DP.LessEqual]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
489 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
490 case TOK.GreaterEqual:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
491 writef(tags[DP.GreaterEqual]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
492 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
493 case TOK.AndLogical:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
494 writef(tags[DP.AndLogical]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
495 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
496 case TOK.OrLogical:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
497 writef(tags[DP.OrLogical]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
498 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
499 case TOK.NotEqual:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
500 writef(tags[DP.NotEqual]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
501 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
502 case TOK.Not:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
503 // Check if this is part of a template instantiation.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
504 // TODO: comments aren't skipped.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
505 if (token.prev.type == TOK.Identifier && token.next.type == TOK.LParen)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
506 goto default;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
507 writef(tags[DP.Not]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
508 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
509 case TOK.Int32, TOK.Int64, TOK.Uint32, TOK.Uint64,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
510 TOK.Float32, TOK.Float64, TOK.Float80,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
511 TOK.Imaginary32, TOK.Imaginary64, TOK.Imaginary80:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
512 writef(tags[DP.Number], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
513 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
514 case TOK.LParen, TOK.RParen, TOK.LBracket,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
515 TOK.RBracket, TOK.LBrace, TOK.RBrace:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
516 writef(tags[DP.Bracket], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
517 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
518 case TOK.Special:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
519 writef(tags[DP.SpecialToken], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
520 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
521 case TOK.Shebang:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
522 writef(tags[DP.Shebang], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
523 break;
323
6259fb93e3dd - Rewrote scanSpecialToken().
aziz
parents: 322
diff changeset
524 case TOK.HashLine:
328
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
525 void printWS(char* start, char* end)
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
526 {
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
527 if (start != end)
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
528 writef(start[0 .. end - start]);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
529 }
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
530 writef(tags[DP.HLineBegin]);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
531 auto num = token.line_num;
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
532 // Print whitespace between #line and number
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
533 auto ptr = token.start + "#line".length;
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
534 printWS(ptr, num.start);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
535 printToken(num, tags);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
536 if (token.line_filespec)
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
537 {
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
538 auto filespec = token.line_filespec;
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
539 // Print whitespace between number and filespec
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
540 printWS(num.end, filespec.start);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
541 writef(tags[DP.Filespec], xml_escape(filespec.srcText));
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
542
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
543 ptr = filespec.end;
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
544 }
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
545 else
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
546 ptr = num.end;
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
547 // Print remaining whitespace
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
548 printWS(ptr, token.end);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
549 writef(tags[DP.HLineEnd]);
323
6259fb93e3dd - Rewrote scanSpecialToken().
aziz
parents: 322
diff changeset
550 break;
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
551 default:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
552 if (token.isKeyword())
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
553 writef(tags[DP.Keyword], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
554 else
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
555 writef("%s", srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
556 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
557 }