Better error reporting for missing identifiers.
authorMarek Safar <marek.safar@gmail.com>
Mon, 13 Sep 2010 08:46:59 +0000 (09:46 +0100)
committerMarek Safar <marek.safar@gmail.com>
Mon, 13 Sep 2010 16:53:41 +0000 (17:53 +0100)
mcs/errors/cs1001-3.cs [new file with mode: 0755]
mcs/errors/cs1001-4.cs [new file with mode: 0644]
mcs/errors/cs1001.cs [new file with mode: 0644]
mcs/errors/cs1041-2.cs [deleted file]
mcs/errors/cs1041.cs [new file with mode: 0644]
mcs/errors/cs1525-18.cs [deleted file]
mcs/errors/gcs1041.cs [deleted file]
mcs/errors/gcs1525-3.cs [deleted file]
mcs/mcs/cs-parser.jay

diff --git a/mcs/errors/cs1001-3.cs b/mcs/errors/cs1001-3.cs
new file mode 100755 (executable)
index 0000000..b09054c
--- /dev/null
@@ -0,0 +1,10 @@
+// CS1001: Unexpected symbol `)', expecting identifier
+// Line: 8
+
+class C
+{
+       public static void Main ()
+       {
+               object o = (int) => null;
+       }
+}
diff --git a/mcs/errors/cs1001-4.cs b/mcs/errors/cs1001-4.cs
new file mode 100644 (file)
index 0000000..451eb4b
--- /dev/null
@@ -0,0 +1,9 @@
+// CS1001: Unexpected symbol `)', expecting identifier
+// Line: 6
+
+class B<T>
+{
+       T Foo (T)
+       {
+       }
+}
diff --git a/mcs/errors/cs1001.cs b/mcs/errors/cs1001.cs
new file mode 100644 (file)
index 0000000..a1651fe
--- /dev/null
@@ -0,0 +1,9 @@
+// CS1001: Unexpected symbol `)', expecting identifier
+// Line: 6
+
+class T {
+       // Change (args) to (string args) to fix it
+       public static int Main (args)
+       {
+       }
+}
diff --git a/mcs/errors/cs1041-2.cs b/mcs/errors/cs1041-2.cs
deleted file mode 100644 (file)
index b108fb6..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// cs1001: Identifier expected
-// Line: 6
-
-class T {
-       // Change (args) to (string args) to fix it
-       public static int Main (args)
-       {
-       }
-}
diff --git a/mcs/errors/cs1041.cs b/mcs/errors/cs1041.cs
new file mode 100644 (file)
index 0000000..a770876
--- /dev/null
@@ -0,0 +1,15 @@
+// CS1041: Identifier expected, `foreach' is a keyword
+// Line: 11
+
+public partial class Log
+{
+       void Update (object[] h)
+       {
+               if (h == null)
+                       return;
+               
+               logstore.
+               foreach (var rev in h) {
+               }
+       }
+}
diff --git a/mcs/errors/cs1525-18.cs b/mcs/errors/cs1525-18.cs
deleted file mode 100644 (file)
index c6ad28b..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-// CS1525: Unexpected symbol `foreach', expecting `identifier'
-// Line: 11
-
-public partial class Log
-{
-       void Update (object[] h)
-       {
-               if (h == null)
-                       return;
-               
-               logstore.
-               foreach (var rev in h) {
-               }
-       }
-}
diff --git a/mcs/errors/gcs1041.cs b/mcs/errors/gcs1041.cs
deleted file mode 100644 (file)
index 61f9833..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// CS1001: Identifier expected
-// Line: 6
-
-class B<T>
-{
-       T Foo (T)
-       {
-       }
-}
\ No newline at end of file
diff --git a/mcs/errors/gcs1525-3.cs b/mcs/errors/gcs1525-3.cs
deleted file mode 100755 (executable)
index d183dba..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-// CS1525: Unexpected symbol `)', expecting `identifier'
-// Line: 8
-
-class C
-{
-       public static void Main ()
-       {
-               object o = (int) => null;
-       }
-}
index 00a087318f23e8c096f209495f9200b9ec9b55b9..1f9ea888dd79334f34c670808be80656185e9b3b 100644 (file)
@@ -443,8 +443,9 @@ using_alias_directive
                var lt = (Tokenizer.LocatedToken) $2;
                current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
          }
-       | USING error {
-               CheckIdentifierToken (yyToken, GetLocation ($2));
+       | USING error
+        {
+               Error_SyntaxError (yyToken);
                $$ = null;
          }
        ;
@@ -951,8 +952,9 @@ struct_declaration
                lbag.AppendToMember (current_class, GetLocation ($13));
                $$ = pop_current_class ();
          }
-       | opt_attributes opt_modifiers opt_partial STRUCT error {
-               CheckIdentifierToken (yyToken, GetLocation ($5));
+       | opt_attributes opt_modifiers opt_partial STRUCT error
+         {
+               Error_SyntaxError (yyToken);
          }
        ;
 
@@ -1517,8 +1519,8 @@ fixed_parameter
          parameter_type
          error
          {
+               Error_SyntaxError (yyToken);      
                Location l = GetLocation ($4);
-               CheckIdentifierToken (yyToken, l);
                $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
          }
        | opt_attributes
@@ -1643,7 +1645,7 @@ parameter_array
          }
        | opt_attributes params_modifier type error
          {
-               CheckIdentifierToken (yyToken, GetLocation ($4));
+               Error_SyntaxError (yyToken);
                $$ = null;
          }
        ;
@@ -1921,8 +1923,9 @@ interface_declaration
            lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13));
                $$ = pop_current_class ();
          }
-       | opt_attributes opt_modifiers opt_partial INTERFACE error {
-               CheckIdentifierToken (yyToken, GetLocation ($5));
+       | opt_attributes opt_modifiers opt_partial INTERFACE error
+         {
+               Error_SyntaxError (yyToken);      
          }
        ;
 
@@ -6202,11 +6205,6 @@ void CheckToken (int error, int yyToken, string msg, Location loc)
                Report.Error (error, loc, msg);
 }
 
-void CheckIdentifierToken (int yyToken, Location loc)
-{
-       CheckToken (1041, yyToken, "Identifier expected", loc);
-}
-
 string ConsumeStoredComment ()
 {
        string s = tmpComment;
@@ -6310,7 +6308,6 @@ public NamespaceEntry CurrentNamespace {
        }
 }
 
-
 void Error_SyntaxError (int token)
 {
        Error_SyntaxError (0, token, "Unexpected symbol");
@@ -6320,18 +6317,28 @@ void Error_SyntaxError (int error_code, int token, string msg)
 {
        string symbol = GetSymbolName (token);
        string expecting = GetExpecting ();
+       var loc = lexer.Location - symbol.Length;
        
        if (error_code == 0) {
-               if (expecting == "`)'")
+               if (expecting == "`identifier'") {
+                       if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
+                               Report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
+                               return;
+                       }
+                       
+                       error_code = 1001;
+                       expecting = "identifier";
+               } else if (expecting == "`)'") {
                        error_code = 1026;
-               else
+               } else {
                        error_code = 1525;
+               }
        }
        
        if (string.IsNullOrEmpty (expecting))
-               Report.Error (error_code, lexer.Location, "{1} `{0}'", symbol, msg);
+               Report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
        else
-               Report.Error (error_code, lexer.Location, "{2} `{0}', expecting {1}", symbol, expecting, msg);    
+               Report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);       
 }
 
 string GetExpecting ()