diff dmd/Parser.d @ 19:01cadcfa4842

Implemented CompileExp, ConditionalDeclaration, ModAssignExp, parsingmixin statements, TemplateAliasParameters, TemplateMixins, TypeDArray.
author Robert Clipsham <robert@octarineparrot.com>
date Tue, 06 Apr 2010 02:21:04 +0100
parents d706d958e4e8
children 460959608115
line wrap: on
line diff
--- a/dmd/Parser.d	Mon Apr 05 19:16:14 2010 +0100
+++ b/dmd/Parser.d	Tue Apr 06 02:21:04 2010 +0100
@@ -46,6 +46,7 @@
 import dmd.AssertExp;
 import dmd.CompileExp;
 import dmd.FileExp;
+import dmd.TemplateMixin;
 import dmd.TemplateParameter;
 import dmd.TemplateTypeParameter;
 import dmd.TypeidExp;
@@ -1075,10 +1076,96 @@
 	Lerr:
 		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 == TOK.TOKdot)
+    {
+	id = Id.empty;
+    }
+    else
+    {
+	if (token.value == TOK.TOKtypeof)
+	{
+	    tqual = parseTypeof();
+	    check(TOKdot);
+	}
+	if (token.value != TOK.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 == TOK.TOKnot)
+	{
+	    nextToken();
+	    if (token.value == TOK.TOKlparen)
+		tiargs = parseTemplateArgumentList();
+	    else
+		tiargs = parseTemplateArgument();
+	}
+
+	if (token.value != TOK.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 != TOK.TOKidentifier)
+	{   error("identifier expected following '.' instead of '%s'", token.toChars());
+	    break;
+	}
+	id = token.ident;
+	nextToken();
+    }
+    idents.push(cast(void*)id);
+
+    if (token.value == TOK.TOKidentifier)
+    {
+	id = token.ident;
+	nextToken();
+    }
+    else
+	id = null;
+
+    tm = new TemplateMixin(loc, id, tqual, idents, tiargs);
+    if (token.value != TOK.TOKsemicolon)
+	error("';' expected after mixin");
+    nextToken();
+
+    return tm;
 	}
 	
 	/******************************************
@@ -6024,4 +6111,4 @@
 		s.addComment(combineComments(blockComment, token.lineComment));
 		token.lineComment = null;
 	}
-}
\ No newline at end of file
+}