diff src/lexer/Token.d @ 207:e0551773a005

Added the correct version.
author Anders Johnsen <skabet@gmail.com>
date Tue, 12 Aug 2008 18:19:34 +0200
parents d3c148ca429b
children
line wrap: on
line diff
--- a/src/lexer/Token.d	Tue Aug 12 18:14:56 2008 +0200
+++ b/src/lexer/Token.d	Tue Aug 12 18:19:34 2008 +0200
@@ -1,7 +1,8 @@
 module lexer.Token;
 
 public 
-import basic.SourceLocation;
+import basic.SourceLocation,
+       basic.SourceManager;
 
 import Integer = tango.text.convert.Integer;
 
@@ -34,8 +35,10 @@
     /**
       Get the type of the Token as a string
       */
-    char[] getType ()
+    char[] get (SourceManager sm)
     {
+        if (isIdentifier)
+            return sm.getText(asRange);
         return typeToString[this.type];
     }
 
@@ -44,7 +47,7 @@
       */
     char[] toString ()
     {
-        return this.getType()~": Len: "~Integer.toString(this.length);
+        return typeToString[this.type];
     }
 
     /// Get the range of this token
@@ -64,7 +67,63 @@
      */
     bool isAssignment()
     {
-        return type == Tok.Assign;
+        return type >= Tok.Assign && type <= Tok.PercentAssign;
+    }
+
+    /**
+      Returns true for all attributes( public, static, private...)
+     */
+    bool isAttribute()
+    {
+        return type >= Tok.Public && type <= Tok.Extern;
+    }
+
+    /**
+      Returns true for all attributes( public, static, private...)
+     */
+    bool isBaseClassProtection()
+    {
+        return type >= Tok.Public && type <= Tok.Export;
+    }
+
+    /**
+      just a shortcut to avoid `token.type == tok.Switch`.
+     */
+    bool isSwitch()
+    {
+        return type == Tok.Switch;
+    }
+
+    /**
+      just a shortcut to avoid `token.type == tok.While`.
+     */
+    bool isWhile()
+    {
+        return type == Tok.While;
+    }
+
+    /**
+      just a shortcut to avoid `token.type == tok.For`.
+     */
+    bool isFor()
+    {
+        return type == Tok.For;
+    }
+
+    /**
+      just a shortcut to avoid `token.type == tok.If`.
+     */
+    bool isIf()
+    {
+        return type == Tok.If;
+    }
+
+    /**
+      just a shortcut to avoid `token.type == tok.Return`.
+     */
+    bool isReturn()
+    {
+        return type == Tok.Return;
     }
 
     /**
@@ -90,12 +149,23 @@
     /* Basic types */
     Identifier,
     Integer,
+    String,
 
     /* Basic operators */
     Assign,
-    Plus, Minus,
-    Star, Slash, Percent,
+    PlusAssign,
+    MinusAssign,
+    StarAssign,
+    SlashAssign,
+    PercentAssign,
+    Plus, 
+    Minus, 
+    Star, 
+    Slash, 
+    Percent, 
+    LeftShift, RightShift, UnsignedRightShift,
     Comma,
+    And,
 
     /* Symbols */
     OpenParentheses,
@@ -115,6 +185,7 @@
 
     Not,
 
+
     /* Keywords */
     Byte, Ubyte,
     Short, Ushort,
@@ -129,17 +200,42 @@
 
     Void,
 
-    Struct,
+    Struct, Function, Delegate, Class, This,
+    Interface, Union, Typedef, Typeid,
+    Typeof, Sizeof, Alias,
 
     If, Else,
     While,
-    Switch, Case, Default,
-    Return, Cast,
-
-    String,
+    For,
+    Switch, Case, Default, Break,
+    Return, Cast, 
 
     Module, Import,
 
