2009-06-23 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / cs-parser.jay
index 6a9e15e022de4b24c9bc7d3cba681a7e540462ea..e7390c8dfbf638f7c8efb409b77249564ef35c81 100644 (file)
@@ -119,9 +119,9 @@ namespace Mono.CSharp
                bool global_attrs_enabled = true;
                bool has_get, has_set;
                bool parameter_modifiers_not_allowed;
-               bool params_modifiers_not_allowed;
+               bool complex_parameters_modifiers_not_allowed;
                bool arglist_allowed;
-
+               bool default_parameter_used;
 
                /// When using the interactive parser, this holds the
                /// resulting expression
@@ -330,6 +330,17 @@ namespace Mono.CSharp
 %token EVAL_COMPILATION_UNIT_PARSER
 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
 
+// 
+// This token is generated to trigger the completion engine at this point
+//
+%token GENERATE_COMPLETION
+
+//
+// This token is return repeatedly after the first GENERATE_COMPLETION
+// token is produced and before the final EOF
+//
+%token COMPLETE_COMPLETION
+
 /* Add precedence rules to solve dangling else s/r conflict */
 %nonassoc IF
 %nonassoc ELSE
@@ -359,7 +370,7 @@ compilation_unit
         | outer_declarations global_attributes opt_EOF
         | global_attributes opt_EOF
        | opt_EOF /* allow empty files */
-       | interactive_parsing opt_EOF
+       | interactive_parsing  { Lexer.CompleteOnEOF = false; } opt_EOF
        ;
 
 opt_EOF
