# HG changeset patch # User Anders Johnsen # Date 1209736137 -7200 # Node ID 9171f04dd9ee7fede18861d5787a1afe7c0a69af # Parent 86aec21602211ce1ebec01fba4f84b3a8e1decb7 Now parsing varDecls a lot nicer! diff -r 86aec2160221 -r 9171f04dd9ee parser/Parser.d --- a/parser/Parser.d Fri May 02 15:05:02 2008 +0200 +++ b/parser/Parser.d Fri May 02 15:48:57 2008 +0200 @@ -39,7 +39,7 @@ if (t.isBasicType || t.isIdentifier) { - Id type = parseType;//Id(lexer.next); + Id type = Id(lexer.next); Id iden = Id(require(Tok.Identifier)); Token next = lexer.peek(); if (next.type == Tok.Seperator) @@ -182,26 +182,18 @@ // identifiers in a row if (iden.isBasicType() || iden.isIdentifier()) { - // manually hardcoded to only support "type id [= exp];" - // as that is the only thing the codegen understands - Id type = parseType; - n = lexer.peek(); - Id id = Id(lexer.next); - Exp init; - if (skip(Tok.Assign)) - init = parseExpression(); - require(Tok.Seperator); - Decl d = action.actOnDeclarator(type, id, init); - return action.actOnDeclStmt(d); - } - // Expression: a.b, a = b, a(b) etc. - else - { + if ( n.type == Tok.Star) + return action.actOnDeclStmt(parseVarDecl()); + + if ( n.isIdentifier()) + return action.actOnDeclStmt(parseVarDecl()); + + // Expression: a.b, a = b, a(b) etc. Exp exp = parseExpression(); require(Tok.Seperator); return action.actOnExprStmt(exp); + break; } - break; case Tok.Switch: throw error(__LINE__, ":(").tok(lexer.peek); @@ -216,6 +208,20 @@ return null; } + Decl parseVarDecl() + { + // manually hardcoded to only support "type id [= exp];" + // as that is the only thing the codegen understands + Id type = parseType; + Id id = Id(lexer.next); + Exp init; + if (skip(Tok.Assign)) + init = parseExpression(); + require(Tok.Seperator); + Decl d = action.actOnDeclarator(type, id, init); + return d; + } + /** Parses a function/method given the already parsed return type and name */