diff trunk/src/Parser.d @ 86:0459c902a370

- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions. - Added methods errorIfNot(), requireNext() and require(). - Added error msg MID.ExpectedButFound.
author aziz
date Thu, 05 Jul 2007 18:45:00 +0000
parents d8dc3171440d
children c9544b7d5c7d
line wrap: on
line diff
--- a/trunk/src/Parser.d	Thu Jul 05 14:20:05 2007 +0000
+++ b/trunk/src/Parser.d	Thu Jul 05 18:45:00 2007 +0000
@@ -423,10 +423,13 @@
       break;
     case T.String:
       char[] buffer = lx.token.str;
+      char postfix = lx.token.pf;
       nT();
       while (lx.token.type == T.String)
       {
         string tmp = lx.token.str;
+//         if (postfix != lx.token.pf)
+//           error();
         if (tmp.length > 1)
         {
           buffer[$-1] = tmp[0]; // replace '\0'
@@ -490,19 +493,55 @@
     case T.Function, T.Delegate:
       break;
     case T.Assert:
+      Expression msg;
+      requireNext(T.LParen);
+      e = parseAssignExpression();
+      if (lx.token.type == T.Comma)
+      {
+        nT();
+        msg = parseAssignExpression();
+      }
+      require(T.RParen);
+      e = new AssertExpression(e, msg);
       break;
     case T.Mixin:
+      requireNext(T.LParen);
+      e = parseAssignExpression();
+      require(T.RParen);
+      e = new MixinExpression(e);
       break;
     case T.Import:
+      requireNext(T.LParen);
+      e = parseAssignExpression();
+      require(T.RParen);
+      e = new ImportExpression(e);
       break;
     case T.Typeid:
+      requireNext(T.LParen);
+      e = new TypeidExpression();
       break;
     case T.Is:
       break;
     case T.LParen:
       break;
+    // BasicType . Identifier
+    case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, T.Byte, T.Ubyte,
+         T.Short, T.Ushort, T.Int, T.Uint, T.Long, T.Ulong,
+         T.Float, T.Double, T.Real, T.Ifloat, T.Idouble, T.Ireal,
+         T.Cfloat, T.Cdouble, T.Creal:
+    TOK type = lx.token.type;
+    requireNext(T.Dot);
+
+    string ident;
+    errorIfNot(T.Identifier);
+    if (lx.token.type == T.Identifier)
+    {
+      ident = lx.token.srcText;
+      nT();
+    }
+
+    e = new TypeDotIdExpression(type, ident);
     default:
-      // BasicType . Identifier
     }
     return e;
   }
@@ -537,6 +576,29 @@
     return es;
   }
 
+  void errorIfNot(TOK tok)
+  {
+    if (lx.token.type != tok)
+      error(MID.ExpectedButFound, tok, lx.token.srcText);
+  }
+
+  void require(TOK tok)
+  {
+    if (lx.token.type == tok)
+      nT();
+    else
+      error(MID.ExpectedButFound, tok, lx.token.srcText);
+  }
+
+  void requireNext(TOK tok)
+  {
+    nT();
+    if (lx.token.type == tok)
+      nT();
+    else
+      error(MID.ExpectedButFound, tok, lx.token.srcText);
+  }
+
   void error(MID id, ...)
   {
     errors ~= new Information(Information.Type.Parser, id, lx.loc, arguments(_arguments, _argptr));