[mcs] C#7 throw expression
[mono.git] / mcs / mcs / cs-parser.jay
index d3d6671a8404480c891eff1898f50cf335f2745e..153a6bc7bdba4d8cc56dca48f8c9396ed3e00df3 100644 (file)
@@ -219,7 +219,7 @@ namespace Mono.CSharp
 %token STRUCT  
 %token SWITCH  
 %token THIS    
-%token THROW   
+%token THROW
 %token TRUE    
 %token TRY     
 %token TYPEOF  
@@ -261,6 +261,7 @@ namespace Mono.CSharp
 %token WHEN
 %token INTERPOLATED_STRING
 %token INTERPOLATED_STRING_END
+%token THROW_EXPR
 
 /* C# keywords which are not really keywords */
 %token GET
@@ -400,6 +401,17 @@ outer_declaration
          }
        | opt_extern_alias_directives opt_using_directives attribute_sections
          {
+               Attributes attrs = (Attributes) $3;
+               if (attrs != null) {
+                       foreach (var a in attrs.Attrs) {
+                               if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
+                                       continue;
+
+                               if (a.ExplicitTarget == null)
+                                       report.Error (-1671, a.Location, "Global attributes must have attribute target specified");
+                       }
+               }
+
                module.AddAttributes ((Attributes) $3, current_namespace);
          }
        | error
@@ -1818,9 +1830,9 @@ property_declaration
          accessor_declarations 
          {
                lexer.PropertyParsing = false;
-               
+
                if (doc_support)
-                       current_property.DocComment = ConsumeStoredComment ();                          
+                       current_property.DocComment = ConsumeStoredComment ();
          }
          CLOSE_BRACE
          {
@@ -1858,6 +1870,9 @@ property_declaration
                if (type.Type != null && type.Type.Kind == MemberKind.Void)
                        report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
 
+               if (doc_support)
+                       property.DocComment = ConsumeStoredComment ();
+
                current_type.AddMember (property);
 
                current_local_parameters = null;
@@ -1879,6 +1894,9 @@ opt_property_initializer
                lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
                end_block (GetLocation ($4));
                current_local_parameters = null;
+
+               if (doc_support)
+                       Lexer.doc_state = XmlCommentState.Allowed;
          }
        ;
 
@@ -2056,7 +2074,8 @@ set_accessor_declaration
        ;
 
 accessor_body
-       : block 
+       : block
+       | expression_block
        | SEMICOLON
          {
                // TODO: lbag
@@ -2069,6 +2088,7 @@ accessor_body
          }
        ;
 
+
 interface_declaration
        : opt_attributes
          opt_modifiers
@@ -2725,7 +2745,8 @@ event_accessor_block
                report.Error (73, lexer.Location, "An add or remove accessor must have a body");
                $$ = null;
          }
-       | block;
+       | block
+       | expression_block
        ;
 
 attributes_without_members
@@ -3334,10 +3355,16 @@ boolean_literal
 interpolated_string
        : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
          {
+               if (lang_version < LanguageVersion.V_6)
+                       FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
+
                $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
          }
        | INTERPOLATED_STRING_END
          {
+               if (lang_version < LanguageVersion.V_6)
+                       FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
+
                $$ = new InterpolatedString ((StringLiteral) $1, null, null);
          }
        ;
@@ -3901,7 +3928,10 @@ array_creation_expression
                $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
                                new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
                                        Next = (ComposedTypeSpecifier) $6
-                               }, (ArrayInitializer) $7, GetLocation ($1));
+                               }, (ArrayInitializer) $7, GetLocation ($1)) {
+                       NoEmptyInterpolation = true
+               };
+
                lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
          }
        | NEW new_expr_type rank_specifiers opt_array_initializer
@@ -3909,7 +3939,9 @@ array_creation_expression
                if ($4 == null)
                        report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
 
-               $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
+               $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) {
+                       NoEmptyInterpolation = true
+               };
          }
        | NEW rank_specifier array_initializer
          {
@@ -4279,6 +4311,13 @@ unary_expression
                
                $$ = new Await ((Expression) $2, GetLocation ($1));
          }
+       | THROW_EXPR prefixed_unary_expression
+         {
+               if (lang_version < LanguageVersion.V_7)
+                       FeatureIsNotAvailable (lexer.Location, "throw expression");
+
+               $$ = new ThrowExpression ((Expression) $2, GetLocation ($1));
+         }
        | BANG error
          {
                Error_SyntaxError (yyToken);
@@ -6335,11 +6374,16 @@ return_statement
        ;
 
 throw_statement
-       : THROW opt_expression SEMICOLON
+       : THROW expression SEMICOLON
          {
                $$ = new Throw ((Expression) $2, GetLocation ($1));
                lbag.AddStatement ($$, GetLocation ($3));
          }
+       | THROW SEMICOLON
+         {
+               $$ = new Throw (null, GetLocation ($1));
+               lbag.AddStatement ($$, GetLocation ($2));
+         }
        | THROW expression error
          {
                Error_SyntaxError (yyToken);
@@ -8050,6 +8094,7 @@ static string GetTokenName (int token)
        case Token.THIS:
                return "this";
        case Token.THROW:
+       case Token.THROW_EXPR:
                return "throw";
        case Token.TRUE:
                return "true";