annotate trunk/src/main.d @ 328:39f93a4ec416

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