# HG changeset patch # User Aziz K?ksal # Date 1189438618 -7200 # Node ID 66477017cb95e90e8472887eb4010375ada817fd # Parent 7b5c6c2c6a793ebf54529247a59d7d4681ae0500 Applied fixes to isNonReservedIdentifier(). Return false if ident is empty. Before entering the foreach loop, it must be checked if ident starts with a valid identifier character. diff -r 7b5c6c2c6a79 -r 66477017cb95 trunk/src/dil/Lexer.d --- a/trunk/src/dil/Lexer.d Sat Sep 08 20:57:01 2007 +0000 +++ b/trunk/src/dil/Lexer.d Mon Sep 10 17:36:58 2007 +0200 @@ -1578,7 +1578,7 @@ foreach(k; keywords) idtable[k.str] = k; } -/+ +/+ // Not needed anymore because tokens are stored in a linked list. struct State { Lexer lexer; @@ -1648,6 +1648,7 @@ unittest { + writefln("Testing method Lexer.peek()"); string sourceText = "unittest { }"; auto lx = new Lexer(sourceText, null); @@ -1660,7 +1661,6 @@ assert(next.type == TOK.RBrace); lx.peek(next); assert(next.type == TOK.EOF); - writefln("end of peek() unittest"); } Token* getTokens() @@ -1672,16 +1672,34 @@ static bool isNonReservedIdentifier(char[] ident) { + if (ident.length == 0) + return false; + static Identifier[string] reserved_ids_table; if (reserved_ids_table is null) foreach(k; keywords) reserved_ids_table[k.str] = k; + size_t idx = 1; // Index to the 2nd character in ident. + dchar isFirstCharUniAlpha() + { + idx = 0; + // NB: decode() could throw an Exception which would be + // caught by the next try-catch-block. + return isUniAlpha(std.utf.decode(ident, idx)); + } + try - foreach (dchar c; ident) - if (!isident(c) && !isUniAlpha(c)) - return false; - catch (Exception e) + { + if (isidbeg(ident[0]) || + ident[0] & 128 && isFirstCharUniAlpha()) + { + foreach (dchar c; ident[idx..$]) + if (!isident(c) && !isUniAlpha(c)) + return false; + } + } + catch (Exception) return false; return !(ident in reserved_ids_table);