diff lexer/Token.d @ 42:4e879f82dd64 new_gen

Added some docs for the lexer - now you can understand _some_ of the madness going on here :)
author Anders Johnsen <skabet@gmail.com>
date Tue, 22 Apr 2008 22:25:07 +0200
parents 858b9805843d
children 495188f9078e
line wrap: on
line diff
--- a/lexer/Token.d	Tue Apr 22 19:30:51 2008 +0200
+++ b/lexer/Token.d	Tue Apr 22 22:25:07 2008 +0200
@@ -5,12 +5,23 @@
 
 import Integer = tango.text.convert.Integer;
 
+/** 
+  The Token struct will be used through the Lexer, Parser and other
+  modules as a location into source.
+
+  The Token should always be optimized for size to limit unnecessary
+  memory usage.
+  */
 struct Token
 {
     Tok type;
     Location location;
     uint length;
 
+    /**
+      Create a new token with a Tok type, Location in source and a 
+      length of how many chars the Token span in the source
+      */
     static Token opCall (Tok type, Location location, uint length)
     {
         Token t;
@@ -20,23 +31,39 @@
         return t;
     }
 
+    /**
+      Get the type of the Token as a string
+      */
     char[] getType ()
     {
         return typeToString[this.type];
     }
 
+    /**
+      A human readable dump of a Token
+      */
     char[] toString ()
     {
         return this.getType()~": Len: "~Integer.toString(this.length)
             ~", Loc: "~location.toString;
     }
 
+    /**
+      Get the string in the source that matches what this Token is 
+      covering.
+      */
     char[] get ()
     {
         return location.get(length);
     }
 }
 
+/**
+  Tok is short for TokenType. This enum list is to supply the Token 
+  with a type. 
+  
+  This enum is used to switch over "many" places.
+  */
 enum Tok : ushort
 {
     /* Non-code related tokens */
@@ -89,6 +116,11 @@
 
 }
 
+/**
+  An associative array to supply a Tok to String function.
+
+  Keep always this list updated when adding a new Tok.
+  */
 public char[][Tok] typeToString;
 
 static this()