Permalink
Browse files

Better error message formatting.

  • Loading branch information...
1 parent b82797f commit 168ce136717d5fc5a6ab2a7795076ffa4b6bbaac @JamesDunne committed May 24, 2012
Showing with 13 additions and 10 deletions.
  1. +10 −10 WellDunne.ExpressionLibrary/ExpressionLibrary.cs
  2. +3 −0 WellDunne.Test/Program.cs
@@ -98,15 +98,15 @@ internal static string kindToString(TokenKind kind)
case TokenKind.Operator: return "operator";
case TokenKind.IntegerLiteral: return "integer";
case TokenKind.DecimalLiteral: return "decimal";
- case TokenKind.Null: return "null";
- case TokenKind.True: return "true";
- case TokenKind.False: return "false";
- case TokenKind.ParenOpen: return "(";
- case TokenKind.ParenClose: return ")";
- case TokenKind.BracketOpen: return "[";
- case TokenKind.BracketClose: return "]";
- case TokenKind.Comma: return ",";
- case TokenKind.StringLiteral: return "string";
+ case TokenKind.Null: return "'null'";
+ case TokenKind.True: return "'true'";
+ case TokenKind.False: return "'false'";
+ case TokenKind.ParenOpen: return "'('";
+ case TokenKind.ParenClose: return "')'";
+ case TokenKind.BracketOpen: return "'['";
+ case TokenKind.BracketClose: return "']'";
+ case TokenKind.Comma: return "','";
+ case TokenKind.StringLiteral: return "'string'";
default: return String.Format("<unknown token kind {0}>", kind.ToString());
}
}
@@ -792,7 +792,7 @@ private bool AdvanceOrError(string error)
private bool Check(TokenKind tokenKind)
{
if (Eof())
- return Error("Unexpected end of expression");
+ return Error("Unexpected end of expression while looking for {0}", Token.kindToString(tokenKind));
if (Current.Kind != tokenKind)
return Error("Expected {0} but found {1}", Token.kindToString(tokenKind), Current);
return true;
@@ -128,6 +128,9 @@ static void Main(string[] args)
@" f gt g",
@"(f gt g)"
);
+
+ Fails(@"b in [1,");
+ Fails(@"b in [1");
}
catch (Exception ex)
{

0 comments on commit 168ce13

Please sign in to comment.