@@ -643,7 +654,7 @@ attribute_sections
 
                        if (global_attrs_enabled) {
                                if (current_attr_target == "module") {
-                                       CodeGen.Module.AddAttributes (sect);
+                                       current_container.Module.AddAttributes (sect);
                                        $$ = null;
                                } else if (current_attr_target != null && current_attr_target.Length > 0) {
                                        CodeGen.Assembly.AddAttributes (sect);
@@ -674,7 +685,7 @@ attribute_sections
 
                        if (global_attrs_enabled) {
                                if (current_attr_target == "module") {
-                                       CodeGen.Module.AddAttributes (sect);
+                                       current_container.Module.AddAttributes (sect);
                                        $$ = null;
                                } else if (current_attr_target == "assembly") {
                                        CodeGen.Assembly.AddAttributes (sect);
@@ -756,7 +767,7 @@ attribute
          {
                ++lexer.parsing_block;
          }
-        opt_attribute_arguments
+         opt_attribute_arguments
          {
                --lexer.parsing_block;
                MemberName mname = (MemberName) $1;
@@ -796,78 +807,68 @@ opt_attribute_arguments
 
 
 attribute_arguments
-       : opt_positional_argument_list
-         {
-               if ($1 == null)
-                       $$ = null;
-               else {
-                       $$ = new object [] { $1, null };
-               }
-         }
-    | positional_argument_list COMMA named_argument_list
+       : /* empty */           { $$ = null; } 
+       | positional_or_named_argument
          {
-               $$ = new object[] { $1, $3 };
+               ArrayList a = new ArrayList (4);
+               a.Add ($1);
+               $$ = new object [] { a, null };
          }
-    | named_argument_list
+       | named_attribute_argument
          {
-               $$ = new object [] { null, $1 };
+               ArrayList a = new ArrayList (4);
+               a.Add ($1);  
+               $$ = new object [] { null, a };
          }
-    ;
-
-
-opt_positional_argument_list
-       : /* empty */           { $$ = null; } 
-       | positional_argument_list
-       ;
-
-positional_argument_list
-       : expression
+    | attribute_arguments COMMA positional_or_named_argument
          {
-               ArrayList args = new ArrayList (4);
-               args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
-
-               $$ = args;
+               object[] o = (object[]) $1;
+               if (o [1] != null) {
+                       Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
+                       o [0] = new ArrayList (4);
+               }
+               
+               ArrayList args = ((ArrayList) o [0]);
+               if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
+                       Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
+               
+               args.Add ($3);
          }
-        | positional_argument_list COMMA expression
-        {
-               ArrayList args = (ArrayList) $1;
-               args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
-
-               $$ = args;
-        }
-        ;
-
-named_argument_list
-       : named_argument
+    | attribute_arguments COMMA named_attribute_argument
          {
-               ArrayList args = new ArrayList (4);
-               args.Add ($1);
+               object[] o = (object[]) $1;
+               if (o [1] == null) {
+                       o [1] = new ArrayList (4);
+               }
 
-               $$ = args;
+               ((ArrayList) o [1]).Add ($3);
          }
-        | named_argument_list COMMA named_argument
-         {       
-               ArrayList args = (ArrayList) $1;
-               args.Add ($3);
+    ;
 
-               $$ = args;
-         }
-       | named_argument_list COMMA expression
+positional_or_named_argument
+       : expression
          {
-               Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
-               $$ = null;
+               $$ = new Argument ((Expression) $1);
          }
+       | named_argument
        ;
 
-named_argument
+named_attribute_argument
        : IDENTIFIER ASSIGN expression
          {
-               // FIXME: keep location
-               $$ = new DictionaryEntry (
-                       ((LocatedToken) $1).Value, 
-                       new Argument ((Expression) $3, Argument.AType.Expression));
+               $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3);      
          }
        ;
+       
+named_argument
+       : IDENTIFIER COLON expression
+         {
+               if (RootContext.Version <= LanguageVersion.V_3)
+                       Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
+                       
+               $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3);
+         }       
+       ;       
 
                  
 class_body
@@ -1312,18 +1313,23 @@ method_header
          opt_modifiers
          PARTIAL
          VOID method_declaration_name
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
+         OPEN_PARENS
+         {
+               arglist_allowed = true;
+         }
+         opt_formal_parameter_list CLOSE_PARENS 
          {
                lexer.ConstraintsParsing = true;
          }
          opt_type_parameter_constraints_clauses
          {
                lexer.ConstraintsParsing = false;
+               arglist_allowed = false;
 
                MemberName name = (MemberName) $5;
-               current_local_parameters = (ParametersCompiled) $7;
+               current_local_parameters = (ParametersCompiled) $8;
 
-               if ($9 != null && name.TypeArguments == null)
+               if ($10 != null && name.TypeArguments == null)
                        Report.Error (80, lexer.Location,
                                      "Constraints are not allowed on non-generic declarations");
 
@@ -1333,7 +1339,7 @@ method_header
                        generic = new GenericMethod (current_namespace, current_class, name,
                                                     TypeManager.system_void_expr, current_local_parameters);
 
-                       generic.SetParameterInfo ((ArrayList) $10);
+                       generic.SetParameterInfo ((ArrayList) $11);
                }
 
                int modifiers = (int) $2;
@@ -1352,7 +1358,7 @@ method_header
                        Report.Error (751, name.Location, "A partial method must be declared within a " +
                                "partial class or partial struct");
                }
-
+               
                modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
                
                method = new Method (current_class, generic, TypeManager.system_void_expr,
@@ -1410,7 +1416,7 @@ opt_parameter_list_no_mod
        ;
 
 formal_parameter_list
-       : fixed_parameters              
+       : fixed_parameters
          { 
                ArrayList pars_list = (ArrayList) $1;
 
@@ -1475,17 +1481,23 @@ fixed_parameters
        : fixed_parameter       
          {
                ArrayList pars = new ArrayList (4);
-
-               pars.Add ($1);
+               Parameter p = (Parameter) $1;
+               pars.Add (p);
+               
+               default_parameter_used = p.HasDefaultValue;
                $$ = pars;
          }
        | fixed_parameters COMMA fixed_parameter
          {
                ArrayList pars = (ArrayList) $1;
-               Parameter p = (Parameter)$3;
+               Parameter p = (Parameter) $3;
                if (p != null) {
                        if (p.HasExtensionMethodModifier)
                                Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
+                       else if (!p.HasDefaultValue && default_parameter_used)
+                               Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
+
+                       default_parameter_used |= p.HasDefaultValue;
                        pars.Add (p);
                }
                $$ = $1;
@@ -1513,16 +1525,11 @@ fixed_parameter
        | opt_attributes
          opt_parameter_modifier
          type
+         error
          {
-               Report.Error (1001, GetLocation ($3), "Identifier expected");
-               $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, lexer.Location);               
-         }
-       | opt_attributes
-         opt_parameter_modifier
-         type
-         error {
-               CheckIdentifierToken (yyToken, GetLocation ($4));
-               $$ = null;
+               Location l = GetLocation ($4);
+               CheckIdentifierToken (yyToken, l);
+               $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
          }
        | opt_attributes
          opt_parameter_modifier
@@ -1530,11 +1537,39 @@ fixed_parameter
          IDENTIFIER
          ASSIGN
          constant_expression
-          {
+         {
+               if (RootContext.Version <= LanguageVersion.V_3) {
+                       Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
+               }
+               
+               Parameter.Modifier mod = (Parameter.Modifier) $2;
+               if (mod != Parameter.Modifier.NONE) {
+                       switch (mod) {
+                       case Parameter.Modifier.REF:
+                       case Parameter.Modifier.OUT:
+                               Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
+                                       Parameter.GetModifierSignature (mod));
+                               break;
+                               
+                       case Parameter.Modifier.This:
+                               Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
+                                       Parameter.GetModifierSignature (mod));
+                               break;
+                       default:
+                               throw new NotImplementedException (mod.ToString ());
+                       }
+                               
+                       mod = Parameter.Modifier.NONE;
+               }
+               
+               if (complex_parameters_modifiers_not_allowed)
+                       Report.Error (1065, GetLocation ($6), "Optional parameter is not valid in this context");
+               
                LocatedToken lt = (LocatedToken) $4;
-               Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
-                $$ = null;
-          }
+               $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
+               if ($6 != null)
+                       ((Parameter) $$).DefaultValue = (Expression) $6;
+         }
        ;
 
 opt_parameter_modifier
@@ -1599,10 +1634,17 @@ parameter_modifier
 
 parameter_array
        : opt_attributes params_modifier type IDENTIFIER
-         { 
+         {
                LocatedToken lt = (LocatedToken) $4;
                $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
          }
+       | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
+         {
+               Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
+               
+               LocatedToken lt = (LocatedToken) $4;
+               $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);            
+         }
        | opt_attributes params_modifier type error {
                CheckIdentifierToken (yyToken, GetLocation ($4));
                $$ = null;
@@ -1612,7 +1654,7 @@ parameter_array
 params_modifier
        : PARAMS
          {
-               if (params_modifiers_not_allowed)
+               if (complex_parameters_modifiers_not_allowed)
                        Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
          }
        | PARAMS parameter_modifier
@@ -1936,11 +1978,11 @@ operator_type
 operator_declarator
        : operator_type OPERATOR overloadable_operator OPEN_PARENS
          {
-               params_modifiers_not_allowed = true;
+               complex_parameters_modifiers_not_allowed = true;
          }
          opt_parameter_list_no_mod CLOSE_PARENS
          {
-               params_modifiers_not_allowed = false;
+               complex_parameters_modifiers_not_allowed = false;
 
                Location loc = (Location) $2;
                Operator.OpType op = (Operator.OpType) $3;
@@ -2011,11 +2053,11 @@ overloadable_operator
 conversion_operator_declarator
        : IMPLICIT OPERATOR type OPEN_PARENS
          {
-               params_modifiers_not_allowed = true;
+               complex_parameters_modifiers_not_allowed = true;
          }
          opt_parameter_list_no_mod CLOSE_PARENS
          {
-               params_modifiers_not_allowed = false;
+               complex_parameters_modifiers_not_allowed = false;
 
                Location loc = (Location) $2;
                current_local_parameters = (ParametersCompiled)$6;  
@@ -2029,11 +2071,11 @@ conversion_operator_declarator
          }
        | EXPLICIT OPERATOR type OPEN_PARENS
          {
-               params_modifiers_not_allowed = true;
+               complex_parameters_modifiers_not_allowed = true;
          }
          opt_parameter_list_no_mod CLOSE_PARENS
          {
-               params_modifiers_not_allowed = false;
+               complex_parameters_modifiers_not_allowed = false;
                
                Location loc = (Location) $2;
                current_local_parameters = (ParametersCompiled)$6;  
@@ -2084,9 +2126,11 @@ constructor_declarator
                        tmpComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
+               arglist_allowed = true;
          }
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          {
+               arglist_allowed = false;
                current_local_parameters = (ParametersCompiled) $6;  
                
                //
@@ -2356,8 +2400,13 @@ indexer_declaration
                implicit_value_parameter_type = (FullNamedExpression) $3;
                indexer_parameters = (ParametersCompiled) $6;
                
-               if (indexer_parameters.IsEmpty)
+               if (indexer_parameters.IsEmpty) {
                        Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
+               } else if (indexer_parameters.Count == 1) {
+                       Parameter p = indexer_parameters [0];
+                       if (p.HasDefaultValue)
+                               p.Warning_UselessOptionalParameter ();
+               }
 
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
@@ -2590,7 +2639,9 @@ opt_nullable
          }
        | INTERR_NULLABLE
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
+               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
+                       Report.FeatureIsNotSupported (lexer.Location, "nullable types");
+               else if (RootContext.Version < LanguageVersion.ISO_2)
                        Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
          
                $$ = this;
@@ -2632,7 +2683,9 @@ opt_type_argument_list
        : /* empty */                { $$ = null; } 
        | OP_GENERICS_LT type_arguments OP_GENERICS_GT
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
+               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
+                       Report.FeatureIsNotSupported (lexer.Location, "generics");
+               else if (RootContext.Version < LanguageVersion.ISO_2)
                        Report.FeatureIsNotAvailable (GetLocation ($1), "generics");      
          
                $$ = $2;
@@ -2732,7 +2785,9 @@ opt_type_parameter_list
        : /* empty */                { $$ = null; } 
        | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
+               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
+                       Report.FeatureIsNotSupported (lexer.Location, "generics");
+               else if (RootContext.Version < LanguageVersion.ISO_2)
                        Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
          
                $$ = $2;
@@ -2758,7 +2813,7 @@ type_parameter
        : opt_attributes opt_type_parameter_variance IDENTIFIER
          {
                LocatedToken lt = (LocatedToken)$3;
-               $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance)$2, lt.Location);
+               $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
          }
        | error
          {
@@ -2827,8 +2882,7 @@ type_expression
                if ($2 != null) {
                        $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
                } else {
-                       if (name.Left == null && name.Name == "var" &&
-                           (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
+                       if (name.Left == null && name.Name == "var" && RootContext.Version > LanguageVersion.ISO_2)
                                $$ = current_array_type = new VarExpr (name.Location);
                        else
                                $$ = name.GetTypeExpression ();
@@ -2933,6 +2987,10 @@ primary_expression_no_array_creation
                LocatedToken lt = (LocatedToken) $1;
                $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);          
          }
+       | IDENTIFIER GENERATE_COMPLETION {
+               LocatedToken lt = (LocatedToken) $1;
+              $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
+         }
        | parenthesized_expression
        | default_value_expression
        | member_access
@@ -3006,6 +3064,10 @@ parenthesized_expression
          {
                $$ = new ParenthesizedExpression ((Expression) $2);
          }
+       | OPEN_PARENS expression COMPLETE_COMPLETION
+         {
+               $$ = new ParenthesizedExpression ((Expression) $2);
+         }
        ;
        
 member_access
@@ -3027,6 +3089,22 @@ member_access
 
                $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
          }
+       | primary_expression DOT GENERATE_COMPLETION {
+               $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
+         }
+       | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
+               LocatedToken lt = (LocatedToken) $3;
+               $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
+         }
+       | predefined_type DOT GENERATE_COMPLETION
+         {
+               // TODO: Location is wrong as some predefined types doesn't hold a location
+               $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
+         }
+       | predefined_type DOT IDENTIFIER GENERATE_COMPLETION {
+               LocatedToken lt = (LocatedToken) $3;
+               $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
+         }
        ;
 
 invocation_expression
@@ -3042,12 +3120,12 @@ opt_object_or_collection_initializer
        ;
 
 object_or_collection_initializer
-       : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
+       : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
          {
                if ($2 == null)
-                 $$ = CollectionOrObjectInitializers.Empty;
+                       $$ = CollectionOrObjectInitializers.Empty;
                else
-                 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
+                       $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
          }
        | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
          {
@@ -3064,7 +3142,7 @@ opt_member_initializer_list
        ;
 
 member_initializer_list
-       : member_initializer
+       : member_initializer 
          {
                ArrayList a = new ArrayList ();
                a.Add ($1);
@@ -3084,9 +3162,16 @@ member_initializer
                LocatedToken lt = $1 as LocatedToken;
                $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
          }
-       | non_assignment_expression
+       | GENERATE_COMPLETION 
          {
-               $$ = new CollectionElementInitializer ((Expression)$1);
+               $$ = new CompletionElementInitializer (null, GetLocation ($1));
+         }
+       | non_assignment_expression opt_COMPLETE_COMPLETION  {
+               CompletionSimpleName csn = $1 as CompletionSimpleName;
+               if (csn == null)
+                       $$ = new CollectionElementInitializer ((Expression)$1);
+               else
+                       $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
          }
        | OPEN_BRACE expression_list CLOSE_BRACE
          {
@@ -3118,6 +3203,9 @@ argument_list
        | argument_list COMMA argument
          {
                ArrayList list = (ArrayList) $1;
+               if (!($3 is NamedArgument) && list [list.Count - 1] is NamedArgument)
+                       Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
+               
                list.Add ($3);
                $$ = list;
          }
@@ -3136,12 +3224,10 @@ argument_list
 argument
        : expression
          {
-               $$ = new Argument ((Expression) $1, Argument.AType.Expression);
+               $$ = new Argument ((Expression) $1);
          }
        | non_simple_argument
-         {
-               $$ = $1;
-         }
+       | named_argument        
        ;
 
 non_simple_argument
@@ -3159,21 +3245,20 @@ non_simple_argument
                Argument[] args = new Argument [list.Count];
                list.CopyTo (args, 0);
 
-               Expression expr = new Arglist (args, (Location) $1);
-               $$ = new Argument (expr, Argument.AType.Expression);
+               $$ = new Argument (new Arglist (args, (Location) $1));
          }
        | ARGLIST open_parens_any CLOSE_PARENS
          {
-               $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
+               $$ = new Argument (new Arglist ((Location) $1));
          }       
        | ARGLIST
          {
-               $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
+               $$ = new Argument (new ArglistAccess ((Location) $1));
          }
        ;
 
 variable_reference
-       : expression { note ("section 5.4"); $$ = $1; }
+       : expression
        ;
 
 element_access
@@ -3326,7 +3411,9 @@ new_expr_start
 anonymous_type_expression
        : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
          {
-               if (RootContext.Version <= LanguageVersion.ISO_2)
+               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
+                       Report.FeatureIsNotSupported (lexer.Location, "anonymous types");
+               else if (RootContext.Version <= LanguageVersion.ISO_2)
                        Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
 
                $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
@@ -3560,7 +3647,9 @@ unbound_type_name
 generic_dimension
        : GENERIC_DIMENSION
          {
-               if (RootContext.Version < LanguageVersion.ISO_2)
+               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
+                       Report.FeatureIsNotSupported (lexer.Location, "generics");
+               else if (RootContext.Version < LanguageVersion.ISO_2)
                        Report.FeatureIsNotAvailable (lexer.Location, "generics");
 
                $$ = $1;
@@ -3631,11 +3720,11 @@ opt_anonymous_method_signature
 anonymous_method_signature
        : OPEN_PARENS
          {
-               params_modifiers_not_allowed = true; 
+               complex_parameters_modifiers_not_allowed = true; 
          }
          opt_formal_parameter_list CLOSE_PARENS
          {
-               params_modifiers_not_allowed = false;
+               complex_parameters_modifiers_not_allowed = false;
                $$ = $3;
          }
        ;
@@ -4010,8 +4099,8 @@ lambda_expression
        ;
 
 expression
-       : assignment_expression
-       | non_assignment_expression
+       : assignment_expression 
+       | non_assignment_expression 
        ;
        
 non_assignment_expression
@@ -4195,8 +4284,11 @@ opt_type_parameter_variance
          }
        | type_parameter_variance
          {
-               if (RootContext.Version < LanguageVersion.Future)
-                       Report.FeatureIsNotAvailable (lexer.Location, "generic variance");
+               if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)        
+                       Report.FeatureIsNotSupported (lexer.Location, "generic type variance");
+               else if (RootContext.Version <= LanguageVersion.V_3)
+                       Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
+
                $$ = $1;
          }
        ;
@@ -4231,13 +4323,26 @@ block
                ++lexer.parsing_block;
                start_block ((Location) $1);
          } 
-         opt_statement_list CLOSE_BRACE 
+         opt_statement_list block_end
+         {
+               $$ = $4;
+          }
+       ;
+
+block_end 
+       : CLOSE_BRACE 
          {
                --lexer.parsing_block;
-               $$ = end_block ((Location) $4);
+               $$ = end_block ((Location) $1);
+         }
+       | COMPLETE_COMPLETION
+         {
+               --lexer.parsing_block;
+               $$ = end_block (lexer.Location);
          }
        ;
 
+
 block_prepared
        : OPEN_BRACE
          {
@@ -4427,8 +4532,7 @@ variable_type
                        //
                        if (rank_or_nullable.Length == 0) {
                                SimpleName sn = expr as SimpleName;
-                               if (sn != null && sn.Name == "var" &&
-                                   (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
+                               if (sn != null && sn.Name == "var" && RootContext.Version > LanguageVersion.ISO_2)
                                        $$ = current_array_type = new VarExpr (sn.Location);
                                else
                                        $$ = $1;
@@ -4523,10 +4627,12 @@ local_constant_declaration
 
 expression_statement
        : statement_expression SEMICOLON { $$ = $1; }
+       | statement_expression COMPLETE_COMPLETION { $$ = $1; }
        ;
 
 interactive_expression_statement
        : interactive_statement_expression SEMICOLON { $$ = $1; }
+       | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
        ;
 
        //
@@ -5655,7 +5761,7 @@ interactive_parsing
                ++lexer.parsing_block;
                start_block (lexer.Location);
          }             
-         interactive_statement_list
+         interactive_statement_list opt_COMPLETE_COMPLETION
          {
                --lexer.parsing_block;
                Method method = (Method) oob_stack.Pop ();
@@ -5679,6 +5785,16 @@ interactive_compilation_unit
        | global_attributes 
        | /* nothing */
        ;
+
+opt_COMPLETE_COMPLETION
+       : /* nothing */
+       | COMPLETE_COMPLETION
+       ;
+
+close_brace_or_complete_completion
+       : CLOSE_BRACE
+       | COMPLETE_COMPLETION
+       ;
 %%
 
 // <summary>
@@ -5742,7 +5858,7 @@ struct OperatorDeclaration {
        }
 }
 
-void Error_ExpectingTypeName (Expression expr)
+static void Error_ExpectingTypeName (Expression expr)
 {
        if (expr is Invocation){
                Report.Error (1002, expr.Location, "Expecting `;'");
@@ -5768,6 +5884,11 @@ static void Error_TypeExpected (Location loc)
        Report.Error (1031, loc, "Type expected");
 }
 
+static void Error_NamedArgumentExpected (NamedArgument a)
+{
+       Report.Error (1738, a.Name.Location, "Named arguments must appear after the positional arguments");
+}
+
 void push_current_class (TypeContainer tc, object partial_token)
 {
        if (RootContext.EvalMode){
@@ -5963,11 +6084,6 @@ void syntax_error (Location l, string msg)
        Report.Error (1003, l, "Syntax error, " + msg);
 }
 
-void note (string s)
-{
-       // Used to put annotations
-}
-
 Tokenizer lexer;
 
 public Tokenizer Lexer {
@@ -6439,7 +6555,7 @@ static string GetTokenName (int token)
        case Token.WHILE:
                return "while";
        case Token.ARGLIST:
-               return "arglist";
+               return "__arglist";
        case Token.PARTIAL:
                return "partial";
        case Token.ARROW:
@@ -6584,7 +6700,9 @@ static string GetTokenName (int token)
        case Token.EVAL_COMPILATION_UNIT_PARSER:
        case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
        case Token.EVAL_STATEMENT_PARSER:
-       case Token.LAST_KEYWORD:        
+       case Token.LAST_KEYWORD:
+       case Token.GENERATE_COMPLETION:
+       case Token.COMPLETE_COMPLETION:
                return "<internal>";
 
                // A bit more robust.