diff lexer/Lexer.d @ 67:3fdf20b08a81 new_gen

Been working on the floating point parsing. Still a bit of work to do here.
author Anders Johnsen <skabet@gmail.com>
date Tue, 29 Apr 2008 20:15:22 +0200
parents 78a6808b2e0f
children 628cb46ab13b
line wrap: on
line diff
--- a/lexer/Lexer.d	Tue Apr 29 18:30:14 2008 +0200
+++ b/lexer/Lexer.d	Tue Apr 29 20:15:22 2008 +0200
@@ -33,7 +33,7 @@
 
 
         charTable.length = 256;
-        foreach( char c ; "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
+        foreach( char c ; "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_")
             charTable[c] = CharType.Letter;
 
         foreach( char c ; "0123456789")
@@ -157,6 +157,17 @@
     }
     Token dot() 
     {
+        int pos = 0;
+        while(getNextChar(0) == CharType.Number || 
+              this.source.data[position + pos + 1] == '_')
+        {
+            if(getNextChar(0) == CharType.Number)
+            {
+                position--;
+                return lexNumber();
+            }
+            pos++;
+        }
         return Token(Tok.Dot, Location(position - 1, this.source), 1);
     }
     Token comma() 
@@ -253,9 +264,51 @@
     
     Token lexNumber ()
     {
+        bool sign = false;
+        bool dot = false;
+        bool e = false;
+
         int i = 0;
-        while(getNextChar(++i) == CharType.Number)
-        {}
+
+        bool end = false;
+        while(!end)
+        {
+            switch(getNextChar(i))
+            {
+                case CharType.Number:
+                    break;
+                case CharType.Symbol:
+                    if(this.source.data[position+i] == '.')
+                    {
+                        if(dot)
+                            throw error(__LINE__,"Only one '.' is allowed in an floating number")
+                                .tok(Token(Tok.Float, Location(position + i, this.source), 1));
+                        dot = true;
+                        break;
+                    }
+                    end = true;
+                    continue;
+                case CharType.Letter:
+                    if(this.source.data[position+i] == '_')
+                        break;
+                    if (this.source.data[position+i] == 'e' || 
+                        this.source.data[position+i] == 'E')
+                    {
+                        if (e)
+                            throw error(__LINE__,"Only one '"~this.source.data[position+i]
+                                    ~"' is allowed in an floating number");
+                        e = true;
+                        break;
+                    }
+                    end = true;
+                    continue;
+
+                default:
+                    end = true;
+                    continue;
+            }
+            i++;
+        }
 
         position += i;