annotate trunk/src/main.d @ 334:ca8ad7c34d6a

- Added a name table to getShortClassName(). - Changed 't i' to 't > i' in CSS file.
author aziz
date Wed, 22 Aug 2007 09:45:00 +0000
parents 44fc02d1eae6
children 63c6afb915f7
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 {
334
ca8ad7c34d6a - Added a name table to getShortClassName().
aziz
parents: 330
diff changeset
104 static char[][] name_table;
ca8ad7c34d6a - Added a name table to getShortClassName().
aziz
parents: 330
diff changeset
105 if (name_table is null)
ca8ad7c34d6a - Added a name table to getShortClassName().
aziz
parents: 330
diff changeset
106 name_table = new char[][NodeKind.max+1];
ca8ad7c34d6a - Added a name table to getShortClassName().
aziz
parents: 330
diff changeset
107 char[] name = name_table[n.kind];
ca8ad7c34d6a - Added a name table to getShortClassName().
aziz
parents: 330
diff changeset
108 if (name !is null)
ca8ad7c34d6a - Added a name table to getShortClassName().
aziz
parents: 330
diff changeset
109 return name;
ca8ad7c34d6a - Added a name table to getShortClassName().
aziz
parents: 330
diff changeset
110
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
111 alias std.string.find find;
334
ca8ad7c34d6a - Added a name table to getShortClassName().
aziz
parents: 330
diff changeset
112 name = n.classinfo.name;
329
17f43b0d6106 - Renamed command highlight to generate.
aziz
parents: 328
diff changeset
113 name = name[find(name, ".")+1 .. $]; // Remove package name
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
114 name = name[find(name, ".")+1 .. $]; // Remove module name
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
115 char[] remove;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
116 switch (n.category)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
117 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
118 alias NodeCategory NC;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
119 case NC.Declaration: remove = "Declaration"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
120 case NC.Statement:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
121 if (n.kind == NodeKind.Statements)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
122 return name;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
123 remove = "Statement";
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
124 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
125 case NC.Expression: remove = "Expression"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
126 case NC.Type: remove = "Type"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
127 case NC.Other: return name;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
128 default:
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 // Remove common suffix.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
131 auto idx = find(name, remove);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
132 if (idx != -1)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
133 name = name[0 .. idx];
334
ca8ad7c34d6a - Added a name table to getShortClassName().
aziz
parents: 330
diff changeset
134 // Store the name.
ca8ad7c34d6a - Added a name table to getShortClassName().
aziz
parents: 330
diff changeset
135 name_table[n.kind] = name;
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
136 return name;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
137 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
138
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
139 enum DocPart
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
140 {
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
141 Head,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
142 CompBegin,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
143 CompEnd,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
144 Error,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
145 SyntaxBegin,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
146 SyntaxEnd,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
147 SrcBegin,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
148 SrcEnd,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
149 Tail,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
150 // Tokens:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
151 Identifier,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
152 Comment,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
153 StringLiteral,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
154 CharLiteral,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
155 Operator,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
156 LorG,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
157 LessEqual,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
158 GreaterEqual,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
159 AndLogical,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
160 OrLogical,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
161 NotEqual,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
162 Not,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
163 Number,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
164 Bracket,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
165 SpecialToken,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
166 Shebang,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
167 Keyword,
328
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
168 HLineBegin,
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
169 HLineEnd,
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
170 Filespec,
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
171 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
172
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
173 auto html_tags = [
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
174 // Head
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
175 `<html>`\n
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
176 `<head>`\n
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
177 `<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
178 `<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
179 `</head>`\n
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
180 `<body>`[],
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
181 // CompBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
182 `<div class="compilerinfo">`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
183 // CompEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
184 `</div>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
185 // Error
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
186 `<p class="error %s">%s(%d)%s: %s</p>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
187 // SyntaxBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
188 `<span class="%s %s">`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
189 // SyntaxEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
190 `</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
191 // SrcBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
192 `<pre class="sourcecode">`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
193 // SrcEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
194 `</pre>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
195 // Tail
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
196 `</html>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
197 // Identifier
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
198 `<span class="i">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
199 // Comment
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
200 `<span class="c%s">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
201 // StringLiteral
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
202 `<span class="sl">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
203 // CharLiteral
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
204 `<span class="cl">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
205 // Operator
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
206 `<span class="op">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
207 // LorG
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
208 `<span class="oplg">&lt;&gt;</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
209 // LessEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
210 `<span class="ople">&lt;=</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
211 // GreaterEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
212 `<span class="opge">&gt;=</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
213 // AndLogical
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
214 `<span class="opaa">&amp;&amp;</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
215 // OrLogical
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
216 `<span class="opoo">||</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
217 // NotEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
218 `<span class="opne">!=</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
219 // Not
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
220 `<span class="opn">!</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
221 // Number
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
222 `<span class="n">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
223 // Bracket
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
224 `<span class="br">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
225 // SpecialToken
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
226 `<span class="st">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
227 // Shebang
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
228 `<span class="shebang">%s</span>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
229 // Keyword
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
230 `<span class="k">%s</span>`,
328
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
231 // HLineBegin
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
232 `<span class="hl">#line`,
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
233 // HLineEnd
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
234 "</span>",
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
235 // Filespec
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
236 `<span class="fs">%s</span>`,
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
237 ];
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
238
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
239 auto xml_tags = [
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
240 // Head
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
241 `<?xml version="1.0"?>`\n
330
44fc02d1eae6 - Renamed format.css to dil_xml.css.
aziz
parents: 329
diff changeset
242 `<?xml-stylesheet href="dil_xml.css" type="text/css"?>`\n
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
243 `<root>`[],
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
244 // CompBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
245 `<compilerinfo>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
246 // CompEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
247 `</compilerinfo>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
248 // Error
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
249 `<error t="%s">%s(%d)%s: %s</error>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
250 // SyntaxBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
251 `<%s t="%s">`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
252 // SyntaxEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
253 `</%s>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
254 // SrcBegin
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
255 `<sourcecode>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
256 // SrcEnd
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
257 `</sourcecode>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
258 // Tail
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
259 `</root>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
260 // Identifier
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
261 "<i>%s</i>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
262 // Comment
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
263 `<c t="%s">%s</c>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
264 // StringLiteral
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
265 "<sl>%s</sl>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
266 // CharLiteral
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
267 "<cl>%s</cl>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
268 // Operator
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
269 "<op>%s</op>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
270 // LorG
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
271 `<op t="lg">&lt;&gt;</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
272 // LessEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
273 `<op t="le">&lt;=</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
274 // GreaterEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
275 `<op t="ge">&gt;=</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
276 // AndLogical
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
277 `<op t="aa">&amp;&amp;</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
278 // OrLogical
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
279 `<op t="oo">||</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
280 // NotEqual
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
281 `<op t="ne">!=</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
282 // Not
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
283 `<op t="n">!</op>`,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
284 // Number
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
285 "<n>%s</n>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
286 // Bracket
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
287 "<br>%s</br>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
288 // SpecialToken
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
289 "<st>%s</st>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
290 // Shebang
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
291 "<shebang>%s</shebang>",
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
292 // Keyword
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
293 "<k>%s</k>",
328
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
294 // HLineBegin
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
295 "<hl>#line",
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
296 // HLineEnd
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
297 "</hl>",
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
298 // Filespec
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
299 "<fs>%s</fs>",
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
300 ];
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
301
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
302 static assert(html_tags.length == DocPart.max+1);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
303 static assert(xml_tags.length == DocPart.max+1);
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 void syntaxToDoc(string fileName, DocOption options)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
306 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
307 auto tags = options & DocOption.HTML ? html_tags : xml_tags;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
308 auto sourceText = cast(char[]) std.file.read(fileName);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
309 auto parser = new Parser(sourceText, fileName);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
310 parser.start();
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
311 auto root = parser.parseModule();
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
312 auto lx = parser.lx;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
313
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
314 auto token = lx.head;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
315 char* end = lx.text.ptr;
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 writefln(tags[DocPart.Head]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
318 // Output error messages.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
319 if (lx.errors.length || parser.errors.length)
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.CompBegin]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
322 foreach (error; lx.errors)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
323 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
324 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
325 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
326 foreach (error; parser.errors)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
327 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
328 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
329 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
330 writefln(tags[DocPart.CompEnd]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
331 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
332 writef(tags[DocPart.SrcBegin]);
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 Node[][Token*] beginNodes, endNodes;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
335
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
336 void populateAAs(Node[] nodes)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
337 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
338 foreach (node; nodes)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
339 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
340 auto begin = node.begin;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
341 if (begin)
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 auto end = node.end;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
344 assert(end);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
345 beginNodes[begin] ~= node;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
346 endNodes[end] ~= node;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
347 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
348 if (node.children.length)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
349 populateAAs(node.children);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
350 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
351 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
352 populateAAs(root.children);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
353
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
354 char[] getTag(NodeCategory nc)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
355 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
356 char[] tag;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
357 switch (nc)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
358 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
359 alias NodeCategory NC;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
360 case NC.Declaration: tag = "d"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
361 case NC.Statement: tag = "s"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
362 case NC.Expression: tag = "e"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
363 case NC.Type: tag = "t"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
364 case NC.Other: tag = "o"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
365 default:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
366 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
367 return tag;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
368 }
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 // Traverse linked list and print tokens.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
371 while (token.type != TOK.EOF)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
372 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
373 token = token.next;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
374
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
375 // Print whitespace between previous and current token.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
376 if (end != token.start)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
377 writef("%s", end[0 .. token.start - end]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
378
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
379 Node[]* nodes = token in beginNodes;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
380
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
381 if (nodes)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
382 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
383 foreach (node; *nodes)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
384 writef(tags[DocPart.SyntaxBegin], getTag(node.category), getShortClassName(node));
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
385 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
386
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
387 printToken(token, tags);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
388
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
389 nodes = token in endNodes;
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 if (nodes)
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 foreach_reverse (node; *nodes)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
394 if (options & DocOption.HTML)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
395 writef(tags[DocPart.SyntaxEnd]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
396 else
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
397 writef(tags[DocPart.SyntaxEnd], getTag(node.category));
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
398 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
399
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
400 end = token.end;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
401 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
402 writef(tags[DocPart.SrcEnd], tags[DocPart.Tail]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
403 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
404
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
405 void tokensToDoc(string fileName, DocOption options)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
406 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
407 auto tags = options & DocOption.HTML ? html_tags : xml_tags;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
408 auto sourceText = cast(char[]) std.file.read(fileName);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
409 auto lx = new Lexer(sourceText, fileName);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
410
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
411 auto token = lx.getTokens();
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
412 char* end = lx.text.ptr;
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
413
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
414 writefln(tags[DocPart.Head]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
415
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
416 if (lx.errors.length)
51
cadd2bfe686c - Displaying error messages in XML.
aziz
parents: 44
diff changeset
417 {
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
418 writefln(tags[DocPart.CompBegin]);
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
419 foreach (error; lx.errors)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
420 {
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
421 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
422 }
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
423 writefln(tags[DocPart.CompEnd]);
51
cadd2bfe686c - Displaying error messages in XML.
aziz
parents: 44
diff changeset
424 }
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
425 writef(tags[DocPart.SrcBegin]);
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
426
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
427 // Traverse linked list and print tokens.
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
428 while (token.type != TOK.EOF)
4
92df59b1ec4a - Started implementation of scan().
aziz
parents: 3
diff changeset
429 {
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
430 token = token.next;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
431
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
432 // Print whitespace between previous and current token.
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
433 if (end != token.start)
328
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
434 writef("%s", end[0 .. token.start - end]);
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
435 printToken(token, tags);
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
436 end = token.end;
4
92df59b1ec4a - Started implementation of scan().
aziz
parents: 3
diff changeset
437 }
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
438 writef(\n, tags[DocPart.SrcEnd], \n, tags[DocPart.Tail]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
439 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
440
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
441 void printToken(Token* token, string[] tags)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
442 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
443 alias DocPart DP;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
444 string srcText = xml_escape(token.srcText);
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 switch(token.type)
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
447 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
448 case TOK.Identifier:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
449 writef(tags[DP.Identifier], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
450 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
451 case TOK.Comment:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
452 string t;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
453 switch (token.start[1])
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
454 {
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
455 case '/': t = "l"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
456 case '*': t = "b"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
457 case '+': t = "n"; break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
458 default:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
459 assert(0);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
460 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
461 writef(tags[DP.Comment], t, srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
462 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
463 case TOK.String:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
464 writef(tags[DP.StringLiteral], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
465 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
466 case TOK.CharLiteral, TOK.WCharLiteral, TOK.DCharLiteral:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
467 writef(tags[DP.CharLiteral], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
468 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
469 case TOK.Assign, TOK.Equal,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
470 TOK.Less, TOK.Greater,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
471 TOK.LShiftAssign, TOK.LShift,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
472 TOK.RShiftAssign, TOK.RShift,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
473 TOK.URShiftAssign, TOK.URShift,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
474 TOK.OrAssign, TOK.OrBinary,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
475 TOK.AndAssign, TOK.AndBinary,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
476 TOK.PlusAssign, TOK.PlusPlus, TOK.Plus,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
477 TOK.MinusAssign, TOK.MinusMinus, TOK.Minus,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
478 TOK.DivAssign, TOK.Div,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
479 TOK.MulAssign, TOK.Mul,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
480 TOK.ModAssign, TOK.Mod,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
481 TOK.XorAssign, TOK.Xor,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
482 TOK.CatAssign,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
483 TOK.Tilde,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
484 TOK.Unordered,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
485 TOK.UorE,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
486 TOK.UorG,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
487 TOK.UorGorE,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
488 TOK.UorL,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
489 TOK.UorLorE,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
490 TOK.LorEorG:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
491 writef(tags[DP.Operator], srcText);
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.LorG:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
494 writef(tags[DP.LorG]);
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.LessEqual:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
497 writef(tags[DP.LessEqual]);
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.GreaterEqual:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
500 writef(tags[DP.GreaterEqual]);
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.AndLogical:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
503 writef(tags[DP.AndLogical]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
504 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
505 case TOK.OrLogical:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
506 writef(tags[DP.OrLogical]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
507 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
508 case TOK.NotEqual:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
509 writef(tags[DP.NotEqual]);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
510 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
511 case TOK.Not:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
512 // Check if this is part of a template instantiation.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
513 // TODO: comments aren't skipped.
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
514 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
515 goto default;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
516 writef(tags[DP.Not]);
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.Int32, TOK.Int64, TOK.Uint32, TOK.Uint64,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
519 TOK.Float32, TOK.Float64, TOK.Float80,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
520 TOK.Imaginary32, TOK.Imaginary64, TOK.Imaginary80:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
521 writef(tags[DP.Number], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
522 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
523 case TOK.LParen, TOK.RParen, TOK.LBracket,
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
524 TOK.RBracket, TOK.LBrace, TOK.RBrace:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
525 writef(tags[DP.Bracket], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
526 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
527 case TOK.Special:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
528 writef(tags[DP.SpecialToken], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
529 break;
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
530 case TOK.Shebang:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
531 writef(tags[DP.Shebang], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
532 break;
323
6259fb93e3dd - Rewrote scanSpecialToken().
aziz
parents: 322
diff changeset
533 case TOK.HashLine:
328
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
534 void printWS(char* start, char* end)
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
535 {
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
536 if (start != end)
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
537 writef(start[0 .. end - start]);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
538 }
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
539 writef(tags[DP.HLineBegin]);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
540 auto num = token.line_num;
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
541 // Print whitespace between #line and number
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
542 auto ptr = token.start + "#line".length;
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
543 printWS(ptr, num.start);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
544 printToken(num, tags);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
545 if (token.line_filespec)
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
546 {
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
547 auto filespec = token.line_filespec;
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
548 // Print whitespace between number and filespec
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
549 printWS(num.end, filespec.start);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
550 writef(tags[DP.Filespec], xml_escape(filespec.srcText));
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
551
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
552 ptr = filespec.end;
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
553 }
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
554 else
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
555 ptr = num.end;
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
556 // Print remaining whitespace
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
557 printWS(ptr, token.end);
39f93a4ec416 - Added code for printing #line and filespec tokens.
aziz
parents: 327
diff changeset
558 writef(tags[DP.HLineEnd]);
323
6259fb93e3dd - Rewrote scanSpecialToken().
aziz
parents: 322
diff changeset
559 break;
322
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
560 default:
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
561 if (token.isKeyword())
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
562 writef(tags[DP.Keyword], srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
563 else
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
564 writef("%s", srcText);
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
565 }
ed4ef0173793 - Moved out large TOK switch case to function printToken().
aziz
parents: 315
diff changeset
566 }