diff dmd/Parser.d @ 13:427f8aa74d28

On the road to make Phobos compilable
author korDen
date Mon, 12 Apr 2010 16:29:33 +0400
parents d706d958e4e8
children 460959608115
line wrap: on
line diff
--- a/dmd/Parser.d	Mon Apr 12 15:13:00 2010 +0400
+++ b/dmd/Parser.d	Mon Apr 12 16:29:33 2010 +0400
@@ -12,6 +12,7 @@
 import dmd.CatAssignExp;
 import dmd.StaticIfCondition;
 import dmd.TraitsExp;
+import dmd.TemplateMixin;
 import dmd.BaseClass;
 import dmd.AssignExp;
 import dmd.TemplateInstance;
@@ -1076,9 +1077,96 @@
 		return tpl;
 	}
 	
+	/******************************************
+	 * Parse template mixin.
+	 *	mixin Foo;
+	 *	mixin Foo!(args);
+	 *	mixin a.b.c!(args).Foo!(args);
+	 *	mixin Foo!(args) identifier;
+	 *	mixin typeof(expr).identifier!(args);
+	 */
     Dsymbol parseMixin()
 	{
-		assert(false);
+		TemplateMixin tm;
+		Identifier id;
+		Type tqual;
+		Objects tiargs;
+		Array idents;
+
+		//printf("parseMixin()\n");
+		nextToken();
+		tqual = null;
+		if (token.value == TOKdot)
+		{
+			id = Id.empty;
+		}
+		else
+		{
+			if (token.value == TOKtypeof)
+			{
+				tqual = parseTypeof();
+				check(TOKdot);
+			}
+			if (token.value != TOKidentifier)
+			{
+				error("identifier expected, not %s", token.toChars());
+				id = Id.empty;
+			}
+			else
+				id = token.ident;
+			nextToken();
+		}
+
+		idents = new Array();
+		while (1)
+		{
+			tiargs = null;
+			if (token.value == TOKnot)
+			{
+				nextToken();
+				if (token.value == TOKlparen)
+					tiargs = parseTemplateArgumentList();
+				else
+					tiargs = parseTemplateArgument();
+			}
+
+			if (token.value != TOKdot)
+				break;
+
+			if (tiargs)
+			{   
+				TemplateInstance tempinst = new TemplateInstance(loc, id);
+				tempinst.tiargs = tiargs;
+				id = cast(Identifier)tempinst;
+				tiargs = null;
+			}
+			idents.push(cast(void*)id);
+
+			nextToken();
+			if (token.value != TOKidentifier)
+			{   
+				error("identifier expected following '.' instead of '%s'", token.toChars());
+				break;
+			}
+			id = token.ident;
+			nextToken();
+		}
+		idents.push(cast(void*)id);
+
+		if (token.value == TOKidentifier)
+		{
+			id = token.ident;
+			nextToken();
+		}
+		else
+			id = null;
+
+		tm = new TemplateMixin(loc, id, tqual, idents, tiargs);
+		if (token.value != TOKsemicolon)
+			error("';' expected after mixin");
+		nextToken();
+
+		return tm;
 	}
 	
 	/******************************************