Mercurial > projects > dang
diff parser/Parser.d @ 53:da551f90e03f new_gen
Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Sat, 26 Apr 2008 18:52:27 +0200 |
parents | c96cdcbdb9d6 |
children | 78a6808b2e0f |
line wrap: on
line diff
--- a/parser/Parser.d Sat Apr 26 16:12:36 2008 +0200 +++ b/parser/Parser.d Sat Apr 26 18:52:27 2008 +0200 @@ -63,12 +63,52 @@ } else if (t.type == Tok.Struct) { + Id type = Id(lexer.next); + Id iden = Id(require(Tok.Identifier)); + + return parseStruct(type, iden); } char[] c = t.getType; throw error(__LINE__, PE.UnexpectedTok).tok(t).arg(c); } /** + Parse struct + */ + Decl parseStruct(Id type, Id iden) + { + auto decl = action.actOnDeclarator(type, iden, null); + + require(Tok.OpenBrace); + + while(lexer.peek.isBasicType || lexer.peek.isIdentifier) + { + Id var_type = Id(lexer.next); + Id var_iden = Id(require(Tok.Identifier)); + Token next = lexer.peek(); + if (next.type == Tok.Seperator) + { + Token sep = lexer.next(); + action.actOnStructMember(decl, var_type, var_iden, null); + continue; + } + else if (next.type == Tok.Assign) + { + Token assign = lexer.next(); + Exp exp = parseExpression(); + require(Tok.Seperator); + action.actOnStructMember(decl, var_type, var_iden, exp); + continue; + } + throw error(__LINE__, PE.UnexpectedTok) + .tok(next).arg(next.getType); + } + + require(Tok.CloseBrace); + + return decl; + } + /** Parse statements. This is the place to attack!