# HG changeset patch # User Aziz K?ksal # Date 1190731467 -7200 # Node ID fb31af0fda738b4cb0f33c2bec59e40cc54370f4 # Parent cca83c0c00fd8592ce5f0b82430712a28446582b Added struct Location, and token2LocTable to Lexer. The token2LocTable member could be used to give the column of where a parser or lexer error occurred. And maybe it could be useful for statistics, too. diff -r cca83c0c00fd -r fb31af0fda73 trunk/src/dil/Lexer.d --- a/trunk/src/dil/Lexer.d Tue Sep 25 15:04:41 2007 +0200 +++ b/trunk/src/dil/Lexer.d Tue Sep 25 16:44:27 2007 +0200 @@ -26,6 +26,20 @@ const uint _Z_ = 26; /// Control+Z +struct Location +{ + size_t lineNum; + char* filePath; + + static Location opCall(size_t lineNum, typeof(filePath) filePath) + { + Location l; + l.lineNum = lineNum; + l.filePath = filePath; + return l; + } +} + class Lexer { Token* head; /// The head of the doubly linked token list. @@ -49,6 +63,10 @@ Identifier[string] idtable; + version(token2LocTable) + /// Maps every token that starts a new line to a Location. + Location[Token*] token2LocTable; + this(string text, string fileName) { this.fileName = fileName; @@ -69,6 +87,13 @@ this.head.type = TOK.HEAD; this.token = this.head; scanShebang(); + version(token2LocTable) + { + // Add first token to table. + auto firstToken = this.head; + peek(firstToken); + token2LocTable[firstToken] = Location(1, null); + } } ~this() @@ -184,13 +209,14 @@ case '\n': ++p; ++loc; + version(token2LocTable) + token2LocTable[&t] = Location(loc, null); continue; case LS[0]: if (p[1] == LS[1] && (p[2] == LS[2] || p[2] == PS[2])) { - p += 3; - ++loc; - continue; + ++p; ++p; + goto case '\n'; } // goto default; default: