Cleaned Code by Removing Location Tracking for Errors
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
|
||||
@implementation MPProduct {
|
||||
NSMutableArray *_factors;
|
||||
NSRange _range;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
@@ -29,33 +28,35 @@
|
||||
if (self) {
|
||||
[tokenStream beginIgnoringWhitespaceTokens];
|
||||
|
||||
MPTokenStreamRecordCurrentLocation(tokenStream);
|
||||
while (tokenStream.currentToken.tokenType != MPOperatorListToken && tokenStream.currentToken.tokenType != MPEOFToken) {
|
||||
[_factors addObject:[[MPFactor alloc] initWithTokenStream:tokenStream]];
|
||||
}
|
||||
_range = MPTokenStreamRecordedRange(tokenStream);
|
||||
[tokenStream endIgnoringOrAcceptingWhitespaceTokens];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSRange)range
|
||||
- (NSArray *)factors
|
||||
{
|
||||
return _range;
|
||||
return _factors;
|
||||
}
|
||||
|
||||
- (BOOL)validate:(MPParseError *__autoreleasing *)error
|
||||
- (BOOL)validate:(NSError *__autoreleasing *)error
|
||||
{
|
||||
if (_factors.count == 0) {
|
||||
if (error) {
|
||||
*error = MPParseError(_range, @"Expected Value");
|
||||
*error = MPParseError(5,
|
||||
NSLocalizedString(@"Expected A Value.", @"Error message. Displayed when a value was expected in an expression but none was found."),
|
||||
nil);
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
MPFactor *factor = _factors[0];
|
||||
if (factor.hasMultiplicationSymbol) {
|
||||
if (error) {
|
||||
*error = MPParseError(factor.multiplicationSymbolRange, @"Unexpected Symbol.");
|
||||
*error = MPParseError(6,
|
||||
NSLocalizedString(@"Unexpected Symbol.", @"Error message. Displayed when or inappropriate symbol was encountered during parsing."),
|
||||
nil);
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
@@ -88,45 +89,4 @@
|
||||
return value;
|
||||
}
|
||||
|
||||
- (NSArray *)expressionElements
|
||||
{
|
||||
NSMutableArray *elements = [[NSMutableArray alloc] init];
|
||||
for (MPFactor *factor in _factors) {
|
||||
[elements addObjectsFromArray:factor.expressionElements];
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
- (NSArray *)factors
|
||||
{
|
||||
return _factors;
|
||||
}
|
||||
|
||||
- (void)appendFactor:(MPFactor *)factor
|
||||
{
|
||||
[_factors addObject:factor];
|
||||
}
|
||||
|
||||
- (void)insertFactor:(MPFactor *)factor
|
||||
atIndex:(NSUInteger)index
|
||||
{
|
||||
[_factors insertObject:factor
|
||||
atIndex:index];
|
||||
}
|
||||
|
||||
- (void)removeFactor:(MPFactor *)factor
|
||||
{
|
||||
[_factors removeObject:factor];
|
||||
}
|
||||
|
||||
- (void)removeFactorAtIndex:(NSUInteger)index
|
||||
{
|
||||
[_factors removeObjectAtIndex:index];
|
||||
}
|
||||
|
||||
- (MPFactor *)factorAtIndex:(NSUInteger)index
|
||||
{
|
||||
return [_factors objectAtIndex:index];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user