+    New, Null,
+
+    /* Attributes */
+    Public, Private, Package, Export, Protected,
+    Static,
+    Final,
+    Const,
+    Abstract,
+    Override,
+    Deprecated,
+    Auto,
+    Extern,
+
+    Align,
+
+    Asm,
+
+    In, Out, Body, 
+    
+    Assert, Throw, Try, Catch, Finally,
+
+            
+
+
 }
 
 /**
@@ -154,49 +250,79 @@
     typeToString =
     [
         Tok.EOF:"EOF"[],
-        Tok.Identifier:"Identifier",
-        Tok.Byte:"Byte",
-        Tok.Short:"Short",
-        Tok.Int:"Int",
-        Tok.Long:"Long",
-        Tok.Char:"Char",
-        Tok.Wchar:"Wchar",
-        Tok.Dchar:"Dchar",
-        Tok.Bool:"Bool",
-        Tok.Void:"Void",
-        Tok.Eq:"Eq",
-        Tok.Ne:"Ne",
-        Tok.Lt:"Lt",
-        Tok.Le:"Le",
-        Tok.Gt:"Gt",
-        Tok.Ge:"Ge",
-        Tok.OpenParentheses:"OpenParentheses",
-        Tok.CloseParentheses:"CloseParentheses",
-        Tok.OpenBrace:"OpenBrace",
-        Tok.CloseBrace:"CloseBrace",
-        Tok.OpenBracket:"OpenBracket",
-        Tok.CloseBracket:"CloseBracket",
-        Tok.Dot:"Dot",
-        Tok.Assign:"Assign",
-        Tok.Plus:"Plus",
-        Tok.Minus:"Minus",
-        Tok.Star:"Star",
-        Tok.Slash:"Slash",
-        Tok.Percent:"Percent",
-        Tok.Integer:"Integer",
-        Tok.If:"If",
-        Tok.While:"While",
-        Tok.Switch:"Switch",
-        Tok.Case:"Case",
-        Tok.Default:"Default",
-        Tok.Comma:"Comma",
-        Tok.Return:"Return",
-        Tok.Struct:"Struct",
-        Tok.Colon:"Colon",
-        Tok.Seperator:"Seperator",
-        Tok.Cast:"Cast",
-        Tok.Module:"Module",
-        Tok.Import:"Import",
-        Tok.String:"String"
+        Tok.Identifier:"identifier",
+        Tok.Byte:"byte",
+        Tok.Short:"short",
+        Tok.Int:"int",
+        Tok.Long:"long",
+        Tok.Char:"char",
+        Tok.Wchar:"wchar",
+        Tok.Dchar:"dchar",
+        Tok.Bool:"bool",
+        Tok.Void:"void",
+        Tok.Function:"function",
+        Tok.Eq:"==",
+        Tok.Ne:"!=",
+        Tok.Lt:"<",
+        Tok.Le:"<=",
+        Tok.Gt:">",
+        Tok.Ge:">=",
+        Tok.OpenParentheses:"(",
+        Tok.CloseParentheses:")",
+        Tok.OpenBrace:"{",
+        Tok.CloseBrace:"}",
+        Tok.OpenBracket:"[",
+        Tok.CloseBracket:"]",
+        Tok.Dot:"-",
+        Tok.Assign:"=",
+        Tok.Plus:"+",
+        Tok.PlusAssign:"+=",
+        Tok.Minus:"-",
+        Tok.MinusAssign:"-=",
+        Tok.Star:"*",
+        Tok.StarAssign:"*=",
+        Tok.Slash:"/",
+        Tok.SlashAssign:"/=",
+        Tok.Percent:"%",
+        Tok.PercentAssign:"%=",
+        Tok.LeftShift:"<<",
+        Tok.RightShift:">>",
+        Tok.UnsignedRightShift:">>>",
+        Tok.Integer:"int",
+        Tok.If:"if",
+        Tok.While:"while",
+        Tok.For:"for",
+        Tok.Switch:"switch",
+        Tok.Case:"case",
+        Tok.Default:"default",
+        Tok.Comma:",",
+        Tok.Return:"return",
+        Tok.Struct:"struct",
+        Tok.Class:"class",
+        Tok.This:"this",
+        Tok.Colon:":",
+        Tok.Seperator:";",
+        Tok.And:"&",
+        Tok.Cast:"cast",
+        Tok.Module:"module",
+        Tok.Import:"import",
+        Tok.String:"String",
+        Tok.Public:"public",
+        Tok.Private:"private",
+        Tok.Protected:"protected",
+        Tok.Package:"package",
+        Tok.Export:"export",
+        Tok.Static:"static",
+        Tok.Final:"finale",
+        Tok.Public:"public",
+        Tok.Const:"const",
+        Tok.Abstract:"abstract",
+        Tok.Override:"override",
+        Tok.Deprecated:"deprecated",
+        Tok.Auto:"auto",
+        Tok.Extern:"extern",
+        Tok.New:"new",
+        Tok.Null:"null",
+        Tok.Alias:"alias"
     ];
 }