diff trunk/src/Token.d @ 28:3a9daccf7d96

- Added table for identifiers to Lexer. - Added keywords table. - Added keywords to TOK.
author aziz
date Sun, 24 Jun 2007 17:19:03 +0000
parents 43b6bf56f0e9
children ef83eea26bbd
line wrap: on
line diff
--- a/trunk/src/Token.d	Sun Jun 24 15:02:02 2007 +0000
+++ b/trunk/src/Token.d	Sun Jun 24 17:19:03 2007 +0000
@@ -42,9 +42,30 @@
   Comma,
   Dollar,
 
+  /* Keywords:
+     NB.: Token.isKeyword() depends on this list being contiguous.
+  */
+  Abstract,Alias,Align,Asm,Assert,Auto,Body,
+  Bool,Break,Byte,Case,Cast,Catch,Cdouble,
+  Cent,Cfloat,Char,Class,Const,Continue,Creal,
+  Dchar,Debug,Default,Delegate,Delete,Deprecated,Do,
+  Double,Else,Enum,Export,Extern,False,Final,
+  Finally,Float,For,Foreach,Foreach_reverse,Function,Goto,
+  Idouble,If,Ifloat,Import,In,Inout,Int,
+  Interface,Invariant,Ireal,Is,Lazy,Long,Macro,
+  Mixin,Module,New,Null,Out,Override,Package,
+  Pragma,Private,Protected,Public,Real,Ref,Return,
+  Scope,Short,Static,Struct,Super,Switch,Synchronized,
+  Template,This,Throw,True,Try,Typedef,Typeid,
+  Typeof,Ubyte,Ucent,Uint,Ulong,Union,Unittest,
+  Ushort,Version,Void,Volatile,Wchar,While,With,
+
   EOF
 }
 
+alias TOK.Abstract KeywordsBegin;
+alias TOK.With KeywordsEnd;
+
 struct Token
 {
   TOK type;
@@ -60,4 +81,16 @@
     float f;
     double d;
   }
+
+  string span()
+  {
+    return start[0 .. end - start];
+  }
+
+  bool isKeyword()
+  {
+    if (KeywordsBegin <= type && type <= KeywordsEnd)
+      return true;
+    return false;
+  }
 }
\ No newline at end of file