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;
}
;
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;
}
| error
{
- syntax_error (lexer.Location, "`.' expected");
+ Error_SyntaxError (yyToken);
$$ = new MemberName ("<invalid>", lexer.Location);
}
;
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);
}
;
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
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
}
| opt_attributes params_modifier type error
{
- CheckIdentifierToken (yyToken, GetLocation ($4));
+ Error_SyntaxError (yyToken);
$$ = null;
}
;
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);
}
;
list.Add ((Expression) $3);
$$ = list;
}
- | error
- {
- Error_SyntaxError (yyToken);
- $$ = new List<Expression> ();
- }
;
typeof_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));
- }
;
//
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
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;
}
;
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);
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 ();
Report.Error (error, loc, msg);
}
-void CheckIdentifierToken (int yyToken, Location loc)
-{
- CheckToken (1041, yyToken, "Identifier expected", loc);
-}
-
string ConsumeStoredComment ()
{
string s = tmpComment;
}
}
-
void Error_SyntaxError (int token)
{
Error_SyntaxError (0, token, "Unexpected symbol");
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 ()