Mercurial > projects > dil
annotate trunk/src/cmd/Generate.d @ 582:724603deed37
Added comments and renamed a few variables.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 05 Jan 2008 22:30:50 +0100 |
parents | 61f9784aaf2a |
children | 39fac5531b85 |
rev | line source |
---|---|
363 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL3 | |
4 +/ | |
5 module cmd.Generate; | |
578
c769bc239006
Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
576
diff
changeset
|
6 |
580
fa6d3c52757d
Moved SyntaxTree.d to new package 'ast'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
578
diff
changeset
|
7 import dil.ast.Node; |
363 | 8 import dil.Token; |
578
c769bc239006
Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
576
diff
changeset
|
9 import dil.parser.Parser; |
c769bc239006
Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
576
diff
changeset
|
10 import dil.lexer.Lexer; |
363 | 11 import dil.File; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
12 import tango.io.Print; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
13 import common; |
363 | 14 |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
15 /// Options for the generate command. |
363 | 16 enum DocOption |
17 { | |
392
bb935c6f9b7a
Applied fixes and improvements to the Lexer class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
18 Empty, |
bb935c6f9b7a
Applied fixes and improvements to the Lexer class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
19 Tokens = 1, |
363 | 20 Syntax = 1<<1, |
392
bb935c6f9b7a
Applied fixes and improvements to the Lexer class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
21 HTML = 1<<2, |
bb935c6f9b7a
Applied fixes and improvements to the Lexer class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
22 XML = 1<<3 |
363 | 23 } |
24 | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
25 /// Executes the command. |
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
26 void execute(string filePath, DocOption options) |
364 | 27 { |
392
bb935c6f9b7a
Applied fixes and improvements to the Lexer class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
28 assert(options != DocOption.Empty); |
364 | 29 if (options & DocOption.Syntax) |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
30 syntaxToDoc(filePath, Stdout, options); |
364 | 31 else |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
32 tokensToDoc(filePath, Stdout, options); |
364 | 33 } |
34 | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
35 /// Escapes the characters '<', '>' and '&' with named character entities. |
363 | 36 char[] xml_escape(char[] text) |
37 { | |
38 char[] result; | |
39 foreach(c; text) | |
40 switch(c) | |
41 { | |
42 case '<': result ~= "<"; break; | |
43 case '>': result ~= ">"; break; | |
44 case '&': result ~= "&"; break; | |
45 default: result ~= c; | |
46 } | |
47 return result; | |
48 } | |
49 | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
50 |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
51 /// Find object in subject and return position. |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
52 /// Returns -1 if no match was found. |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
53 /+int find(char[] subject, char[] object) |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
54 { |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
55 if (object.length > subject.length) |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
56 return -1; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
57 foreach (i, c; subject) |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
58 { |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
59 if (c == object[0]) |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
60 { |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
61 if (object.length > (subject.length - i)) |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
62 return -1; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
63 if (object == subject[i..i+object.length]) |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
64 return i; |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
65 } |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
66 } |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
67 return -1; |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
68 }+/ |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
69 |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
70 /++ |
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
71 Find the last occurrence of object in subject. |
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
72 Returns the index if found, or -1 if not. |
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
73 +/ |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
74 int rfind(char[] subject, char object) |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
75 { |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
76 foreach_reverse(i, c; subject) |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
77 if (c == object) |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
78 return i; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
79 return -1; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
80 } |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
81 |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
82 /// Returns the short class name of an instance descending from Node. |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
83 char[] getShortClassName(Node node) |
363 | 84 { |
85 static char[][] name_table; | |
86 if (name_table is null) | |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
87 name_table = new char[][NodeKind.max+1]; // Create a new table. |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
88 // Look up in table. |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
89 char[] name = name_table[node.kind]; |
363 | 90 if (name !is null) |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
91 return name; // Return cached name. |
363 | 92 |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
93 name = node.classinfo.name; // Get the fully qualified name of the class. |
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
94 name = name[rfind(name, '.')+1 .. $]; // Remove package and module name. |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
95 |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
96 uint suffixLength; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
97 switch (node.category) |
363 | 98 { |
99 alias NodeCategory NC; | |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
100 case NC.Declaration: |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
101 if (node.kind == NodeKind.Declarations) |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
102 break; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
103 suffixLength = "Declaration".length; |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
104 break; |
363 | 105 case NC.Statement: |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
106 if (node.kind == NodeKind.Statements) |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
107 break; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
108 suffixLength = "Statement".length; |
363 | 109 break; |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
110 case NC.Expression: |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
111 suffixLength = "Expression".length; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
112 break; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
113 case NC.Type: |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
114 suffixLength = "Type".length; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
115 break; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
116 case NC.Other: |
363 | 117 default: |
118 } | |
119 // Remove common suffix. | |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
120 name = name[0 .. $ - suffixLength]; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
121 // Store the name in the table. |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
122 name_table[node.kind] = name; |
363 | 123 return name; |
124 } | |
125 | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
126 /// Indices into the XML and HTML tag arrays. |
363 | 127 enum DocPart |
128 { | |
129 Head, | |
130 CompBegin, | |
131 CompEnd, | |
132 Error, | |
133 SyntaxBegin, | |
134 SyntaxEnd, | |
135 SrcBegin, | |
136 SrcEnd, | |
137 Tail, | |
138 // Tokens: | |
139 Identifier, | |
140 Comment, | |
141 StringLiteral, | |
142 CharLiteral, | |
143 Operator, | |
144 LorG, | |
145 LessEqual, | |
146 GreaterEqual, | |
147 AndLogical, | |
148 OrLogical, | |
149 NotEqual, | |
150 Not, | |
151 Number, | |
152 Bracket, | |
153 SpecialToken, | |
154 Shebang, | |
155 Keyword, | |
156 HLineBegin, | |
157 HLineEnd, | |
158 Filespec, | |
159 } | |
160 | |
161 auto html_tags = [ | |
162 // Head | |
163 `<html>`\n | |
164 `<head>`\n | |
165 `<meta http-equiv="Content-Type" content="text/html; charset=utf-8">`\n | |
166 `<link href="dil_html.css" rel="stylesheet" type="text/css">`\n | |
167 `</head>`\n | |
168 `<body>`[], | |
169 // CompBegin | |
170 `<div class="compilerinfo">`, | |
171 // CompEnd | |
172 `</div>`, | |
173 // Error | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
174 `<p class="error {0}">{1}({2}){3}: {4}</p>`, |
363 | 175 // SyntaxBegin |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
176 `<span class="{0} {1}">`, |
363 | 177 // SyntaxEnd |
178 `</span>`, | |
179 // SrcBegin | |
180 `<pre class="sourcecode">`, | |
181 // SrcEnd | |
182 `</pre>`, | |
183 // Tail | |
184 `</html>`, | |
185 // Identifier | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
186 `<span class="i">{0}</span>`, |
363 | 187 // Comment |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
188 `<span class="c{0}">{1}</span>`, |
363 | 189 // StringLiteral |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
190 `<span class="sl">{0}</span>`, |
363 | 191 // CharLiteral |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
192 `<span class="cl">{0}</span>`, |
363 | 193 // Operator |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
194 `<span class="op">{0}</span>`, |
363 | 195 // LorG |
196 `<span class="oplg"><></span>`, | |
197 // LessEqual | |
198 `<span class="ople"><=</span>`, | |
199 // GreaterEqual | |
200 `<span class="opge">>=</span>`, | |
201 // AndLogical | |
202 `<span class="opaa">&&</span>`, | |
203 // OrLogical | |
204 `<span class="opoo">||</span>`, | |
205 // NotEqual | |
206 `<span class="opne">!=</span>`, | |
207 // Not | |
208 `<span class="opn">!</span>`, | |
209 // Number | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
210 `<span class="n">{0}</span>`, |
363 | 211 // Bracket |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
212 `<span class="br">{0}</span>`, |
363 | 213 // SpecialToken |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
214 `<span class="st">{0}</span>`, |
363 | 215 // Shebang |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
216 `<span class="shebang">{0}</span>`, |
363 | 217 // Keyword |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
218 `<span class="k">{0}</span>`, |
363 | 219 // HLineBegin |
388
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
220 `<span class="hl">`, |
363 | 221 // HLineEnd |
222 "</span>", | |
223 // Filespec | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
224 `<span class="fs">{0}</span>`, |
363 | 225 ]; |
226 | |
227 auto xml_tags = [ | |
228 // Head | |
229 `<?xml version="1.0"?>`\n | |
230 `<?xml-stylesheet href="dil_xml.css" type="text/css"?>`\n | |
231 `<root>`[], | |
232 // CompBegin | |
233 `<compilerinfo>`, | |
234 // CompEnd | |
235 `</compilerinfo>`, | |
236 // Error | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
237 `<error t="{0}">{1}({2}){3}: {4}</error>`, |
363 | 238 // SyntaxBegin |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
239 `<{0} t="{1}">`, |
363 | 240 // SyntaxEnd |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
241 `</{0}>`, |
363 | 242 // SrcBegin |
243 `<sourcecode>`, | |
244 // SrcEnd | |
245 `</sourcecode>`, | |
246 // Tail | |
247 `</root>`, | |
248 // Identifier | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
249 "<i>{0}</i>", |
363 | 250 // Comment |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
251 `<c t="{0}">{1}</c>`, |
363 | 252 // StringLiteral |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
253 "<sl>{0}</sl>", |
363 | 254 // CharLiteral |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
255 "<cl>{0}</cl>", |
363 | 256 // Operator |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
257 "<op>{0}</op>", |
363 | 258 // LorG |
259 `<op t="lg"><></op>`, | |
260 // LessEqual | |
261 `<op t="le"><=</op>`, | |
262 // GreaterEqual | |
263 `<op t="ge">>=</op>`, | |
264 // AndLogical | |
265 `<op t="aa">&&</op>`, | |
266 // OrLogical | |
267 `<op t="oo">||</op>`, | |
268 // NotEqual | |
269 `<op t="ne">!=</op>`, | |
270 // Not | |
271 `<op t="n">!</op>`, | |
272 // Number | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
273 "<n>{0}</n>", |
363 | 274 // Bracket |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
275 "<br>{0}</br>", |
363 | 276 // SpecialToken |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
277 "<st>{0}</st>", |
363 | 278 // Shebang |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
279 "<shebang>{0}</shebang>", |
363 | 280 // Keyword |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
281 "<k>{0}</k>", |
363 | 282 // HLineBegin |
388
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
283 "<hl>", |
363 | 284 // HLineEnd |
285 "</hl>", | |
286 // Filespec | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
287 "<fs>{0}</fs>", |
363 | 288 ]; |
289 | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
290 // The size of the arrays must equal the number of members in enum DocPart. |
363 | 291 static assert(html_tags.length == DocPart.max+1); |
292 static assert(xml_tags.length == DocPart.max+1); | |
293 | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
294 /// Prints the syntax tree of a source file using the buffer print. |
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
295 void syntaxToDoc(string filePath, Print!(char) print, DocOption options) |
363 | 296 { |
297 auto tags = options & DocOption.HTML ? html_tags : xml_tags; | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
298 auto sourceText = loadFile(filePath); |
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
299 auto parser = new Parser(sourceText, filePath); |
368 | 300 auto root = parser.start(); |
363 | 301 auto lx = parser.lx; |
302 | |
303 auto token = lx.head; | |
304 | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
305 print(tags[DocPart.Head]~\n); |
363 | 306 // Output error messages. |
307 if (lx.errors.length || parser.errors.length) | |
308 { | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
309 print(tags[DocPart.CompBegin]~\n); |
363 | 310 foreach (error; lx.errors) |
311 { | |
422
ad7977fe315a
Added support for column numbers in error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
312 print.formatln(tags[DocPart.Error], "L", error.filePath, Format("{0},{1}", error.loc, error.col), "L", xml_escape(error.getMsg)); |
363 | 313 } |
314 foreach (error; parser.errors) | |
315 { | |
422
ad7977fe315a
Added support for column numbers in error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
316 print.formatln(tags[DocPart.Error], "P", error.filePath, Format("{0},{1}", error.loc, error.col), "P", xml_escape(error.getMsg)); |
363 | 317 } |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
318 print(tags[DocPart.CompEnd]~\n); |
363 | 319 } |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
320 print(tags[DocPart.SrcBegin]); |
363 | 321 |
322 Node[][Token*] beginNodes, endNodes; | |
323 | |
324 void populateAAs(Node[] nodes) | |
325 { | |
326 foreach (node; nodes) | |
327 { | |
396
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
328 assert(delegate bool(){ |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
329 foreach (child; node.children) |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
330 if (child is null) |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
331 return false; |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
332 return true; |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
333 }() == true, Format("Node '{0}' has a null child", node.classinfo.name) |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
334 ); |
363 | 335 auto begin = node.begin; |
336 if (begin) | |
337 { | |
338 auto end = node.end; | |
339 assert(end); | |
340 beginNodes[begin] ~= node; | |
341 endNodes[end] ~= node; | |
342 } | |
396
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
343 |
363 | 344 if (node.children.length) |
345 populateAAs(node.children); | |
346 } | |
347 } | |
396
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
348 assert(delegate bool(){ |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
349 foreach (child; root.children) |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
350 if (child is null) |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
351 return false; |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
352 return true; |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
353 }() == true, Format("Root node has a null child") |
0a4619735ce9
Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
394
diff
changeset
|
354 ); |
363 | 355 populateAAs(root.children); |
356 | |
357 char[] getTag(NodeCategory nc) | |
358 { | |
359 char[] tag; | |
360 switch (nc) | |
361 { | |
362 alias NodeCategory NC; | |
363 case NC.Declaration: tag = "d"; break; | |
364 case NC.Statement: tag = "s"; break; | |
365 case NC.Expression: tag = "e"; break; | |
366 case NC.Type: tag = "t"; break; | |
367 case NC.Other: tag = "o"; break; | |
368 default: | |
369 } | |
370 return tag; | |
371 } | |
372 | |
373 // Traverse linked list and print tokens. | |
374 while (token.type != TOK.EOF) | |
375 { | |
376 token = token.next; | |
377 | |
394
6440da4adb07
Fixed forward references of enum MID complaints by compiler.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
392
diff
changeset
|
378 // Print whitespace. |
6440da4adb07
Fixed forward references of enum MID complaints by compiler.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
392
diff
changeset
|
379 if (token.ws) |
6440da4adb07
Fixed forward references of enum MID complaints by compiler.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
392
diff
changeset
|
380 print(token.ws[0..token.start - token.ws]); |
6440da4adb07
Fixed forward references of enum MID complaints by compiler.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
392
diff
changeset
|
381 |
363 | 382 Node[]* nodes = token in beginNodes; |
383 | |
384 if (nodes) | |
385 { | |
386 foreach (node; *nodes) | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
387 print.format(tags[DocPart.SyntaxBegin], getTag(node.category), getShortClassName(node)); |
363 | 388 } |
389 | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
390 printToken(token, tags, print); |
363 | 391 |
392 nodes = token in endNodes; | |
393 | |
394 if (nodes) | |
395 { | |
396 foreach_reverse (node; *nodes) | |
397 if (options & DocOption.HTML) | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
398 print(tags[DocPart.SyntaxEnd]); |
363 | 399 else |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
400 print.format(tags[DocPart.SyntaxEnd], getTag(node.category)); |
363 | 401 } |
402 } | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
403 print(\n~tags[DocPart.SrcEnd])(\n~tags[DocPart.Tail]); |
363 | 404 } |
405 | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
406 /// Prints all tokens of a source file using the buffer print. |
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
407 void tokensToDoc(string filePath, Print!(char) print, DocOption options) |
363 | 408 { |
409 auto tags = options & DocOption.HTML ? html_tags : xml_tags; | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
410 auto sourceText = loadFile(filePath); |
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
411 auto lx = new Lexer(sourceText, filePath); |
363 | 412 |
413 auto token = lx.getTokens(); | |
414 | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
415 print(tags[DocPart.Head]~\n); |
363 | 416 |
417 if (lx.errors.length) | |
418 { | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
419 print(tags[DocPart.CompBegin]~\n); |
363 | 420 foreach (error; lx.errors) |
421 { | |
422
ad7977fe315a
Added support for column numbers in error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
396
diff
changeset
|
422 print.formatln(tags[DocPart.Error], "L", error.filePath, Format("{0},{1}", error.loc, error.col), "L", xml_escape(error.getMsg)); |
363 | 423 } |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
424 print(tags[DocPart.CompEnd]~\n); |
363 | 425 } |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
426 print(tags[DocPart.SrcBegin]); |
363 | 427 |
428 // Traverse linked list and print tokens. | |
429 while (token.type != TOK.EOF) | |
430 { | |
431 token = token.next; | |
394
6440da4adb07
Fixed forward references of enum MID complaints by compiler.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
392
diff
changeset
|
432 // Print whitespace. |
6440da4adb07
Fixed forward references of enum MID complaints by compiler.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
392
diff
changeset
|
433 if (token.ws) |
6440da4adb07
Fixed forward references of enum MID complaints by compiler.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
392
diff
changeset
|
434 print(token.ws[0..token.start - token.ws]); |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
435 printToken(token, tags, print); |
363 | 436 } |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
437 print(\n~tags[DocPart.SrcEnd])(\n~tags[DocPart.Tail]); |
363 | 438 } |
439 | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
440 /// Prints a token with tags using the buffer print. |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
441 void printToken(Token* token, string[] tags, Print!(char) print) |
363 | 442 { |
443 alias DocPart DP; | |
444 string srcText = xml_escape(token.srcText); | |
445 | |
446 switch(token.type) | |
447 { | |
448 case TOK.Identifier: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
449 print.format(tags[DP.Identifier], srcText); |
363 | 450 break; |
451 case TOK.Comment: | |
452 string t; | |
453 switch (token.start[1]) | |
454 { | |
455 case '/': t = "l"; break; | |
456 case '*': t = "b"; break; | |
457 case '+': t = "n"; break; | |
458 default: | |
459 assert(0); | |
460 } | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
461 print.format(tags[DP.Comment], t, srcText); |
363 | 462 break; |
463 case TOK.String: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
464 print.format(tags[DP.StringLiteral], srcText); |
363 | 465 break; |
507
996041463028
Removed TOK.WCharLiteral and TOK.DCharLiteral.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
466 case TOK.CharLiteral: |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
467 print.format(tags[DP.CharLiteral], srcText); |
363 | 468 break; |
469 case TOK.Assign, TOK.Equal, | |
470 TOK.Less, TOK.Greater, | |
471 TOK.LShiftAssign, TOK.LShift, | |
472 TOK.RShiftAssign, TOK.RShift, | |
473 TOK.URShiftAssign, TOK.URShift, | |
474 TOK.OrAssign, TOK.OrBinary, | |
475 TOK.AndAssign, TOK.AndBinary, | |
476 TOK.PlusAssign, TOK.PlusPlus, TOK.Plus, | |
477 TOK.MinusAssign, TOK.MinusMinus, TOK.Minus, | |
478 TOK.DivAssign, TOK.Div, | |
479 TOK.MulAssign, TOK.Mul, | |
480 TOK.ModAssign, TOK.Mod, | |
481 TOK.XorAssign, TOK.Xor, | |
482 TOK.CatAssign, | |
483 TOK.Tilde, | |
484 TOK.Unordered, | |
485 TOK.UorE, | |
486 TOK.UorG, | |
487 TOK.UorGorE, | |
488 TOK.UorL, | |
489 TOK.UorLorE, | |
490 TOK.LorEorG: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
491 print.format(tags[DP.Operator], srcText); |
363 | 492 break; |
493 case TOK.LorG: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
494 print(tags[DP.LorG]); |
363 | 495 break; |
496 case TOK.LessEqual: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
497 print(tags[DP.LessEqual]); |
363 | 498 break; |
499 case TOK.GreaterEqual: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
500 print(tags[DP.GreaterEqual]); |
363 | 501 break; |
502 case TOK.AndLogical: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
503 print(tags[DP.AndLogical]); |
363 | 504 break; |
505 case TOK.OrLogical: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
506 print(tags[DP.OrLogical]); |
363 | 507 break; |
508 case TOK.NotEqual: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
509 print(tags[DP.NotEqual]); |
363 | 510 break; |
511 case TOK.Not: | |
512 // Check if this is part of a template instantiation. | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
513 // TODO: comments aren't skipped. Use Token.nextNWS and Token.prevNWS |
363 | 514 if (token.prev.type == TOK.Identifier && token.next.type == TOK.LParen) |
515 goto default; | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
516 print(tags[DP.Not]); |
363 | 517 break; |
518 case TOK.Int32, TOK.Int64, TOK.Uint32, TOK.Uint64, | |
519 TOK.Float32, TOK.Float64, TOK.Float80, | |
520 TOK.Imaginary32, TOK.Imaginary64, TOK.Imaginary80: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
521 print.format(tags[DP.Number], srcText); |
363 | 522 break; |
523 case TOK.LParen, TOK.RParen, TOK.LBracket, | |
524 TOK.RBracket, TOK.LBrace, TOK.RBrace: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
525 print.format(tags[DP.Bracket], srcText); |
363 | 526 break; |
527 case TOK.Shebang: | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
528 print.format(tags[DP.Shebang], srcText); |
363 | 529 break; |
530 case TOK.HashLine: | |
531 void printWS(char* start, char* end) | |
532 { | |
533 if (start != end) | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
534 print(start[0 .. end - start]); |
363 | 535 } |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
536 print(tags[DP.HLineBegin]); |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
537 auto num = token.tokLineNum; |
388
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
538 if (num is null) |
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
539 { |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
540 print(token.srcText); |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
541 print(tags[DP.HLineEnd]); |
388
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
542 break; |
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
543 } |
363 | 544 // Print whitespace between #line and number |
388
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
545 auto ptr = token.start; |
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
546 printWS(ptr, num.start); // prints "#line" as well |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
547 printToken(num, tags, print); |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
548 if (token.tokLineFilespec) |
363 | 549 { |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
550 auto filespec = token.tokLineFilespec; |
363 | 551 // Print whitespace between number and filespec |
552 printWS(num.end, filespec.start); | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
553 print.format(tags[DP.Filespec], xml_escape(filespec.srcText)); |
363 | 554 |
555 ptr = filespec.end; | |
556 } | |
557 else | |
558 ptr = num.end; | |
559 // Print remaining whitespace | |
560 printWS(ptr, token.end); | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
561 print(tags[DP.HLineEnd]); |
363 | 562 break; |
563 default: | |
564 if (token.isKeyword()) | |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
565 print.format(tags[DP.Keyword], srcText); |
363 | 566 else if (token.isSpecialToken) |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
567 print.format(tags[DP.SpecialToken], srcText); |
363 | 568 else |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
569 print(srcText); |
363 | 570 } |
571 } |