Mercurial > projects > dil
diff trunk/src/Lexer.d @ 103:511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
- Started implementation of parseDeclaration(), parseAttributeSpecifier() and parseImportDeclaration().
author | aziz |
---|---|
date | Sun, 08 Jul 2007 10:14:00 +0000 |
parents | 0fe650a7a8d1 |
children | df34ec47fb81 |
line wrap: on
line diff
--- a/trunk/src/Lexer.d Sat Jul 07 21:34:02 2007 +0000 +++ b/trunk/src/Lexer.d Sun Jul 08 10:14:00 2007 +0000 @@ -35,6 +35,8 @@ Information[] errors; + bool reportErrors; + Identifier[string] idtable; this(string text, string fileName) @@ -50,7 +52,7 @@ this.p = this.text.ptr; this.end = this.p + this.text.length; - + this.reportErrors = true; loadKeywords(); } @@ -531,16 +533,6 @@ } } - void peek(ref Token t) - { - char* tmp = p; - uint len = errors.length; - scan(t); - p = tmp; - if (errors.length != len) - errors = errors[0..len]; - } - void scanNormalStringLiteral(ref Token t) { assert(*p == '"'); @@ -1434,9 +1426,27 @@ idtable[k.str] = k; } + void peek(ref Token t) + { + // Because peeked tokens are not stored in a linked + // list we need to switch off error reporting + // so as to avoid getting the same error more than once. + reportErrors = false; + char* save = p; + if (t.end) // For successive peeks. + { + p = t.end; + assert(text.ptr <= p && p < end); + } + scan(t); + p = save; + reportErrors = true; + } + void error(MID id, ...) { - errors ~= new Information(InfoType.Lexer, id, loc, arguments(_arguments, _argptr)); + if (reportErrors) + errors ~= new Information(InfoType.Lexer, id, loc, arguments(_arguments, _argptr)); } public TOK nextToken()