Permalink
Browse files

Fix edge case when an operator never correctly resolves

Fixes the error reporting for parsing strings in this form: "3++"
  • Loading branch information...
1 parent e689d4b commit bf22144027f51b420e26a6867faf136c5a456ade @davedelong committed Nov 21, 2011
Showing with 9 additions and 0 deletions.
  1. +1 −0 DDMathParser/DDTypes.h
  2. +8 −0 DDMathParser/_DDOperatorTerm.m
View
@@ -40,6 +40,7 @@ typedef enum {
DDErrorCodeBinaryOperatorMissingRightOperand, //@"no right operand to binary %@"
DDErrorCodeUnaryOperatorMissingLeftOperand, //@"no left operand to unary %@"
DDErrorCodeUnaryOperatorMissingRightOperand, //@"no right operand to unary %@"
+ DDErrorCodeOperatorMissingOperands, //@"missing operand(s) for operator: %@"
// evaluation errors
DDErrorCodeUnresolvedVariable, //@"unable to resolve variable expression: %@"
@@ -8,6 +8,7 @@
#import "_DDOperatorTerm.h"
#import "DDMathStringToken.h"
+#import "DDMathParserMacros.h"
@implementation _DDOperatorTerm
@@ -29,6 +30,13 @@ - (NSString *)operatorFunction {
return [[self token] operatorFunction];
}
+- (BOOL)resolveWithParser:(DDParser *)parser error:(NSError *__autoreleasing *)error {
+#pragma unused(parser)
+ ERR_ASSERT(error);
+ *error = ERR(DDErrorCodeOperatorMissingOperands, @"missing operand(s) for operator: %@", [self token]);
+ return NO;
+}
+
- (NSString *)description {
return [[self token] token];
}

0 comments on commit bf22144

Please sign in to comment.