changeset 637:fe66cecb6ec9

Reporting error if module declaration is not first.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Mon, 14 Jan 2008 01:06:17 +0100
parents 15a0f37caabe
children 7131c07997f9
files trunk/src/dil/Messages.d trunk/src/dil/parser/Parser.d
diffstat 2 files changed, 9 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/Messages.d	Mon Jan 14 00:21:13 2008 +0100
+++ b/trunk/src/dil/Messages.d	Mon Jan 14 01:06:17 2008 +0100
@@ -91,16 +91,6 @@
   return Format(_arguments, _argptr, GetMsg(mid));
 }
 
-/+
-char[] FormatArray(char[] format_str, char[][] args)
-{
-  auto tiinfos = new TypeInfo[args.length];
-  foreach (ref tiinfo; tiinfos)
-    tiinfo = typeid(char[]);
-  return Format(tiinfos, args.ptr, format_str);
-}
-+/
-
 /// Collection of error messages with no MID yet.
 struct MSG
 {
@@ -111,6 +101,7 @@
   auto UTF16FileMustBeDivisibleBy2 = "the byte length of a UTF-16 source file must be divisible by 2.";
   auto UTF32FileMustBeDivisibleBy4 = "the byte length of a UTF-32 source file must be divisible by 4.";
   // Parser messages:
+  auto ModuleDeclarationNotFirst = "a module declaration is only allowed as the first declaration in a file";
   auto ExpectedIdAfterTypeDot = "expected identifier after '(Type).', not '{}'";
   auto ExpectedModuleIdentifier = "expected module identifier, not '{}'";
   auto IllegalDeclaration = "illegal Declaration found: {}";
--- a/trunk/src/dil/parser/Parser.d	Mon Jan 14 00:21:13 2008 +0100
+++ b/trunk/src/dil/parser/Parser.d	Mon Jan 14 01:06:17 2008 +0100
@@ -173,6 +173,7 @@
 
   Declaration parseModuleDeclaration()
   {
+    assert(token.type == T.Module);
     auto begin = token;
     ModuleFQN moduleFQN;
     do
@@ -268,12 +269,10 @@
       return parseStorageAttribute();
     case T.Alias:
       nT();
-      // TODO: parse StorageClasses?
       decl = new AliasDeclaration(parseVariableOrFunction());
       break;
     case T.Typedef:
       nT();
-      // TODO: parse StorageClasses?
       decl = new TypedefDeclaration(parseVariableOrFunction());
       break;
     case T.Static:
@@ -365,12 +364,18 @@
     case T.Identifier, T.Dot, T.Typeof:
     case_Declaration:
       return parseVariableOrFunction(this.storageClass, this.protection, this.linkageType);
-    /+case T.Module:
+    /+case :
       // TODO: Error: module is optional and can appear only once at the top of the source file.
       break;+/
     default:
       if (token.isIntegralType)
         goto case_Declaration;
+      else if (token.type == T.Module)
+      {
+        decl = parseModuleDeclaration();
+        error(begin, MSG.ModuleDeclarationNotFirst);
+        return decl;
+      }
 
       decl = new IllegalDeclaration();
       // Skip to next valid token.