comparison trunk/src/dil/lexer/Token.d @ 675:e7811328e6c7

Made Token.getLocation() a template function and added two aliases.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 18 Jan 2008 18:18:14 +0100
parents c65b11c2074c
children ff6971637f88
comparison
equal deleted inserted replaced
674:6a934ff01b68 675:e7811328e6c7
191 { 191 {
192 return type == type2; 192 return type == type2;
193 } 193 }
194 194
195 /// Returns the Location of this token. 195 /// Returns the Location of this token.
196 Location getLocation() 196 Location getLocation(bool realLocation)()
197 { 197 {
198 auto search_t = this.prev; 198 auto search_t = this.prev;
199 // Find previous newline token. 199 // Find previous newline token.
200 while (search_t.type != TOK.Newline) 200 while (search_t.type != TOK.Newline)
201 search_t = search_t.prev; 201 search_t = search_t.prev;
202 auto filePath = search_t.newline.filePaths.setPath; 202 static if (realLocation)
203 auto lineNum = search_t.newline.oriLineNum - search_t.newline.setLineNum; 203 {
204 auto filePath = search_t.newline.filePaths.oriPath;
205 auto lineNum = search_t.newline.oriLineNum;
206 }
207 else
208 {
209 auto filePath = search_t.newline.filePaths.setPath;
210 auto lineNum = search_t.newline.oriLineNum - search_t.newline.setLineNum;
211 }
204 auto lineBegin = search_t.end; 212 auto lineBegin = search_t.end;
205 // Determine actual line begin and line number. 213 // Determine actual line begin and line number.
206 while (1) 214 while (1)
207 { 215 {
208 search_t = search_t.next; 216 search_t = search_t.next;
225 } 233 }
226 } 234 }
227 return new Location(filePath, lineNum, lineBegin, this.start); 235 return new Location(filePath, lineNum, lineBegin, this.start);
228 } 236 }
229 237
238 alias getLocation!(true) getRealLocation;
239 alias getLocation!(false) getErrorLocation;
240
230 uint lineCount() 241 uint lineCount()
231 { 242 {
232 uint count = 1; 243 uint count = 1;
233 if (this.isMultiline) 244 if (this.isMultiline)
234 { 245 {