changeset 781:d887184efb3c

Improved class TagMap.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Thu, 21 Feb 2008 00:19:15 +0100
parents edd217e14736
children c4b28cf38760
files trunk/src/cmd/Generate.d trunk/src/dil/lexer/TokensEnum.d
diffstat 2 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/cmd/Generate.d	Wed Feb 20 23:13:56 2008 +0100
+++ b/trunk/src/cmd/Generate.d	Thu Feb 21 00:19:15 2008 +0100
@@ -73,6 +73,7 @@
 class TagMap
 {
   string[string] table;
+  string[TOK.MAX] tokenTable;
 
   this(string[string] table)
   {
@@ -97,6 +98,10 @@
     Type         = this["Type", "t"];
     Other        = this["Other", "o"];
     EOF          = this["EOF", ""];
+
+    foreach (i, tokStr; tokToString)
+      if (auto pStr = tokStr in this.table)
+        tokenTable[i] = *pStr;
   }
 
   string opIndex(string str, string fallback = "")
@@ -107,6 +112,11 @@
     return fallback;
   }
 
+  string opIndex(TOK tok)
+  {
+    return tokenTable[tok];
+  }
+
   string Identifier, String, Char, Number, Keyword, LineC, BlockC,
          NestedC, Shebang, HLine, Filespec, Illegal, Newline, SpecialToken,
          Declaration, Statement, Expression, Type, Other, EOF;
@@ -464,6 +474,6 @@
     else if (token.isSpecialToken)
       print.format(tags.SpecialToken, token.srcText);
     else
-      print(tags[token.srcText]);
+      print(tags[token.kind]);
   }
 }
--- a/trunk/src/dil/lexer/TokensEnum.d	Wed Feb 20 23:13:56 2008 +0100
+++ b/trunk/src/dil/lexer/TokensEnum.d	Thu Feb 21 00:19:15 2008 +0100
@@ -121,7 +121,7 @@
 alias TOK.VERSION SpecialTokensEnd;
 
 /// A table mapping each TOK to a string.
-const string[] tokToString = [
+const string[TOK.MAX] tokToString = [
   "Invalid",
 
   "Illegal",