Cleaned Code by Removing Location Tracking for Errors
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#import "MPMathRules.h"
|
||||
|
||||
@implementation MPFactor {
|
||||
NSRange _multiplicationSymbolRange;
|
||||
BOOL _multiplicationSymbolPresent;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
@@ -28,11 +28,9 @@
|
||||
if (self) {
|
||||
[tokenStream beginIgnoringWhitespaceTokens];
|
||||
MPToken *token = tokenStream.currentToken;
|
||||
if (token.tokenType == MPMultiplicationSymbolToken) {
|
||||
_multiplicationSymbolRange = token.range;
|
||||
_multiplicationSymbolPresent = token.tokenType == MPMultiplicationSymbolToken;
|
||||
if (_multiplicationSymbolPresent) {
|
||||
[tokenStream currentTokenConsumed];
|
||||
} else {
|
||||
_multiplicationSymbolRange = NSMakeRange(NSNotFound, 0);
|
||||
}
|
||||
if (tokenStream.currentToken.tokenType == MPOperatorListToken) {
|
||||
_operatorChain = [[MPOperatorChain alloc] initWithTokenStream:tokenStream];
|
||||
@@ -44,29 +42,18 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSRange)range
|
||||
{
|
||||
if (_multiplicationSymbolRange.location == NSNotFound) {
|
||||
return self.value.range;
|
||||
}
|
||||
return NSUnionRange(_multiplicationSymbolRange, self.value.range);
|
||||
}
|
||||
|
||||
- (NSRange)multiplicationSymbolRange
|
||||
{
|
||||
return _multiplicationSymbolRange;
|
||||
}
|
||||
|
||||
- (BOOL)hasMultiplicationSymbol
|
||||
{
|
||||
return _multiplicationSymbolRange.location != NSNotFound;
|
||||
return _multiplicationSymbolPresent;
|
||||
}
|
||||
|
||||
- (BOOL)validate:(MPParseError *__autoreleasing *)error
|
||||
- (BOOL)validate:(NSError *__autoreleasing *)error
|
||||
{
|
||||
if (self.operatorChain.numberOfOperators > [[MPMathRules sharedRules] maximumOperatorChainLengthInMultiplication]) {
|
||||
if (error) {
|
||||
*error = MPParseError(self.operatorChain.range, @"Too many operators in Multiplication");
|
||||
*error = MPParseError(7,
|
||||
NSLocalizedString(@"Too many operators in Multiplication.", @"Error message. This is displayed when there are too many operators between a multiplication symbol and a value."),
|
||||
nil);
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
@@ -82,14 +69,4 @@
|
||||
return value;
|
||||
}
|
||||
|
||||
- (NSArray *)expressionElements
|
||||
{
|
||||
NSMutableArray *elements = [[NSMutableArray alloc] init];
|
||||
if (self.hasMultiplicationSymbol) {
|
||||
[elements addObject:@"*"];
|
||||
}
|
||||
[elements addObjectsFromArray:self.value.expressionElements];
|
||||
return elements;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user