private static AssertionError CreateVMError(ErrorInfo info) { var message = new StringBuilder(); var expression = String.Empty; var kind = String.Empty; var offenders = new List <string>(); var parts = new List <string>(); message.Append(ErrorKindString[info.Kind]); message.Append(": "); switch (info.Code) { case ErrorCode.BinaryOperationInvalidOperand: offenders.Add(Stringify.Object((Object)info.Offenders.First())); offenders.Add(Stringify.Opcode((byte)info.Offenders[1])); offenders.Add(Stringify.Object((Object)info.Offenders.Last())); expression = ComposeExpression(info, offenders, arrow: true); parts.Add(expression); parts.Add(Stringify.Kind(((Object)info.Offenders.First()).Kind)); break; } message.Append(ComposeErrorMessage(parts, ErrorMessages[info.Code])); return(new AssertionError(message.ToString())); }
private static AssertionError CreateParseError(ErrorInfo info) { var sb = new StringBuilder(); string kind = String.Empty; string expression; sb.Append(ErrorKindString[info.Kind]); sb.Append(": "); switch (info.Code) { case ErrorCode.ExpectedCommaToken: case ErrorCode.ExpectedColonToken: expression = ComposeExpression(info, arrow: true, placeholder: default(string)); break; case ErrorCode.MissingExpressionToken: expression = ComposeExpression(info, arrow: false, placeholder: DeterminePlaceholder(SyntaxKind.Int)); break; case ErrorCode.MissingLetAssignToken: expression = ComposeExpression(info, arrow: false, placeholder: default(string)); break; case ErrorCode.MissingColon: expression = ComposeExpression(info, arrow: false, placeholder: DeterminePlaceholder(SyntaxKind.Colon)); break; case ErrorCode.MissingComma: expression = ComposeExpression(info, arrow: false, placeholder: DeterminePlaceholder(SyntaxKind.Comma)); break; case ErrorCode.MissingOpeningToken: case ErrorCode.MissingClosingToken: expression = ComposeExpression(info, arrow: false, placeholder: DeterminePlaceholder((SyntaxKind)info.Offenders.First())); kind = Stringify.Kind((SyntaxKind)info.Offenders.First()); break; case ErrorCode.InvalidLetExpression: case ErrorCode.InvalidLetIdentifierToken: case ErrorCode.InvalidLetAssignToken: case ErrorCode.InvalidReturnExpression: case ErrorCode.InvalidToken: expression = ComposeExpression(info, arrow: true, placeholder: default(string)); break; default: expression = String.Empty; break; } List <string> offenders = new List <string> { expression }; if (kind != String.Empty) { offenders.Add(kind); } sb.Append(ComposeErrorMessage(offenders, ErrorMessages[info.Code])); return(new AssertionError(sb.ToString())); }
private static AssertionError CreateEvaluationError(ErrorInfo info) { List <string> offenders = new List <string>(); var sb = new StringBuilder(); sb.Append(ErrorKindString[info.Kind]); sb.Append(": "); switch (info.Code) { case ErrorCode.ArrayExpressionEvaluation: case ErrorCode.ArrayIndexExpressionEvaluation: case ErrorCode.HashIndexExpressionEvaluation: case ErrorCode.InfixExpressionEvaluation: offenders = new List <String> { Stringify.Object((Object)info.Offenders.First()), Stringify.Object((Object)info.Offenders.Last()) }; break; case ErrorCode.BangOperatorExpressionEvaluation: offenders = new List <String> { Stringify.Object((Object)info.Offenders.First()) }; break; case ErrorCode.IdentifierExpressionEvaluation: offenders = new List <String> { Stringify.Object(info.Offenders.First()) }; break; case ErrorCode.MinusOperatorExpressionEvaluation: offenders = new List <String> { Stringify.Object((Object)info.Offenders.First()), Stringify.Kind(((Object)info.Offenders.First()).Kind) }; break; case ErrorCode.InfixExpressionOperatorEvaluation: offenders = new List <String> { Stringify.Object((Object)info.Offenders.First()), ((Token)info.Offenders[1]).Literal, Stringify.Object((Object)info.Offenders.Last()) }; break; case ErrorCode.BooleanInfixExpressionEvaluation: case ErrorCode.StringExpressionOperatorEvaluation: offenders = new List <String> { Stringify.Object(info.Offenders.First()), ((Token)info.Offenders[1]).Literal, Stringify.Object(info.Offenders.Last()) }; break; case ErrorCode.BuiltInLenUnexpectedNoOfArguments: case ErrorCode.BuiltInFirstUnexpectedNoOfArguments: case ErrorCode.BuiltInLastUnexpectedNoOfArguments: case ErrorCode.BuiltInRestUnexpectedNoOfArguments: case ErrorCode.BuiltInPushUnexpectedNoOfArguments: offenders = new List <String> { info.Offenders.First().ToString() }; break; case ErrorCode.BuiltInLenInvalidArgument: case ErrorCode.BuiltInFirstInvalidArgument: case ErrorCode.BuiltInLastInvalidArgument: case ErrorCode.BuiltInRestInvalidArgument: offenders = new List <String> { info.Offenders.First().ToString(), Stringify.Object((Object)info.Offenders.Last()) }; break; case ErrorCode.BuiltInPushInvalidArgument: offenders = new List <String> { info.Offenders.First().ToString(), Stringify.Object((Object)info.Offenders[1]), Stringify.Object((Object)info.Offenders.Last()) }; break; case ErrorCode.UnknownOperator: offenders = new List <string> { ((Token)info.Offenders.First()).Literal }; break; } sb.Append(ComposeErrorMessage(offenders, ErrorMessages[info.Code])); return(new AssertionError(sb.ToString())); }