{
++lexer.parsing_block;
}
- opt_attribute_arguments
+ opt_attribute_arguments
{
--lexer.parsing_block;
MemberName mname = (MemberName) $1;
attribute_arguments
- : opt_positional_argument_list
+ : /* empty */ { $$ = null; }
+ | positional_or_named_argument
{
- if ($1 == null)
- $$ = null;
- else {
- $$ = new object [] { $1, null };
- }
+ ArrayList a = new ArrayList (4);
+ a.Add ($1);
+ $$ = new object [] { a, null };
}
- | positional_argument_list COMMA named_argument_list
+ | named_attribute_argument
{
- $$ = new object[] { $1, $3 };
+ ArrayList a = new ArrayList (4);
+ a.Add ($1);
+ $$ = new object [] { null, a };
}
- | named_argument_list
+ | attribute_arguments COMMA positional_or_named_argument
{
- $$ = new object [] { null, $1 };
- }
- ;
-
-
-opt_positional_argument_list
- : /* empty */ { $$ = null; }
- | positional_argument_list
- ;
-
-positional_argument_list
- : expression
- {
- 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
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");
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;
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,
Report.Error (1065, GetLocation ($6), "Optional parameter is not valid in this context");
LocatedToken lt = (LocatedToken) $4;
- $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, (Expression) $6, lt.Location);
+ $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
+ if ($6 != null)
+ ((Parameter) $$).DefaultValue = (Expression) $6;
}
;
} else if (indexer_parameters.Count == 1) {
Parameter p = indexer_parameters [0];
if (p.HasDefaultValue)
- Report.Warning (1066, 1, p.Location,
- "The default value specified for optional parameter 'i' will never be used",
- p.Name);
+ p.Warning_UselessOptionalParameter ();
}
if (RootContext.Documentation != null) {
| 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;
}
argument
: expression
{
- $$ = new Argument ((Expression) $1, Argument.AType.Expression);
+ $$ = new Argument ((Expression) $1);
}
| non_simple_argument
- {
- $$ = $1;
- }
+ | named_argument
;
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
}
}
-void Error_ExpectingTypeName (Expression expr)
+static void Error_ExpectingTypeName (Expression expr)
{
if (expr is Invocation){
Report.Error (1002, expr.Location, "Expecting `;'");
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){
Report.Error (1003, l, "Syntax error, " + msg);
}
-void note (string s)
-{
- // Used to put annotations
-}
-
Tokenizer lexer;
public Tokenizer Lexer {