Archived
1

Fundamental Redesign of Evaluation

This commit is contained in:
Kim Wittenburg
2014-11-24 22:42:44 +01:00
parent 10f0e73ad3
commit 7a32e3b0b6
45 changed files with 1398 additions and 350 deletions

View File

@@ -31,57 +31,6 @@ FOUNDATION_EXPORT NSString *const MPIllegalElementException;
FOUNDATION_EXPORT NSString *const MPIllegalElementExceptionElementKey;
/*!
@const MPMathKitErrorDomain
@brief Predefined error domain for errors from the MathKit framework.
@discussion Errors in MathKit can occur during parsing of expressions or
during evaluation of expressions. These two can be distinguished
by the error code. Parsing errors have lower error codes.
Evaluation errors (math errors) have error codes from @c 100 upwards.
*/
FOUNDATION_EXPORT NSString *const MPMathKitErrorDomain;
// TODO: Deal with this:
// FOUNDATION_EXPORT NSString *const MPPathToExpressionKey;
// FOUNDATION_EXPORT NSString *const MPRangeKey;
/*!
@function MPParseError
@brief Creates an @c NSError object in the @c MPMathKitErrorDomain.
@discussion The created error is filled with the passed data if present.
@param errorCode
The error code of the created error.
@param errorDescription
The localized description of the created error. May be @c nil.
@param underlyingError
The underlying error of the created error. May be @c nil.
@return An @c NSError object initialized with the given data.
*/
NS_INLINE NSError * MPParseError(NSInteger errorCode,
NSString *errorDescription,
NSError *underlyingError) {
NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
if (errorDescription) {
userInfo[NSLocalizedDescriptionKey] = errorDescription;
}
if (underlyingError) {
userInfo[NSUnderlyingErrorKey] = underlyingError;
}
NSError *error = [NSError errorWithDomain:MPMathKitErrorDomain
code:errorCode
userInfo:userInfo.copy];
return error;
}
/*!
@typedef MPReferenceFrame
@brief A reference frame describes what an @em item is.
@@ -116,7 +65,7 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) {
@class MPExpression, MPFunction, MPRangePath, MPExpressionTree, MPExpressionEvaluator;
@class MPExpression, MPFunction, MPRangePath, MPParsedExpression;
@protocol MPExpressionElement, MPToken;
/*!
@@ -630,7 +579,7 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) {
want more control over the evaluation process use @c -parse
instead.
@param error
@param errors
If the receiver (or any of its elements) contains a syntax error
or can not be evaluated this parameter is set to an appropriate
value. Pass @c NULL if you are not interested in any errors that
@@ -642,7 +591,7 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) {
math error. In most cases the error parameter contains an
appropriate description of the problem.
*/
- (NSDecimalNumber *)evaluateWithError:(NSError *__autoreleasing *)error;
- (NSDecimalNumber *)evaluateWithErrors:(NSArray *__autoreleasing *)errors;
/*!
@@ -657,7 +606,10 @@ typedef NS_ENUM(NSUInteger, MPReferenceFrame) {
@return A @c MPExpressionTree object that can evaluate the receiver.
*/
- (MPExpressionTree *)parse;
- (MPParsedExpression *)parse:(NSArray *__autoreleasing *)errors;
- (MPParsedExpression *)parseExpectingVariable:(BOOL)flag
errors:(NSArray *__autoreleasing *)errors;
#pragma mark Notifications