diff trunk/src/dil/Token.d @ 359:511c14950cac

- Added messages MissingLinkageType and UnrecognizedLinkageType. - Changed enum Linkage into a class. - Added method parseLinkage() to Parser. - Added MAX to enum TOK. - Added methods nextNWS() and prevNWS() to Token. - Fixed tokToString table.
author aziz
date Tue, 28 Aug 2007 11:41:00 +0000
parents 95f1b6e43214
children eb08126cca56
line wrap: on
line diff
--- a/trunk/src/dil/Token.d	Sun Aug 26 15:59:02 2007 +0000
+++ b/trunk/src/dil/Token.d	Tue Aug 28 11:41:00 2007 +0000
@@ -36,7 +36,7 @@
   VENDOR,
   VERSION,
 
-  // Numbers
+  // Number literals
   Int32, Int64, Uint32, Uint64,
   // Floating point number scanner relies on this order. (FloatXY + 3 == ImaginaryXY)
   Float32, Float64, Float80,
@@ -107,7 +107,8 @@
   Ushort,Version,Void,Volatile,Wchar,While,With,
 
   HEAD, // start of linked list
-  EOF
+  EOF,
+  MAX
 }
 
 alias TOK.Abstract KeywordsBegin;
@@ -153,6 +154,38 @@
     return start[0 .. end - start];
   }
 
+  /// Find next non-whitespace token. Returns 'this' token if the next token is TOK.EOF or null.
+  Token* nextNWS()
+  out(token)
+  {
+    assert(token !is null);
+  }
+  body
+  {
+    auto token = next;
+    while (token !is null && token.isWhitespace)
+      token = token.next;
+    if (token is null || token.type == TOK.EOF)
+      return this;
+    return token;
+  }
+
+  /// Find previous non-whitespace token. Returns 'this' token if the previous token is TOK.HEAD or null.
+  Token* prevNWS()
+  out(token)
+  {
+    assert(token !is null);
+  }
+  body
+  {
+    auto token = prev;
+    while (token !is null && token.isWhitespace)
+      token = token.prev;
+    if (token is null || token.type == TOK.HEAD)
+      return this;
+    return token;
+  }
+
   static string toString(TOK tok)
   {
     return tokToString[tok];
@@ -193,18 +226,26 @@
   }
 }
 
-string[] tokToString = [
+const string[] tokToString = [
   "Invalid",
 
   "Comment",
   "#! /shebang/",
   "#line",
+  `"filespec"`,
 
   "Identifier",
   "String",
-  "Special",
   "CharLiteral", "WCharLiteral", "DCharLiteral",
 
+  "__FILE__",
+  "__LINE__",
+  "__DATE__",
+  "__TIME__",
+  "__TIMESTAMP__",
+  "__VENDOR__",
+  "__VERSION__",
+
   "Int32", "Int64", "Uint32", "Uint64",
   "Float32", "Float64", "Float80",
   "Imaginary32", "Imaginary64", "Imaginary80",
@@ -262,9 +303,11 @@
   "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",
+  "template","this","throw","__traits","true","try","typedef","typeid",
   "typeof","ubyte","ucent","uint","ulong","union","unittest",
   "ushort","version","void","volatile","wchar","while","with",
 
+  "HEAD",
   "EOF"
 ];
+static assert(tokToString.length == TOK.MAX);
\ No newline at end of file