# HG changeset patch # User Aziz K?ksal # Date 1205337687 -3600 # Node ID 49e32b5bc161ba328780f7613e3a8807707afe70 # Parent 1abffc3965949a9848f9fcd8add614cb0cdd4c15 Added isValidUnreservedIdentifier() to Lexer. Added the msg InvalidModuleName. diff -r 1abffc396594 -r 49e32b5bc161 src/dil/Messages.d --- a/src/dil/Messages.d Wed Mar 12 00:49:17 2008 +0100 +++ b/src/dil/Messages.d Wed Mar 12 17:01:27 2008 +0100 @@ -115,6 +115,7 @@ auto UnterminatedDDocMacro = "DDoc macro '{}' has no closing ')'"; // Lexer messages: auto InvalidOctalEscapeSequence = "value of octal escape sequence is greater than 0xFF: '{}'"; + auto InvalidModuleName = "the file name '{}' can't be used a module name; it's an invalid or reserved D identifier."; // Parser messages: auto InvalidUTF8SequenceInString = "invalid UTF-8 sequence in string literal: '{0}'"; auto ModuleDeclarationNotFirst = "a module declaration is only allowed as the first declaration in a file"; diff -r 1abffc396594 -r 49e32b5bc161 src/dil/lexer/Lexer.d --- a/src/dil/lexer/Lexer.d Wed Mar 12 00:49:17 2008 +0100 +++ b/src/dil/lexer/Lexer.d Wed Mar 12 17:01:27 2008 +0100 @@ -2547,14 +2547,16 @@ /// Returns true if str is a keyword or a special token (__FILE__, __LINE__ etc.) static bool isReservedIdentifier(char[] str) { - if (!isIdentifierString(str)) - return false; // str is not a valid identifier. - auto id = IdTable.inStatic(str); if (id is null || id.kind == TOK.Identifier) return false; // str is not in the table or a normal identifier. + return true; + } - return true; + /// Returns true if this is a valid identifier and if it's not reserved. + static bool isValidUnreservedIdentifier(char[] str) + { + return isIdentifierString(str) && !isReservedIdentifier(str); } /// Returns true if the current character to be decoded is diff -r 1abffc396594 -r 49e32b5bc161 src/dil/semantic/Module.d --- a/src/dil/semantic/Module.d Wed Mar 12 00:49:17 2008 +0100 +++ b/src/dil/semantic/Module.d Wed Mar 12 17:01:27 2008 +0100 @@ -10,6 +10,8 @@ import dil.lexer.Lexer; import dil.semantic.Symbol; import dil.semantic.Symbols; +import dil.Location; +import dil.Messages; import dil.Information; import dil.SourceText; import common; @@ -102,8 +104,13 @@ if (!this.moduleFQN.length) { // Take base name of file path as module name. auto str = (new FilePath(filePath)).name(); - if (Lexer.isReservedIdentifier(str)) - throw new Exception("'"~str~"' is not a valid module name; it's a reserved or invalid D identifier."); + if (!Lexer.isValidUnreservedIdentifier(str)) + { + auto location = parser.lexer.firstToken().getErrorLocation(); + auto msg = Format(MSG.InvalidModuleName, str); + infoMan ~= new LexerError(location, msg); + str = "_"; + } this.moduleFQN = this.moduleName = str; } } diff -r 1abffc396594 -r 49e32b5bc161 src/main.d --- a/src/main.d Wed Mar 12 00:49:17 2008 +0100 +++ b/src/main.d Wed Mar 12 17:01:27 2008 +0100 @@ -334,7 +334,7 @@ version(D2) cc.addVersionId("D_Version2"); foreach (versionId; GlobalSettings.versionIds) - if (!Lexer.isReservedIdentifier(versionId)) + if (Lexer.isValidUnreservedIdentifier(versionId)) cc.versionIds[versionId] = true; return cc; } @@ -348,7 +348,7 @@ auto val = arg[7..$]; if (isdigit(val[0])) context.debugLevel = Integer.toInt(val); - else if (!Lexer.isReservedIdentifier(val)) + else if (Lexer.isValidUnreservedIdentifier(val)) context.addDebugId(val); } else @@ -359,7 +359,7 @@ auto val = arg[9..$]; if (isdigit(val[0])) context.versionLevel = Integer.toInt(val); - else if (!Lexer.isReservedIdentifier(val)) + else if (Lexer.isValidUnreservedIdentifier(val)) context.addVersionId(val); } else