%token STRUCT
%token SWITCH
%token THIS
-%token THROW
+%token THROW
%token TRUE
%token TRY
%token TYPEOF
%token WHEN
%token INTERPOLATED_STRING
%token INTERPOLATED_STRING_END
+%token THROW_EXPR
/* C# keywords which are not really keywords */
%token GET
}
| 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
$$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
lbag.AddLocation ($$, GetLocation($2));
}
+ | identifier_inside_body COLON OUT named_argument_expr_or_out_variable_declaration
+ {
+ if (lang_version <= LanguageVersion.V_3)
+ FeatureIsNotAvailable (GetLocation ($1), "named argument");
+
+ var lt = (LocatedToken) $1;
+ $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, Argument.AType.Out);
+ lbag.AddLocation ($$, GetLocation($2));
+ }
+
;
named_argument_expr
: expression_or_error
-// | declaration_expression
+ ;
+
+named_argument_expr_or_out_variable_declaration
+ : expression_or_error
+ | out_variable_declaration
;
opt_named_modifier
{
$$ = Argument.AType.Ref;
}
- | OUT
- {
- $$ = Argument.AType.Out;
- }
;
opt_class_member_declarations
accessor_declarations
{
lexer.PropertyParsing = false;
-
+
if (doc_support)
- current_property.DocComment = ConsumeStoredComment ();
+ current_property.DocComment = ConsumeStoredComment ();
}
CLOSE_BRACE
{
lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
end_block (GetLocation ($4));
current_local_parameters = null;
+
+ if (doc_support)
+ Lexer.doc_state = XmlCommentState.Allowed;
}
;
;
accessor_body
- : block
+ : block
+ | expression_block
| SEMICOLON
{
// TODO: lbag
}
;
+
interface_declaration
: opt_attributes
opt_modifiers
$$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
lbag.AddLocation ($$, GetLocation ($1));
}
- | COMMA IDENTIFIER ASSIGN
- {
- ++lexer.parsing_block;
- }
- event_variable_initializer
+ | COMMA IDENTIFIER ASSIGN event_variable_initializer
{
- --lexer.parsing_block;
var lt = (LocatedToken) $2;
- $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
+ $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $4);
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
}
;
if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
current_event_field.GetSignatureForError ());
- }
+ }
+
+ ++lexer.parsing_block;
+ current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
+ start_block (lexer.Location);
}
variable_initializer
{
$$ = $2;
+
+ --lexer.parsing_block;
+ end_block (lexer.Location);
+ current_local_parameters = null;
}
;
report.Error (73, lexer.Location, "An add or remove accessor must have a body");
$$ = null;
}
- | block;
+ | block
+ | expression_block
;
attributes_without_members
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);
}
;
$$ = new Argument ((Expression) $2, Argument.AType.Ref);
lbag.AddLocation ($$, GetLocation ($1));
}
- | REF declaration_expression
- {
- $$ = new Argument ((Expression) $2, Argument.AType.Ref);
- }
| OUT variable_reference
{
$$ = new Argument ((Expression) $2, Argument.AType.Out);
lbag.AddLocation ($$, GetLocation ($1));
}
- | OUT declaration_expression
+ | OUT out_variable_declaration
{
$$ = new Argument ((Expression) $2, Argument.AType.Out);
}
}
;
-declaration_expression
- : OPEN_PARENS declaration_expression CLOSE_PARENS
- {
- $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
- lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
- }
-/*
- | CHECKED open_parens_any declaration_expression CLOSE_PARENS
- {
- $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
- lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
- }
- | UNCHECKED open_parens_any declaration_expression CLOSE_PARENS
- {
- $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
- lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
- }
-*/
- | variable_type identifier_inside_body
+out_variable_declaration
+ : variable_type identifier_inside_body
{
- if (lang_version != LanguageVersion.Experimental)
- FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
+ if (lang_version < LanguageVersion.V_7)
+ FeatureIsNotAvailable (GetLocation ($1), "out variable declaration");
var lt = (LocatedToken) $2;
var lv = new LocalVariable (current_block, lt.Value, lt.Location);
current_block.AddLocalName (lv);
$$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
}
- | variable_type identifier_inside_body ASSIGN expression
- {
- if (lang_version != LanguageVersion.Experimental)
- FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
-
- var lt = (LocatedToken) $2;
- var lv = new LocalVariable (current_block, lt.Value, lt.Location);
- current_block.AddLocalName (lv);
- $$ = new DeclarationExpression ((FullNamedExpression) $1, lv) {
- Initializer = (Expression) $4
- };
- }
;
variable_reference
$$ = 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
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
{
$$ = 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);
{
var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
if ($4 != null) {
- if (lang_version != LanguageVersion.Experimental)
- FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
+ if (lang_version < LanguageVersion.V_7)
+ FeatureIsNotAvailable (GetLocation ($4), "pattern matching");
var lt = (LocatedToken) $4;
- is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
- current_block.AddLocalName (is_expr.Variable);
+ var lv = new LocalVariable (current_block, lt.Value, lt.Location);
+ is_expr.Variable = lv;
+ current_block.AddLocalName (lv);
}
$$ = is_expr;
$$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
lbag.AddLocation ($$, GetLocation ($4));
}
+ | null_coalescing_expression INTERR expression COLON THROW prefixed_unary_expression
+ {
+ if (lang_version < LanguageVersion.V_7)
+ FeatureIsNotAvailable (lexer.Location, "throw expression");
+
+ var expr = new ThrowExpression ((Expression) $6, GetLocation ($5));
+ $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, expr, GetLocation ($2));
+ lbag.AddLocation ($$, GetLocation ($4));
+ }
| null_coalescing_expression INTERR expression error
{
Error_SyntaxError (yyToken);
;
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);
}
}
-Block
-end_block (Location loc)
+Block end_block (Location loc)
{
Block retval = current_block.Explicit;
retval.SetEndLocation (loc);
case Token.THIS:
return "this";
case Token.THROW:
+ case Token.THROW_EXPR:
return "throw";
case Token.TRUE:
return "true";