Started to Implement Evaluation
Corrected Some Errors Cleaned Code
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
||||
//
|
||||
|
||||
// TODO: Reorganise header/implementation order. Drop the primitive/not primitive Approach
|
||||
|
||||
#import "MPExpression.h"
|
||||
#import "MPFunction.h"
|
||||
#import "MPRangePath.h"
|
||||
@@ -13,8 +15,11 @@
|
||||
#import "NSIndexPath+MPAdditions.h"
|
||||
#import "MPException.h"
|
||||
|
||||
@interface MPExpression ()
|
||||
@property (readonly, nonatomic, strong) NSMutableArray *elements;
|
||||
#import "MPExpressionEvaluator.h"
|
||||
|
||||
@interface MPExpression () {
|
||||
NSMutableArray *__strong _elements;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface MPExpression (MPExpressionPrivate)
|
||||
@@ -64,8 +69,8 @@
|
||||
NSString *splitElement = (NSString *)self.elements[splitElementIndex];
|
||||
NSString *leftPart = [splitElement substringToIndex:splitOffset];
|
||||
NSString *rightPart = [splitElement substringFromIndex:splitOffset];
|
||||
[self.elements replaceObjectsInRange:NSMakeRange(splitElementIndex, 1)
|
||||
withObjectsFromArray:@[leftPart, rightPart]];
|
||||
[_elements replaceObjectsInRange:NSMakeRange(splitElementIndex, 1)
|
||||
withObjectsFromArray:@[leftPart, rightPart]];
|
||||
++splitElementIndex;
|
||||
}
|
||||
*insertionIndex = splitElementIndex;
|
||||
@@ -81,8 +86,6 @@
|
||||
NSUInteger _replacementLength;
|
||||
}
|
||||
|
||||
@synthesize elements = _elements;
|
||||
|
||||
#pragma mark Creation Methods
|
||||
- (instancetype)init
|
||||
{
|
||||
@@ -114,14 +117,14 @@
|
||||
id<MPExpressionElement> current = self.elements[index];
|
||||
if ([current isString]) {
|
||||
if (current.length == 0) {
|
||||
[self.elements removeObjectAtIndex:index];
|
||||
[_elements removeObjectAtIndex:index];
|
||||
if (index >= _editedRange.location && index < NSMaxRange(_editedRange)) {
|
||||
--_replacementLength;
|
||||
}
|
||||
--index;
|
||||
} else if ([next isString]) {
|
||||
NSString *new = [NSString stringWithFormat:@"%@%@", current, next];
|
||||
[self.elements replaceObjectsInRange:NSMakeRange(index, 2)
|
||||
[_elements replaceObjectsInRange:NSMakeRange(index, 2)
|
||||
withObjectsFromArray:@[new]];
|
||||
NSUInteger maxReplacementIndex = _editedRange.location + _replacementLength;
|
||||
if (index == _editedRange.location - 1) {
|
||||
@@ -244,7 +247,7 @@
|
||||
// Perform the replacement
|
||||
NSMutableArray *newElements = [[NSMutableArray alloc] initWithArray:elements
|
||||
copyItems:YES];
|
||||
[self.elements replaceObjectsInRange:NSMakeRange(startIndex, endIndex-startIndex)
|
||||
[_elements replaceObjectsInRange:NSMakeRange(startIndex, endIndex-startIndex)
|
||||
withObjectsFromArray:newElements];
|
||||
|
||||
_cachedLength = 0;
|
||||
@@ -260,11 +263,23 @@
|
||||
replacementLength:_replacementLength];
|
||||
}
|
||||
|
||||
|
||||
- (double)doubleValue
|
||||
- (NSArray *)elements
|
||||
{
|
||||
#warning Unimplemented Method
|
||||
return 0;
|
||||
return _elements;
|
||||
}
|
||||
|
||||
- (double)evaluateExpression:(NSError *__autoreleasing *)error
|
||||
{
|
||||
return [self.evaluator evaluateWithError:error];
|
||||
}
|
||||
|
||||
@synthesize evaluator = _evaluator;
|
||||
- (MPExpressionEvaluator *)evaluator
|
||||
{
|
||||
if (!_evaluator) {
|
||||
_evaluator = [[MPExpressionEvaluator alloc] initWithExpression:self];
|
||||
}
|
||||
return _evaluator;
|
||||
}
|
||||
|
||||
#pragma mark Notifications
|
||||
@@ -272,8 +287,7 @@
|
||||
replacementLength:(NSUInteger)replacementLength
|
||||
{
|
||||
NSUInteger selfIndex = [self.parent indexOfChild:self];
|
||||
MPRangePath *newPath = rangePath.copy;
|
||||
newPath.location = [newPath.location indexPathByPreceedingIndex:selfIndex];
|
||||
MPRangePath *newPath = MPMakeRangePath([rangePath.location indexPathByPreceedingIndex:selfIndex], rangePath.length);
|
||||
[self.parent didChangeElementsInRangePath:newPath
|
||||
replacementLength:replacementLength];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user