# HG changeset patch # User Aziz K?ksal # Date 1190977731 -7200 # Node ID ce644d724d87ececc9f857aecd45375dc7f2cd55 # Parent 89e40d43065db3a7b4fa0838a95c6e490d5ff5cc Made Location a class and extended it with new members. diff -r 89e40d43065d -r ce644d724d87 trunk/src/dil/Lexer.d --- a/trunk/src/dil/Lexer.d Fri Sep 28 12:10:11 2007 +0200 +++ b/trunk/src/dil/Lexer.d Fri Sep 28 13:08:51 2007 +0200 @@ -26,17 +26,50 @@ const uint _Z_ = 26; /// Control+Z -struct Location +final class Location { size_t lineNum; char* filePath; + char* from, to; // Used to calculate column. - static Location opCall(size_t lineNum, typeof(filePath) filePath) + this(size_t lineNum, char* filePath) + { + this(lineNum, filePath, null, null); + } + + this(size_t lineNum, char* filePath, char* from, char* to) + { + assert(from <= to); + this.lineNum = lineNum; + this.filePath = filePath; + this.from = from; + this.to = to; + } + + uint getColumn() { - Location l; - l.lineNum = lineNum; - l.filePath = filePath; - return l; + uint col = 1; + auto p = from; + for (; p <= to; ++p) + { + assert(*p != '\n' && *p != '\r'); + if (*p & 128) + { + size_t idx; + dchar d; + try + { + d = std.utf.decode(p[0 .. to-p], idx); + assert(d != LSd && d != PSd); + p += idx -1; + } + catch (UtfException e) + { } + } + + ++col; + } + return col; } } @@ -93,7 +126,7 @@ // Add first token to table. auto firstToken = this.head; peek(firstToken); - token2LocTable[firstToken] = Location(1, null); + token2LocTable[firstToken] = new Location(1, null); } } @@ -248,7 +281,7 @@ t.ws = pws; if (old_loc != this.loc) version(token2LocTable) - token2LocTable[&t] = Location(loc, null); + token2LocTable[&t] = new Location(loc, null); } // Scan token. @@ -729,7 +762,7 @@ t.ws = pws; if (old_loc != this.loc) version(token2LocTable) - token2LocTable[&t] = Location(loc, null); + token2LocTable[&t] = new Location(loc, null); } // Scan token.