# HG changeset patch # User Aziz K?ksal # Date 1197208718 -3600 # Node ID 0ffcc4ff82f3029e458b2a1ba28f3cb3d07369c1 # Parent 5a607597dc225f87f67b85ed72c8f23584678113 Refactored a few things in the Lexer. Fix: SpecialTokensEnd should be TOK.VERSION not TOK.Version. Fixed assert statement in textSpan(). diff -r 5a607597dc22 -r 0ffcc4ff82f3 trunk/src/dil/Keywords.d --- a/trunk/src/dil/Keywords.d Sun Dec 09 13:04:15 2007 +0100 +++ b/trunk/src/dil/Keywords.d Sun Dec 09 14:58:38 2007 +0100 @@ -6,6 +6,7 @@ import dil.Token; import dil.Identifier; +/// Table of reserved identifiers. static const Identifier[] keywords = [ {TOK.Abstract, "abstract"}, {TOK.Alias, "alias"}, diff -r 5a607597dc22 -r 0ffcc4ff82f3 trunk/src/dil/Lexer.d --- a/trunk/src/dil/Lexer.d Sun Dec 09 13:04:15 2007 +0100 +++ b/trunk/src/dil/Lexer.d Sun Dec 09 14:58:38 2007 +0100 @@ -297,17 +297,17 @@ } assert(id); t.type = id.type; - if (t.type == TOK.Identifier) + if (t.type == TOK.Identifier || t.isKeyword) return; - if (t.type == TOK.EOF) + else if (t.isSpecialToken) + finalizeSpecialToken(t); + else if (t.type == TOK.EOF) { - t.type = TOK.EOF; - t.end = p; tail = &t; assert(t.srcText == "__EOF__"); } - else if (t.isSpecialToken) - finalizeSpecialToken(t); + else + assert(0, "unexpected token: " ~ t.srcText); return; } @@ -610,9 +610,9 @@ } // Check for EOF - if (c == 0 || c == _Z_) + if (isEOF(c)) { - assert(*p == 0 || *p == _Z_); + assert(isEOF(*p), ""~*p); t.type = TOK.EOF; t.end = p; tail = &t; @@ -1049,17 +1049,17 @@ } assert(id); t.type = id.type; - if (t.type == TOK.Identifier) + if (t.type == TOK.Identifier || t.isKeyword) return; - if (t.type == TOK.EOF) + else if (t.isSpecialToken) + finalizeSpecialToken(t); + else if (t.type == TOK.EOF) { - t.type = TOK.EOF; - t.end = p; tail = &t; assert(t.srcText == "__EOF__"); } - else if (t.isSpecialToken) - finalizeSpecialToken(t); + else + assert(0, "unexpected token: " ~ t.srcText); return; } @@ -1067,9 +1067,9 @@ return scanNumber(t); // Check for EOF - if (c == 0 || c == _Z_) + if (isEOF(c)) { - assert(*p == 0 || *p == _Z_, *p~""); + assert(isEOF(*p), *p~""); t.type = TOK.EOF; t.end = p; tail = &t; diff -r 5a607597dc22 -r 0ffcc4ff82f3 trunk/src/dil/Token.d --- a/trunk/src/dil/Token.d Sun Dec 09 13:04:15 2007 +0100 +++ b/trunk/src/dil/Token.d Sun Dec 09 14:58:38 2007 +0100 @@ -113,7 +113,7 @@ alias TOK.Abstract KeywordsBegin; alias TOK.With KeywordsEnd; alias TOK.FILE SpecialTokensBegin; -alias TOK.Version SpecialTokensEnd; +alias TOK.VERSION SpecialTokensEnd; struct Token { @@ -330,7 +330,7 @@ /// Return the source text enclosed by the left and right token. static char[] textSpan(Token* left, Token* right) { - assert(left.end <= right.start); + assert(left.end <= right.start || left is right ); return left.start[0 .. right.end - left.start]; }