Mercurial > projects > dil
changeset 106:441962b0f526
- Added parseArrayType() method.
- Added e2 member to ArrayType and two more constructors.
- Corrected function header of try_().
author | aziz |
---|---|
date | Sun, 08 Jul 2007 13:33:02 +0000 |
parents | df34ec47fb81 |
children | 722c05bbd5eb |
files | trunk/src/Parser.d trunk/src/Types.d |
diffstat | 2 files changed, 49 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/Parser.d Sun Jul 08 11:57:03 2007 +0000 +++ b/trunk/src/Parser.d Sun Jul 08 13:33:02 2007 +0000 @@ -66,7 +66,7 @@ nT(); } - ReturnType try_(ReturnType)(lazy ReturnType parseMethod, out failed) + ReturnType try_(ReturnType)(lazy ReturnType parseMethod, out bool failed) { auto len = errors.length; auto lexerState = lx.getState(); @@ -881,18 +881,7 @@ nT(); break; case T.LBracket: - nT(); - if (token.type == T.RBracket) - { - t = new ArrayType(t, null); - nT(); - } - else - { - // TODO: try parsing as Type for assoc arrays and then as Expression. - t = new ArrayType(t, parseExpression()); - require(T.RBracket); - } + t = parseArrayType(t); break; case T.Function, T.Delegate: TOK tok = token.type; @@ -918,18 +907,7 @@ switch (token.type) { case T.LBracket: - nT(); - if (token.type == T.RBracket) - { - t = new ArrayType(t, null); - nT(); - } - else - { - // TODO: try parsing as Type for assoc arrays and then as Expression. - t = new ArrayType(t, parseExpression()); - require(T.RBracket); - } + t = parseArrayType(t); continue; case T.LParen: auto params = parseParameters(); @@ -944,6 +922,36 @@ return t; } + Type parseArrayType(Type t) + { + assert(token.type == T.LBracket); + nT(); + if (token.type == T.RBracket) + { + t = new ArrayType(t); + nT(); + } + else + { + bool failed; + auto assocType = try_(parseType(), failed); + if (!failed) + t = new ArrayType(t, assocType); + else + { + Expression e = parseExpression(), e2; + if (token.type == T.Slice) + { + nT(); + e2 = parseExpression(); + } + t = new ArrayType(t, e, e2); + } + require(T.RBracket); + } + return t; + } + Type parseDeclarator(ref string ident, bool identOptional = false) { auto t = parseType();
--- a/trunk/src/Types.d Sun Jul 08 11:57:03 2007 +0000 +++ b/trunk/src/Types.d Sun Jul 08 13:33:02 2007 +0000 @@ -83,20 +83,31 @@ class ArrayType : Type { - Expression e; - this(Type t, Expression e) + Expression e, e2; + Type assocType; + this(Type t) { super(TOK.Invalid, t); + } + this(Type t, Expression e, Expression e2) + { + this(t); this.e = e; + this.e2 = e2; + } + this(Type t, Type assocType) + { + this(t); + this.assocType = assocType; } } class SpecializationType : Type { - TOK specTok; // T.Colon|T.Equal + TOK specTok; // Colon|Equal Type type; - TOK tokType; // T.Typedef|T.Struct|T.Union|T.Class|T.Interface| - // T.Enum| T.Function|T.Delegate|T.Super|T.Return + TOK tokType; // Typedef|Struct|Union|Class|Interface| + // Enum|Function|Delegate|Super|Return this(TOK specTok, TOK tokType) {