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