Mercurial > projects > dil
diff trunk/src/Parser.d @ 150:753bc07bf3a0
- Forgot to pass ident to constructor of TemplateArgument.
- Implemented parseMixinDeclaration().
- Forgot calling nT() before creating an AttributeDeclaration.
- Removed GlobalIdExpression. Creating an IdentifierExpression with "." as ident instead.
- Created TemplateArguments typedef for Object[].
author | aziz |
---|---|
date | Thu, 12 Jul 2007 18:06:02 +0000 |
parents | 37e2e0d06013 |
children | 2e959f67000b |
line wrap: on
line diff
--- a/trunk/src/Parser.d Thu Jul 12 14:55:00 2007 +0000 +++ b/trunk/src/Parser.d Thu Jul 12 18:06:02 2007 +0000 @@ -179,16 +179,17 @@ decl = parseDeleteDeclaration(); break; case T.Mixin: - // TODO: parse TemplateMixin + decl = parseMixinDeclaration(); break; case T.Semicolon: nT(); decl = new EmptyDeclaration(); break; case T.Module: - // Error: module is optional and can appear only once at the top of the source file. + // TODO: Error: module is optional and can appear only once at the top of the source file. break; default: + // TODO: issue error msg. } return decl; } @@ -307,6 +308,7 @@ case T.Const: case T.Auto: case T.Scope: + nT(); decl = new AttributeDeclaration(token.type, parseDeclarationsBlock()); break; default: @@ -910,6 +912,55 @@ return new DeleteDeclaration(parameters, decls); } + /* + TemplateMixin: + mixin TemplateIdentifier ; + mixin TemplateIdentifier MixinIdentifier ; + mixin TemplateIdentifier !( TemplateArgumentList ) ; + mixin TemplateIdentifier !( TemplateArgumentList ) MixinIdentifier ; + */ + Declaration parseMixinDeclaration() + { + assert(token.type == T.Mixin); + nT(); // Skip mixin keyword. + + Expression[] templateIdent; + string mixinIdent; + + if (token.type == T.Dot) + { + nT(); + templateIdent ~= new IdentifierExpression("."); + } + + while (1) + { + string ident = requireIdentifier(); + if (token.type == T.Not) // Identifier !( TemplateArguments ) + { + // No need to peek for T.RParen. This must be a template instance. + nT(); + templateIdent ~= new TemplateInstanceExpression(ident, parseTemplateArguments()); + } + else // Identifier + templateIdent ~= new IdentifierExpression(ident); + + if (token.type != T.Dot) + break; + nT(); + } + + if (token.type == T.Identifier) + { + mixinIdent = token.identifier; + nT(); + } + + require(T.Semicolon); + + return new MixinDeclaration(templateIdent, mixinIdent); + } + /+++++++++++++++++++++++++++++ + Expression parsing methods + +++++++++++++++++++++++++++++/ @@ -1270,8 +1321,8 @@ nT(); break; case T.Dot: - requireNext(T.Identifier); - e = new GlobalIdExpression(token.identifier); + nT(); + e = new IdentifierExpression("."); break; case T.This: nT(); @@ -1804,9 +1855,9 @@ return params; } - Object[] parseTemplateArguments() + TemplateArguments parseTemplateArguments() { - Object[] args; + TemplateArguments args; require(T.LParen); if (token.type == T.RParen) @@ -1939,7 +1990,7 @@ } } - tparams ~= new TemplateParameter(tp, valueType, specType, defType, specValue, defValue); + tparams ~= new TemplateParameter(tp, valueType, ident, specType, defType, specValue, defValue); if (token.type != T.Comma) break;