Browse Source

Fixed parsing of some incomplete statements.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
3d551edce2
  1. 15
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  2. 6810
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  3. 33
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
  4. 11
      ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs

15
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -1353,7 +1353,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1353,7 +1353,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IfElseStatement.Roles.LPar);
result.AddChild ((Expression)ifStatement.Expr.Accept (this), IfElseStatement.Roles.Condition);
if (location != null)
if (location != null && location.Count > 1)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), IfElseStatement.Roles.RPar);
if (ifStatement.TrueStatement != null)
@ -1376,10 +1376,11 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1376,10 +1376,11 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild ((Statement)doStatement.EmbeddedStatement.Accept (this), WhileStatement.Roles.EmbeddedStatement);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), "while".Length), DoWhileStatement.WhileKeywordRole);
if (location != null)
if (location != null && location.Count > 1)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), DoWhileStatement.Roles.LPar);
result.AddChild ((Expression)doStatement.expr.Accept (this), DoWhileStatement.Roles.Condition);
if (location != null) {
if (doStatement.expr != null)
result.AddChild ((Expression)doStatement.expr.Accept (this), DoWhileStatement.Roles.Condition);
if (location != null && location.Count > 2) {
result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), DoWhileStatement.Roles.RPar);
result.AddChild (new CSharpTokenNode (Convert (location[3]), 1), DoWhileStatement.Roles.Semicolon);
}
@ -1848,8 +1849,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1848,8 +1849,10 @@ namespace ICSharpCode.NRefactory.CSharp
result.AddChild (new CSharpTokenNode (Convert (tryCatchStatement.loc), "try".Length), TryCatchStatement.TryKeywordRole);
if (tryCatchStatement.Block != null)
result.AddChild ((BlockStatement)tryCatchStatement.Block.Accept (this), TryCatchStatement.TryBlockRole);
foreach (Catch ctch in tryCatchStatement.Specific) {
result.AddChild (ConvertCatch (ctch), TryCatchStatement.CatchClauseRole);
if (tryCatchStatement.Specific != null) {
foreach (Catch ctch in tryCatchStatement.Specific) {
result.AddChild (ConvertCatch (ctch), TryCatchStatement.CatchClauseRole);
}
}
if (tryCatchStatement.General != null)
result.AddChild (ConvertCatch (tryCatchStatement.General), TryCatchStatement.CatchClauseRole);

6810
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs

File diff suppressed because it is too large Load Diff

33
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay

@ -151,19 +151,6 @@ namespace Mono.CSharp @@ -151,19 +151,6 @@ namespace Mono.CSharp
List<Location> attributeCommas = new List<Location> ();
List<Location> attributeArgumentCommas = new List<Location> ();
List<Location> parameterListCommas = new List<Location> ();
object lastYYVal;
// Can be used for code completion to get the last valid expression before an error.
// needs a hack in yyparse to make it work add
// lastYYVal = yyVal;
// after the big switch/case (somewhere around line 3915)
public object LastYYVal {
get {
return lastYYVal;
}
}
%}
%token EOF
@ -5165,6 +5152,12 @@ if_statement @@ -5165,6 +5152,12 @@ if_statement
if ($7 is EmptyStatement)
Warning_EmptyStatement (GetLocation ($7));
}
| IF open_parens_any boolean_expression error {
var eloc = GetLocation ($3);
report.Error (1026, eloc, "Expected a ')'");
$$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($2));
}
;
switch_statement
@ -5276,6 +5269,18 @@ do_statement @@ -5276,6 +5269,18 @@ do_statement
$$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
}
| DO embedded_statement error
{
var loc = GetLocation ($1);
report.Error (-100, loc, "Expected `while'");
$$ = new Do ((Statement) $2, null, loc);
}
| DO embedded_statement
WHILE open_parens_any boolean_expression error
{
$$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
}
;
for_statement
@ -5521,7 +5526,7 @@ try_statement @@ -5521,7 +5526,7 @@ try_statement
| TRY block error
{
report.Error (1524, GetLocation ($1), "Expected catch or finally");
$$ = null;
$$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
}
;

11
ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs

@ -5207,11 +5207,12 @@ namespace Mono.CSharp { @@ -5207,11 +5207,12 @@ namespace Mono.CSharp {
this.Block = block;
this.Specific = catch_clauses;
this.inside_try_finally = inside_try_finally;
Catch c = catch_clauses [0];
if (c.IsGeneral) {
this.General = c;
catch_clauses.RemoveAt (0);
if (catch_clauses != null) {
Catch c = catch_clauses [0];
if (c.IsGeneral) {
this.General = c;
catch_clauses.RemoveAt (0);
}
}
}

Loading…
Cancel
Save