[fix] #631810: Form.DialogResult needs to call its close events *before* closing.
[mono.git] / mcs / mcs / cs-parser.jay
index 00a087318f23e8c096f209495f9200b9ec9b55b9..de1b01e4a858e557b95348750e627bb6e5ad27dc 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;
          }
        ;
@@ -470,7 +471,7 @@ namespace_declaration
                        Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
                }
 
-               current_namespace = new NamespaceEntry (
+               current_namespace = new NamespaceEntry (compiler,
                        current_namespace, file, name.GetName ());
                current_class = current_namespace.SlaveDeclSpace;
                current_container = current_class.PartialContainer;
@@ -496,7 +497,7 @@ qualified_identifier
          }
        | error
          {
-               syntax_error (lexer.Location, "`.' expected");
+               Error_SyntaxError (yyToken);
                $$ = new MemberName ("<invalid>", lexer.Location);
          }
        ;
@@ -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);
          }
        ;
 
@@ -1234,6 +1236,12 @@ fixed_field_size
 variable_initializer
        : expression
        | array_initializer
+       | error
+         {
+               // It has to be here for the parent to safely restore artificial block
+               Error_SyntaxError (yyToken);
+               $$ = null;
+         }
        ;
 
 method_declaration
@@ -1517,8 +1525,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 +1651,7 @@ parameter_array
          }
        | opt_attributes params_modifier type error
          {
-               CheckIdentifierToken (yyToken, GetLocation ($4));
+               Error_SyntaxError (yyToken);
                $$ = null;
          }
        ;
@@ -1921,8 +1929,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);      
          }
        ;
 
@@ -3597,11 +3606,6 @@ variable_initializer_list
                list.Add ((Expression) $3);
                $$ = list;
          }
-       | error
-         {
-               Error_SyntaxError (yyToken);
-               $$ = new List<Expression> ();
-         }
        ;
 
 typeof_expression
@@ -3780,11 +3784,6 @@ cast_expression
                $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
                lbag.AddLocation ($$, GetLocation ($3));
          }
-       | OPEN_PARENS builtin_types CLOSE_PARENS prefixed_unary_expression
-         {
-               $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
-               lbag.AddLocation ($$, GetLocation ($3));
-         }
        ;
 
        //
@@ -4593,6 +4592,11 @@ embedded_statement
                  Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
                  $$ = null;
          }
+       | error
+         {
+               Error_SyntaxError (yyToken);
+               $$ = new EmptyStatement (GetLocation ($1));
+         }
        ;
 
 empty_statement
@@ -5399,19 +5403,14 @@ using_statement
                current_block.AddStatement (u);
                $$ = end_block (GetLocation ($8));
          }
-       | USING open_parens_any expression CLOSE_PARENS
+       | USING open_parens_any expression CLOSE_PARENS embedded_statement
          {
-               start_block (lexer.Location);
-         }
-         embedded_statement
-         {
-               if ($6 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
-                       Warning_EmptyStatement (GetLocation ($6));
+               if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
+                       Warning_EmptyStatement (GetLocation ($5));
          
-               UsingTemporary usingTemporary = new UsingTemporary ((Expression) $3, (Statement) $6, GetLocation ($1));
-               lbag.AddStatement (usingTemporary, GetLocation ($2), GetLocation ($4));
-               current_block.AddStatement (usingTemporary);
-               $$ = end_block (lexer.Location);
+               Using u = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
+               lbag.AddStatement (u, GetLocation ($2), GetLocation ($4));
+               $$ = u;
          }
        ;
        
@@ -5916,7 +5915,7 @@ opt_query_continuation
 
 interactive_parsing
        : EVAL_STATEMENT_PARSER EOF 
-       | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives 
+       | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
        | EVAL_STATEMENT_PARSER { 
                Evaluator.LoadAliases (current_namespace);
 
@@ -6150,7 +6149,7 @@ public CSharpParser (SeekableStreamReader reader, CompilationUnit file, Compiler
 
        this.file = file;
        this.compiler = ctx;
-       current_namespace = new NamespaceEntry (null, file, null);
+       current_namespace = new NamespaceEntry (ctx, null, file, null);
        current_class = current_namespace.SlaveDeclSpace;
        current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
        oob_stack.Clear ();
@@ -6202,11 +6201,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 +6304,6 @@ public NamespaceEntry CurrentNamespace {
        }
 }
 
-
 void Error_SyntaxError (int token)
 {
        Error_SyntaxError (0, token, "Unexpected symbol");
@@ -6318,20 +6311,34 @@ void Error_SyntaxError (int token)
 
 void Error_SyntaxError (int error_code, int token, string msg)
 {
+       // An error message has been reported by tokenizer
+       if (token == Token.ERROR)
+               return;
+
        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 ()