From 0972e158f17c95503db2fc540285c08c1aa634bd Mon Sep 17 00:00:00 2001 From: Kim Wittenburg Date: Sun, 28 Sep 2014 23:56:17 +0200 Subject: [PATCH] Updated Schemes --- .../xcschemes/MathKit.xcscheme | 59 +++ .../xcschemes/MathPad.xcscheme | 10 + .../xcschemes/xcschememanagement.plist | 15 + MathPad/MPDisplayExtension.h | 21 -- MathPad/MPDisplayExtension.m | 33 -- MathPad/MPElementParser.h | 28 -- MathPad/MPElementParser.m | 345 ------------------ MathPad/MPException_Private.h | 14 - MathPad/MPFunction+MPParsedFactor.h | 14 - MathPad/MPFunction+MPParsedFactor.m | 30 -- MathPad/MPMath.h | 20 - MathPad/MPMath.lm | 16 - MathPad/MPMath.ym | 126 ------- MathPad/MPModel.h | 23 -- MathPad/MPParsedElement.h | 44 --- MathPad/MPParsedElement.m | 123 ------- MathPad/MPParsedFactor.h | 20 - MathPad/MPParsedFactor.m | 60 --- MathPad/MPParsedNumber.h | 16 - MathPad/MPParsedNumber.m | 42 --- MathPad/MPParsedOperator.h | 17 - MathPad/MPParsedOperator.m | 54 --- MathPad/MPParsedProduct.h | 22 -- MathPad/MPParsedProduct.m | 64 ---- MathPad/MPParsedVariable.h | 16 - MathPad/MPParsedVariable.m | 47 --- MathPad/MPRange.h | 39 -- MathPad/MPRange.m | 140 ------- MathPad/MPView.h | 19 - MathPad/NSIndexPath+MPRemoveFirstIndex.h | 21 -- MathPad/NSIndexPath+MPRemoveFirstIndex.m | 27 -- MathPad/NSIndexPath+MPReverseIndexPath.h | 23 -- MathPad/NSIndexPath+MPReverseIndexPath.m | 37 -- MathPad/NSObject+MPStringTest.h | 21 -- MathPad/NSObject+MPStringTest.m | 18 - MathPad/NSTextStorage+MPSetContents.h | 21 -- MathPad/NSTextStorage+MPSetContents.m | 19 - MathPadTests/MPMutableExpressionTests.m | 61 ---- MathPadTests/MathPadTests.m | 34 -- 39 files changed, 84 insertions(+), 1675 deletions(-) create mode 100644 MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathKit.xcscheme delete mode 100644 MathPad/MPDisplayExtension.h delete mode 100644 MathPad/MPDisplayExtension.m delete mode 100644 MathPad/MPElementParser.h delete mode 100644 MathPad/MPElementParser.m delete mode 100644 MathPad/MPException_Private.h delete mode 100644 MathPad/MPFunction+MPParsedFactor.h delete mode 100644 MathPad/MPFunction+MPParsedFactor.m delete mode 100644 MathPad/MPMath.h delete mode 100644 MathPad/MPMath.lm delete mode 100644 MathPad/MPMath.ym delete mode 100644 MathPad/MPModel.h delete mode 100644 MathPad/MPParsedElement.h delete mode 100644 MathPad/MPParsedElement.m delete mode 100644 MathPad/MPParsedFactor.h delete mode 100644 MathPad/MPParsedFactor.m delete mode 100644 MathPad/MPParsedNumber.h delete mode 100644 MathPad/MPParsedNumber.m delete mode 100644 MathPad/MPParsedOperator.h delete mode 100644 MathPad/MPParsedOperator.m delete mode 100644 MathPad/MPParsedProduct.h delete mode 100644 MathPad/MPParsedProduct.m delete mode 100644 MathPad/MPParsedVariable.h delete mode 100644 MathPad/MPParsedVariable.m delete mode 100644 MathPad/MPRange.h delete mode 100644 MathPad/MPRange.m delete mode 100644 MathPad/MPView.h delete mode 100644 MathPad/NSIndexPath+MPRemoveFirstIndex.h delete mode 100644 MathPad/NSIndexPath+MPRemoveFirstIndex.m delete mode 100644 MathPad/NSIndexPath+MPReverseIndexPath.h delete mode 100644 MathPad/NSIndexPath+MPReverseIndexPath.m delete mode 100644 MathPad/NSObject+MPStringTest.h delete mode 100644 MathPad/NSObject+MPStringTest.m delete mode 100644 MathPad/NSTextStorage+MPSetContents.h delete mode 100644 MathPad/NSTextStorage+MPSetContents.m delete mode 100644 MathPadTests/MPMutableExpressionTests.m delete mode 100644 MathPadTests/MathPadTests.m diff --git a/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathKit.xcscheme b/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathKit.xcscheme new file mode 100644 index 0000000..f1cab0e --- /dev/null +++ b/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathKit.xcscheme @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathPad.xcscheme b/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathPad.xcscheme index a102cc4..0b9f9dc 100644 --- a/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathPad.xcscheme +++ b/MathPad.xcodeproj/xcuserdata/kim.xcuserdatad/xcschemes/MathPad.xcscheme @@ -38,6 +38,16 @@ ReferencedContainer = "container:MathPad.xcodeproj"> + + + + SchemeUserState + MathKit.xcscheme + + orderHint + 1 + MathPad.xcscheme orderHint @@ -12,6 +17,16 @@ SuppressBuildableAutocreation + 3B85830C19BB5E5500D76A8D + + primary + + + 3B85831C19BB5E5500D76A8D + + primary + + 3BF9976A18DE623E009CF6C4 primary diff --git a/MathPad/MPDisplayExtension.h b/MathPad/MPDisplayExtension.h deleted file mode 100644 index 07d18a9..0000000 --- a/MathPad/MPDisplayExtension.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// MPExpression+MPDisplayExtension.h -// MathPad -// -// Created by Kim Wittenburg on 23.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPModel.h" - -@interface MPExpression (MPDisplayExtension) - -- (void)subexpressionChangedAtRangePath:(MPRangePath *)rangePath; - -@end - -@interface MPFunction (MPDisplayExtension) - -- (void)subexpressionChangedAtRangePath:(MPRangePath *)rangePath; - -@end diff --git a/MathPad/MPDisplayExtension.m b/MathPad/MPDisplayExtension.m deleted file mode 100644 index 599fdcc..0000000 --- a/MathPad/MPDisplayExtension.m +++ /dev/null @@ -1,33 +0,0 @@ -// -// MPExpression+MPDisplayExtension.m -// MathPad -// -// Created by Kim Wittenburg on 23.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPDisplayExtension.h" - -@implementation MPExpression (MPDisplayExtension) - -- (void)subexpressionChangedAtRangePath:(MPRangePath *)rangePath -{ - NSUInteger index = [self.parent indexOfChild:self]; - NSIndexPath *newLocation = [rangePath.location indexPathByPrecedingIndex:index]; - [self.parent subexpressionChangedAtRangePath:[[MPRangePath alloc] initWithLocation:newLocation - length:rangePath.length]]; -} - -@end - -@implementation MPFunction (MPDisplayExtension) - -- (void)subexpressionChangedAtRangePath:(MPRangePath *)rangePath -{ - NSUInteger index = [self.parent indexOfSymbol:self]; - NSIndexPath *newLocation = [rangePath.location indexPathByPrecedingIndex:index]; - [self.parent subexpressionChangedAtRangePath:[[MPRangePath alloc] initWithLocation:newLocation - length:rangePath.length]]; -} - -@end diff --git a/MathPad/MPElementParser.h b/MathPad/MPElementParser.h deleted file mode 100644 index 4fec301..0000000 --- a/MathPad/MPElementParser.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// MPElementParser.h -// MathPad -// -// Created by Kim Wittenburg on 10.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import -#import "MPParsedProduct.h" -#import "MPParseError.h" - -#define MPMaximumOperatorChainLength NSUIntegerMax - -@interface MPElementParser : NSObject - -- (NSArray *)parseElement:(NSString *)string - previousProduct:(MPParsedProduct *)previousProduct - nextFactor:(id)nextFactor - definesVariable:(BOOL)flag - definedVariable:(NSString *__autoreleasing *)variableName - error:(out MPParseError *__autoreleasing *)error; -- (NSArray *)parseElement:(NSString *)string - previousProduct:(MPParsedProduct *)previousProduct - nextFactor:(id)nextFactor - error:(out MPParseError *__autoreleasing *)error; - -@end diff --git a/MathPad/MPElementParser.m b/MathPad/MPElementParser.m deleted file mode 100644 index 14edfec..0000000 --- a/MathPad/MPElementParser.m +++ /dev/null @@ -1,345 +0,0 @@ -// -// MPElementParser.m -// MathPad -// -// Created by Kim Wittenburg on 10.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPElementParser.h" -#import "NSRegularExpression+MPParsingAdditions.h" -#import "MPMathRules.h" - -#import "MPParsedFactor.h" -#import "MPParsedNumber.h" -#import "MPParsedVariable.h" -#import "MPParsedOperator.h" - -#define MPMultiplicationSymbol @"*" - -@interface MPElementParser () - -@property (nonatomic) NSString *input; -@property (nonatomic) NSUInteger parsePosition; - -- (BOOL)allowsImplicitMultiplication; -- (BOOL)maximumOperatorChainLength; -- (BOOL)maximumOperatorChainLengthInMultiplication; -- (BOOL)maximumOperatorChainLengthInFunction; - -- (void)setError:(MPParseError *)error; - -- (BOOL)isAtEnd; - -- (NSRange)parseVariableDefinition:(NSString *__autoreleasing *)variableName; - -- (NSRange)parseWhitespaces; -- (NSRange)parseMultiplicationSymbol; -- (MPParsedOperator *)parseOperators; -- (id)parseValue; -- (MPParsedNumber *)parseNumber; -- (MPParsedVariable *)parseVariable; - -@end - -@implementation MPElementParser { - MPParseError *__autoreleasing *outError; -} - -#pragma mark Helpers -- (BOOL)allowsImplicitMultiplication -{ - return [MPMathRules sharedRules].allowsImplicitMultiplication; -} - -- (BOOL)maximumOperatorChainLength -{ - return [MPMathRules sharedRules].maximumOperatorChainLength; -} - -- (BOOL)maximumOperatorChainLengthInFunction -{ - return [MPMathRules sharedRules].maximumOperatorChainLengthInFunction; -} - -- (BOOL)maximumOperatorChainLengthInMultiplication -{ - return [MPMathRules sharedRules].maximumOperatorChainLengthInMultiplication; -} - -#pragma mark Parsing Methods - -- (BOOL)isAtEnd -{ - return self.parsePosition >= self.input.length; -} - -- (void)setError:(MPParseError *)error -{ - if (outError != NULL) { - *outError = error; - } -} - -- (NSArray *)parseElement:(NSString *)string - previousProduct:(MPParsedProduct *)previousProduct - nextFactor:(id)nextFactor - error:(out MPParseError *__autoreleasing *)error -{ - return [self parseElement:string - previousProduct:previousProduct - nextFactor:nextFactor - definesVariable:NO - definedVariable:NULL - error:error]; -} - -- (NSArray *)parseElement:(NSString *)string - previousProduct:(MPParsedProduct *)previousProduct - nextFactor:(id)nextFactor - definesVariable:(BOOL)flag - definedVariable:(NSString *__autoreleasing *)variableName - error:(out MPParseError *__autoreleasing *)error -{ - self.input = string; - outError = error; - self.parsePosition = 0; - - NSString *definedVariable; - NSRange variableDefinitionRange = [self parseVariableDefinition:&definedVariable]; - if (flag) { - if (!definedVariable) { - self.error = MPParseError(NSMakeRange(0, 0), @"Expected Variable Definition"); - return nil; - } else if (variableName) { - *variableName = definedVariable; - } - } else if (definedVariable) { - self.error = MPParseError(variableDefinitionRange, @"Unexpected Variable Definition"); - return nil; - } - - NSMutableArray *products = [[NSMutableArray alloc] init]; - MPParsedProduct *currentProduct = previousProduct; - - while (YES) { - [self parseWhitespaces]; - - NSRange multiplicationSymbolRange = [self parseMultiplicationSymbol]; - BOOL hasMultiplicationSymbol = multiplicationSymbolRange.location != NSNotFound; - - MPParsedOperator *operators = [self parseOperators]; - - // NSRange functionRange = ... - // BOOL hasFunction = functionRange.location != NSNotFound; - - id value = [self parseValue]; - - - if (!value.exists) { - if ([self isAtEnd] && nextFactor != nil) { - if (hasMultiplicationSymbol) { - if (operators.numberOfOperators > self.maximumOperatorChainLengthInFunction) { - self.error = MPParseError(operators.range, @"Too many operators in multiplication."); - return nil; - } - [currentProduct addFactor:operators]; - } else if (operators.exists) { - if (operators.numberOfOperators > self.maximumOperatorChainLength) { - self.error = MPParseError(operators.range, @"Too many operators."); - return nil; - } - [products addObject:currentProduct]; - currentProduct = [[MPParsedProduct alloc] init]; - [currentProduct addFactor:operators]; - } else if (self.allowsImplicitMultiplication) { - if (!currentProduct) { - currentProduct = [[MPParsedProduct alloc] init]; - } - } else { - self.error = MPParseError(NSMakeRange(self.parsePosition, 0), @"Implicit Multiplication not allowed."); - return nil; - } - break; - } else if ([self isAtEnd]) { - if (hasMultiplicationSymbol || operators.exists) { - self.error = MPParseError(NSMakeRange(self.parsePosition, 0), @"Unexpected End. Expected Number."); - return nil; - } - } else { - self.error = MPParseError(NSMakeRange(self.parsePosition, 1), @"Unexpected Symbol. Expected Number."); - return nil; - } - break; - } else { - if (hasMultiplicationSymbol) { - if (currentProduct) { - if (operators.numberOfOperators > self.maximumOperatorChainLengthInMultiplication) { - self.error = MPParseError(operators.range, @"Too many operators in multiplication."); - return nil; - } - [currentProduct addFactor:operators]; - [currentProduct addFactor:value]; - } else { - self.error = MPParseError(multiplicationSymbolRange, @"Unexpected Symbol. Expected Number."); - return nil; - } - } else if (operators.exists) { - if (operators.numberOfOperators > self.maximumOperatorChainLength) { - self.error = MPParseError(operators.range, @"Too many operators."); - return nil; - } - if (currentProduct) { - [products addObject:currentProduct]; - } - currentProduct = [[MPParsedProduct alloc] initWithFactor:operators]; - [currentProduct addFactor:value]; - } else if (!currentProduct) { - currentProduct = [[MPParsedProduct alloc] initWithFactor:value]; - } else if (self.allowsImplicitMultiplication) { - [currentProduct addFactor:value]; - } else { - self.error = MPParseError(NSMakeRange(value.range.location, 0), @"Implicit Multiplication not allowed."); - return nil; - } - } - } - if (nextFactor) { - [currentProduct addFactor:nextFactor]; - } - [products addObject:currentProduct]; - return products; -} - -static NSRegularExpression *variableDefinitionRegex; -- (NSRange)parseVariableDefinition:(NSString *__autoreleasing *)variableName -{ - if (!variableDefinitionRegex) { - variableDefinitionRegex = [NSRegularExpression regularExpressionWithPattern:@"\\A\\s*([A-Za-z])\\s*=\\s*" - options:0 - error:NULL]; - } - - NSTextCheckingResult *match = [variableDefinitionRegex firstMatchInString:self.input - fromIndex:self.parsePosition]; - if (!match) { - return NSMakeRange(NSNotFound, 0); - } - self.parsePosition = NSMaxRange(match.range); - NSRange variableDefinitionRange = [match rangeAtIndex:1]; - *variableName = [self.input substringWithRange:variableDefinitionRange]; - return variableDefinitionRange; -} - -static NSRegularExpression *whitespaceRegex; -- (NSRange)parseWhitespaces -{ - if (!whitespaceRegex) { - whitespaceRegex = [NSRegularExpression regularExpressionWithPattern:@"\\A\\s*" - options:0 - error:NULL]; - } - NSTextCheckingResult *match = [whitespaceRegex firstMatchInString:self.input - fromIndex:self.parsePosition]; - if (match) { - self.parsePosition = NSMaxRange(match.range); - return match.range; - } else { - return NSMakeRange(NSNotFound, 0); - } -} - -static NSRegularExpression *multiplicationSymbolRegex; -- (NSRange)parseMultiplicationSymbol -{ - if (!multiplicationSymbolRegex) { - NSString *multiplicationSymbolString = [NSRegularExpression escapedPatternForString:MPMultiplicationSymbol]; - NSString *multiplicationSymbolRegexString = [NSString stringWithFormat:@"\\A\\s*(%@)\\s*", multiplicationSymbolString]; - multiplicationSymbolRegex = [NSRegularExpression regularExpressionWithPattern:multiplicationSymbolRegexString - options:0 - error:NULL]; - } - NSTextCheckingResult *match = [multiplicationSymbolRegex firstMatchInString:self.input - fromIndex:self.parsePosition]; - if (!match) { - return NSMakeRange(NSNotFound, 0); - } - self.parsePosition = NSMaxRange(match.range); - return [match rangeAtIndex:1]; -} - -static NSRegularExpression *operatorsRegex; -- (MPParsedOperator *)parseOperators -{ - if (!operatorsRegex) { - operatorsRegex = [NSRegularExpression regularExpressionWithPattern:@"\\A\\s*([+-](?:\\s*[+-])*)\\s*" - options:0 - error:NULL]; - } - NSTextCheckingResult *match = [operatorsRegex firstMatchInString:self.input - fromIndex:self.parsePosition]; - NSRange matchRange; - if (!match) { - matchRange = NSMakeRange(NSNotFound, 0); - } else { - self.parsePosition = NSMaxRange(match.range); - matchRange = [match rangeAtIndex:1]; - } - return [[MPParsedOperator alloc] initWithRange:matchRange - inString:self.input]; -} - -- (id)parseValue -{ - MPParsedNumber *parsedNumber = [self parseNumber]; - if (!parsedNumber.exists) { - MPParsedVariable *parsedVariable = [self parseVariable]; - if (parsedVariable.exists) { - return parsedVariable; - } - } - return parsedNumber; -} - -- (MPParsedNumber *)parseNumber -{ - NSString *decimalSeparatorRegexString = [NSRegularExpression escapedPatternForString:[[NSLocale currentLocale] objectForKey:NSLocaleDecimalSeparator]]; - NSString *numberRegexFormat = [NSString stringWithFormat:@"\\A\\s*((?:\\d+(?:%@\\d+)?)|(?:%@\\d+))\\s*", decimalSeparatorRegexString, decimalSeparatorRegexString]; - NSRegularExpression *numberRegex = [NSRegularExpression regularExpressionWithPattern:numberRegexFormat - options:0 - error:NULL]; - NSTextCheckingResult *match = [numberRegex firstMatchInString:self.input - fromIndex:self.parsePosition]; - NSRange matchRange; - if (!match) { - matchRange = NSMakeRange(NSNotFound, 0); - } else { - self.parsePosition = NSMaxRange(match.range); - matchRange = [match rangeAtIndex:1]; - } - return [[MPParsedNumber alloc] initWithRange:matchRange - inString:self.input]; -} - -static NSRegularExpression *variableRegex; -- (MPParsedVariable *)parseVariable -{ - if (!variableRegex) { - variableRegex = [NSRegularExpression regularExpressionWithPattern:@"\\A\\s*([A-Za-z])\\s*" - options:0 - error:NULL]; - } - NSTextCheckingResult *match = [variableRegex firstMatchInString:self.input - fromIndex:self.parsePosition]; - NSRange matchRange; - if (!match) { - matchRange = NSMakeRange(NSNotFound, 0); - } else { - self.parsePosition = NSMaxRange(match.range); - matchRange = [match rangeAtIndex:1]; - } - return [[MPParsedVariable alloc] initWithRange:matchRange - inString:self.input]; -} - -@end diff --git a/MathPad/MPException_Private.h b/MathPad/MPException_Private.h deleted file mode 100644 index fdee303..0000000 --- a/MathPad/MPException_Private.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// MPException_Private.h -// MathPad -// -// Created by Kim Wittenburg on 19.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#ifndef MathPad_MPException_Private_h -#define MathPad_MPException_Private_h - -extern NSString *MPIllegalSymbolExceptionReason; - -#endif diff --git a/MathPad/MPFunction+MPParsedFactor.h b/MathPad/MPFunction+MPParsedFactor.h deleted file mode 100644 index a1a7469..0000000 --- a/MathPad/MPFunction+MPParsedFactor.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// MPFunction+MPParsedFactor.h -// MathPad -// -// Created by Kim Wittenburg on 13.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import -#import "MPParsedFactor.h" - -@interface MPFunction (MPParsedFactor) - -@end diff --git a/MathPad/MPFunction+MPParsedFactor.m b/MathPad/MPFunction+MPParsedFactor.m deleted file mode 100644 index fc963e3..0000000 --- a/MathPad/MPFunction+MPParsedFactor.m +++ /dev/null @@ -1,30 +0,0 @@ -// -// MPFunction+MPParsedFactor.m -// MathPad -// -// Created by Kim Wittenburg on 13.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPFunction+MPParsedFactor.h" - -@implementation MPFunction (MPParsedFactor) - -- (instancetype)initWithRange:(NSRange)range - inString:(NSString *)string -{ - return [self init]; -} - -- (BOOL)exists -{ - return YES; -} - -- (NSRange)range -{ - NSUInteger selfIndex = [self.parent indexOfElement:self]; - return NSMakeRange([self.parent locationOfElementAtIndex:selfIndex], 1); -} - -@end diff --git a/MathPad/MPMath.h b/MathPad/MPMath.h deleted file mode 100644 index 713948f..0000000 --- a/MathPad/MPMath.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// YYParse.h -// MathPad -// -// Created by Kim Wittenburg on 05.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPMath.yy.h" -#import "MPMath.tab.h" -#import "MPParsedElement.h" - -#ifndef MathPad_YYParse_h -#define MathPad_YYParse_h - -extern MPParsedElement *parseResult; - -int yyparse(); - -#endif diff --git a/MathPad/MPMath.lm b/MathPad/MPMath.lm deleted file mode 100644 index 10c8827..0000000 --- a/MathPad/MPMath.lm +++ /dev/null @@ -1,16 +0,0 @@ -%option noyywrap -%{ - @import Foundation; - #include "MPMath.tab.h" -%} -%% - /* Ignore Whitespaces */ -[ \t\n] ; - /* Operators. Divisions are automatically transformed into fractions and dealt - with elsewhere. */ -\+ { return PLUS; } -- { return MINUS; } -\* { return DOT; } - /* Numbers */ -[0-9]+(\.[0-9]+)? { yylval.number = atof(yytext); return NUMBER; } -%% \ No newline at end of file diff --git a/MathPad/MPMath.ym b/MathPad/MPMath.ym deleted file mode 100644 index b09ae8f..0000000 --- a/MathPad/MPMath.ym +++ /dev/null @@ -1,126 +0,0 @@ -%{ - #import "MPMath.h" - #define AT @ - - MPParsedElement *parseResult; - - int yylex(); - int yyparse(); - FILE *yyin; - - void yyerror(const char *s); -%} - -%error-verbose - -%initial-action -{ - parseResult = [[MPParsedElement alloc] init]; -}; - -%union { - double number; -} - /* Terminals */ -%token PLUS -%left MINUS -%token DOT -%token NUMBER - - /* Nonterminals */ -%type summands -%type factor -%type product - -%% - -element: - factor { parseResult.isFactor = YES; - parseResult.factor = $1; - } - | operator - | prefix summands suffix - ; - -factor: - DOT product DOT { $$ = $2; - } - | DOT product { $$ = $2; - } - | product DOT { $$ = $1; - } - | product { $$ = $1; - } - ; - -product: - product DOT product { $$ = $1 * $3; - } - | product product { $$ = $1 * $2; - } - | NUMBER { $$ = $1; - } - ; - -operator: - PLUS { parseResult.suffixMultiplicator = 1; - parseResult.hasSuffixMultiplicator = YES; - } - | MINUS { parseResult.suffixMultiplicator = -1; - parseResult.hasSuffixMultiplicator = YES; - NSLog(AT"Op"); - } - | DOT { parseResult.isFactor = YES; - parseResult.factor = 1; - } - | { parseResult.isFactor = YES; - parseResult.factor = 1; - } - ; - -prefix: - DOT product { parseResult.prefixMultiplicator = $2; - parseResult.hasPrefixMultiplicator = YES; - parseResult.prefixOperatorExplicit = YES; - } - | product { parseResult.prefixMultiplicator = $1; - parseResult.hasPrefixMultiplicator = YES; - parseResult.prefixOperatorExplicit = YES; - } - | { parseResult.hasPrefixMultiplicator = NO; - } - ; - -summands: - summands summand - | summand - ; - -summand: - PLUS product { [parseResult.summands addObject:AT($2)]; - } - | MINUS product { [parseResult.summands addObject:AT(-$2)]; - } - ; - -suffix: - PLUS { parseResult.suffixMultiplicator = 1; - parseResult.hasSuffixMultiplicator = YES; - } - | MINUS { parseResult.suffixMultiplicator = -1; - parseResult.hasSuffixMultiplicator = YES; - } - | DOT { parseResult.suffixMultiplicator = 0; - parseResult.hasSuffixMultiplicator = YES; - } - | { parseResult.hasSuffixMultiplicator = NO; - } - ; - -%% - -void yyerror(const char *s) { - NSLog(@"EEK, parse error! Message: %s", s); - // might as well halt now: - exit(-1); -} \ No newline at end of file diff --git a/MathPad/MPModel.h b/MathPad/MPModel.h deleted file mode 100644 index 1f7f7f6..0000000 --- a/MathPad/MPModel.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// MPModel.h -// MathPad -// -// Created by Kim Wittenburg on 20.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -/* - This is a convenience header which imports all model classes defined by MathPad. - */ - -#ifndef MathPad_MPModel_h -#define MathPad_MPModel_h - -#import "MPException.h" -#import "MPExpression.h" -#import "MPFunction.h" -#import "MPRangePath.h" - -#import "NSIndexPath+MPAdditions.h" - -#endif diff --git a/MathPad/MPParsedElement.h b/MathPad/MPParsedElement.h deleted file mode 100644 index cba8878..0000000 --- a/MathPad/MPParsedElement.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// MPParsedElement.h -// MathPad -// -// Created by Kim Wittenburg on 05.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import - -#import "MPParseError.h" - -@interface MPParsedElement : NSObject - -@property (nonatomic, copy) NSString *definedVariable; -@property (nonatomic) NSUInteger afterVariableDefinitionIndex; // Only set if defineVariable != nil - -@property (nonatomic) BOOL isFactor; - -// If isFactor is YES this is the factor otherwise it is the independant summant -// of the element (may be 0). -@property (nonatomic) NSDecimalNumber *value; - -@property (nonatomic, getter = isPrefixOperatorExplicit) BOOL prefixOperatorExplicit; -@property (nonatomic, getter = isPrefixValueExplicit) BOOL prefixValueExplicit; -@property (nonatomic) NSDecimalNumber *prefixMultiplicator; - -@property (nonatomic, getter = isSuffixOperatorExplicit) BOOL suffixOperatorExplicit; -@property (nonatomic, getter = isSuffixValueExplicit) BOOL suffixValueExplicit; -@property (nonatomic) NSDecimalNumber *suffixMultiplicator; -@property (nonatomic) NSUInteger suffixIndex; - -// No error checking done -- (NSDecimalNumber *)valueAtBeginning; -- (NSDecimalNumber *)valueAtEnd; -- (NSDecimalNumber *)standaloneValue; - -// For error checking -- (BOOL)isValidElementAtBeginning:(MPParseError **)error; -- (BOOL)isValidStandaloneElement:(MPParseError **)error; -- (BOOL)isValidElementAtEnd:(MPParseError **)error; -- (BOOL)isValidVariableDefinition:(MPParseError **)error; - -@end diff --git a/MathPad/MPParsedElement.m b/MathPad/MPParsedElement.m deleted file mode 100644 index 179638e..0000000 --- a/MathPad/MPParsedElement.m +++ /dev/null @@ -1,123 +0,0 @@ -// -// MPParsedElement.m -// MathPad -// -// Created by Kim Wittenburg on 05.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPParsedElement.h" - -@implementation MPParsedElement - -- (instancetype)init -{ - self = [super init]; - if (self) { - } - return self; -} - -- (NSDecimalNumber *)valueAtBeginning -{ - NSDecimalNumber *value = self.value; - if (self.prefixValueExplicit) { - value = [value decimalNumberByAdding:self.prefixMultiplicator]; - } - return value; -} - -- (NSDecimalNumber *)valueAtEnd -{ - NSDecimalNumber *value = self.value; - if (self.suffixValueExplicit) { - value = [value decimalNumberByAdding:self.suffixMultiplicator]; - } - return value; -} - -- (NSDecimalNumber *)standaloneValue -{ - if (self.isFactor) { - return self.value; - } - NSDecimalNumber *value = self.value; - if (self.prefixValueExplicit) { - value = [value decimalNumberByAdding:self.prefixMultiplicator]; - } - if (self.suffixValueExplicit) { - value = [value decimalNumberByAdding:self.suffixMultiplicator]; - } - return value; -} - -- (BOOL)isValidElementAtBeginning:(MPParseError *__autoreleasing *)error -{ - if (self.prefixOperatorExplicit) { - if (error) { - *error = MPParseError(0, @"Expected Number"); - } - return NO; - } - return YES; -} - -- (BOOL)isValidStandaloneElement:(MPParseError *__autoreleasing *)error -{ - return [self isValidElementAtBeginning:error] && [self isValidElementAtEnd:error]; -} - -- (BOOL)isValidElementAtEnd:(MPParseError *__autoreleasing *)error -{ - if (self.suffixOperatorExplicit) { - if (error) { - *error = MPParseError(self.suffixIndex, @"Expected Number"); - } - return NO; - } - return YES; -} - -- (BOOL)isValidVariableDefinition:(MPParseError *__autoreleasing *)error -{ - if (self.definedVariable == nil) { - if (error) { - *error = MPParseError(0, @"Expected Variable Definition"); - } - return NO; - } - return [self isValidElementAtBeginning:error]; -} - -#pragma mark - NSObject Overrides - -- (NSString *)description -{ - NSMutableString *description = [[NSMutableString alloc] initWithString:@"MPParsedElement<"]; - if (self.isFactor) { - [description appendFormat:@"factor=%@%@%@", self.prefixOperatorExplicit?@"*":@"", self.value, self.suffixOperatorExplicit?@"*":@""]; - } else { - [description appendFormat:@"prefix=%@%@ prefixValueExplicit=%@", self.prefixOperatorExplicit?@"*":@"", self.prefixMultiplicator, self.prefixValueExplicit?@"YES":@"NO"]; - [description appendFormat:@" suffix=%@%@ suffixValueExplicit=%@", self.suffixMultiplicator, self.suffixOperatorExplicit?@"*":@"", self.suffixValueExplicit?@"YES":@"NO"]; - [description appendFormat:@" value=%@", self.value]; - } - [description appendString:@">"]; - return [description copy]; -} - -#pragma mark - NSCopying -- (id)copyWithZone:(NSZone *)zone -{ - MPParsedElement *copy = [[MPParsedElement allocWithZone:zone] init]; - copy.isFactor = self.isFactor; - copy.value = self.value; - copy.prefixOperatorExplicit = self.prefixOperatorExplicit; - copy.prefixValueExplicit = self.prefixValueExplicit; - copy.prefixMultiplicator = self.prefixMultiplicator; - copy.suffixOperatorExplicit = self.suffixOperatorExplicit; - copy.suffixValueExplicit = self.suffixValueExplicit; - copy.suffixMultiplicator = self.suffixMultiplicator; - return copy; -} - -@end diff --git a/MathPad/MPParsedFactor.h b/MathPad/MPParsedFactor.h deleted file mode 100644 index 46e6999..0000000 --- a/MathPad/MPParsedFactor.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// MPParsedFactor.h -// MathPad -// -// Created by Kim Wittenburg on 13.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import -#import "MPParseError.h" - -@protocol MPParsedFactor - -- (instancetype)initWithRange:(NSRange)range inString:(NSString *)string; - -- (NSRange)range; -- (BOOL)exists; -- (NSDecimalNumber *)evaluateWithError:(MPParseError *__autoreleasing *)error; - -@end diff --git a/MathPad/MPParsedFactor.m b/MathPad/MPParsedFactor.m deleted file mode 100644 index 9f4aff2..0000000 --- a/MathPad/MPParsedFactor.m +++ /dev/null @@ -1,60 +0,0 @@ -// -// MPParsedFactor.m -// MathPad -// -// Created by Kim Wittenburg on 10.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPParsedFactor.h" - -@implementation MPParsedFactor { - NSDecimalNumber *_value; -} - -+ (MPParsedFactor *)factorWithDecimalNumber:(NSDecimalNumber *)number -{ - return [[MPParsedFactor alloc] initWithDecimalNumber:number]; -} - -+ (MPParsedFactor *)sinFactorWithFactor:(MPParsedFactor *)factor -{ - double value = factor.value.doubleValue; - NSDecimalNumber *actualNumber = [[NSDecimalNumber alloc] initWithDouble:sin(value)]; - return [[MPParsedFactor alloc] initWithDecimalNumber:actualNumber]; -} - -+ (MPParsedFactor *)cosFactorWithFactor:(MPParsedFactor *)factor -{ - double value = factor.value.doubleValue; - NSDecimalNumber *actualNumber = [[NSDecimalNumber alloc] initWithDouble:cos(value)]; - return [[MPParsedFactor alloc] initWithDecimalNumber:actualNumber]; -} - -+ (MPParsedFactor *)tanFactorWithFactor:(MPParsedFactor *)factor -{ - double value = factor.value.doubleValue; - NSDecimalNumber *actualNumber = [[NSDecimalNumber alloc] initWithDouble:tan(value)]; - return [[MPParsedFactor alloc] initWithDecimalNumber:actualNumber]; -} - -- (instancetype)initWithDecimalNumber:(NSDecimalNumber *)number -{ - self = [super init]; - if (self) { - _value = number; - } - return self; -} - -- (NSDecimalNumber *)value -{ - return _value; -} - -- (NSString *)description -{ - return [NSString stringWithFormat:@"MPParsedFactor<%@>", _value]; -} - -@end \ No newline at end of file diff --git a/MathPad/MPParsedNumber.h b/MathPad/MPParsedNumber.h deleted file mode 100644 index 7bf9368..0000000 --- a/MathPad/MPParsedNumber.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// MPParsedNumber.h -// MathPad -// -// Created by Kim Wittenburg on 13.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import -#import "MPParsedFactor.h" - -@interface MPParsedNumber : NSObject - -- (NSDecimalNumber *)number; - -@end diff --git a/MathPad/MPParsedNumber.m b/MathPad/MPParsedNumber.m deleted file mode 100644 index f0be1e7..0000000 --- a/MathPad/MPParsedNumber.m +++ /dev/null @@ -1,42 +0,0 @@ -// -// MPParsedNumber.m -// MathPad -// -// Created by Kim Wittenburg on 13.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPParsedNumber.h" - -@interface MPParsedNumber () -@property (nonatomic) NSRange range; -@property (nonatomic, strong) NSDecimalNumber *number; -@end - -@implementation MPParsedNumber - -- (instancetype)initWithRange:(NSRange)range - inString:(NSString *)string -{ - self = [super init]; - if (self) { - _range = range; - if (range.location != NSNotFound) { - NSString *stringValue = [string substringWithRange:range]; - _number = [NSDecimalNumber decimalNumberWithString:stringValue]; - } - } - return self; -} - -- (BOOL)exists -{ - return self.range.location != NSNotFound; -} - -- (NSDecimalNumber *)evaluateWithError:(MPParseError *__autoreleasing *)error -{ - return self.number; -} - -@end diff --git a/MathPad/MPParsedOperator.h b/MathPad/MPParsedOperator.h deleted file mode 100644 index 040b159..0000000 --- a/MathPad/MPParsedOperator.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// MPParsedOperator.h -// MathPad -// -// Created by Kim Wittenburg on 13.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import -#import "MPParsedFactor.h" - -@interface MPParsedOperator : NSObject - -- (NSUInteger)numberOfOperators; -- (NSDecimalNumber *)multiplicator; - -@end diff --git a/MathPad/MPParsedOperator.m b/MathPad/MPParsedOperator.m deleted file mode 100644 index aacdee1..0000000 --- a/MathPad/MPParsedOperator.m +++ /dev/null @@ -1,54 +0,0 @@ -// -// MPParsedOperator.m -// MathPad -// -// Created by Kim Wittenburg on 13.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPParsedOperator.h" - -@interface MPParsedOperator () -@property (nonatomic) NSRange range; -@property (nonatomic) NSUInteger numberOfOperators; -@property (nonatomic, strong) NSDecimalNumber *multiplicator; -@end - -@implementation MPParsedOperator - -- (instancetype)initWithRange:(NSRange)range - inString:(NSString *)string -{ - self = [super init]; - if (self) { - _range = range; - if (range.location == NSNotFound) { - _multiplicator = [NSDecimalNumber one]; - _numberOfOperators = 0; - } else { - NSString *stringValue = [string substringWithRange:range]; - NSString *operators = [[stringValue componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] componentsJoinedByString:@""]; - NSInteger multiplicator = 1; - for (NSUInteger characterIndex = 0; characterIndex < operators.length; characterIndex++) { - if ([[operators substringWithRange:NSMakeRange(characterIndex, 1)] isEqualToString:@"-"]) { - multiplicator *= -1; - } - } - _multiplicator = [[NSDecimalNumber alloc] initWithInteger:multiplicator]; - _numberOfOperators = operators.length; - } - } - return self; -} - -- (BOOL)exists -{ - return self.range.location != NSNotFound; -} - -- (NSDecimalNumber *)evaluateWithError:(MPParseError *__autoreleasing *)error -{ - return self.multiplicator; -} - -@end diff --git a/MathPad/MPParsedProduct.h b/MathPad/MPParsedProduct.h deleted file mode 100644 index 19dbcdc..0000000 --- a/MathPad/MPParsedProduct.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// MPParsedSummand.h -// MathPad -// -// Created by Kim Wittenburg on 10.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import -#import "MPParsedFactor.h" - -@interface MPParsedProduct : NSObject - -- (instancetype)init; // designated initializer -- (instancetype)initWithFactor:(id)factor; // designated initializer. - -@property (readonly, nonatomic, strong) NSArray *factors; -- (void)addFactor:(id)factor; - -- (NSDecimalNumber *)evaluateWithError:(MPParseError *__autoreleasing *)error; - -@end diff --git a/MathPad/MPParsedProduct.m b/MathPad/MPParsedProduct.m deleted file mode 100644 index c12e654..0000000 --- a/MathPad/MPParsedProduct.m +++ /dev/null @@ -1,64 +0,0 @@ -// -// MPParsedSummand.m -// MathPad -// -// Created by Kim Wittenburg on 10.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPParsedProduct.h" - -@implementation MPParsedProduct { - NSMutableArray *_factors; -} - -- (instancetype)init -{ - self = [super init]; - if (self) { - _factors = [[NSMutableArray alloc] init]; - } - return self; -} - -- (instancetype)initWithFactor:(id)factor -{ - self = [super init]; - if (self) { - _factors = [[NSMutableArray alloc] initWithObjects:factor, nil]; - } - return self; -} - -- (NSArray *)factors -{ - return _factors; -} - -- (void)addFactor:(id)factor -{ - [_factors addObject:factor]; -} - -- (NSDecimalNumber *)evaluateWithError:(MPParseError *__autoreleasing *)error -{ - if (_factors.count == 0) { - return [NSDecimalNumber zero]; - } - NSDecimalNumber *value = [NSDecimalNumber one]; - for (id factor in _factors) { - NSDecimalNumber *factorValue = [factor evaluateWithError:error]; - if (!factorValue) { - return nil; - } - value = [value decimalNumberByMultiplyingBy:factorValue]; - } - return value; -} - -- (NSString *)description -{ - return [NSString stringWithFormat:@"MPParsedProduct<%@>", [_factors componentsJoinedByString:@"*"]]; -} - -@end diff --git a/MathPad/MPParsedVariable.h b/MathPad/MPParsedVariable.h deleted file mode 100644 index 6b1ff7f..0000000 --- a/MathPad/MPParsedVariable.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// MPParsedVariable.h -// MathPad -// -// Created by Kim Wittenburg on 13.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import -#import "MPParsedFactor.h" - -@interface MPParsedVariable : NSObject - -- (NSString *)variableName; - -@end diff --git a/MathPad/MPParsedVariable.m b/MathPad/MPParsedVariable.m deleted file mode 100644 index 7dce021..0000000 --- a/MathPad/MPParsedVariable.m +++ /dev/null @@ -1,47 +0,0 @@ -// -// MPParsedVariable.m -// MathPad -// -// Created by Kim Wittenburg on 13.09.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPParsedVariable.h" -#import "MPEvaluationContext.h" - -@interface MPParsedVariable () -@property (nonatomic) NSRange range; -@property (nonatomic, strong) NSString *variableName; -@end - -@implementation MPParsedVariable - -- (instancetype)initWithRange:(NSRange)range - inString:(NSString *)string -{ - self = [super init]; - if (self) { - _range = range; - if (range.location != NSNotFound) { - _variableName = [string substringWithRange:range]; - } - } - return self; -} - -- (BOOL)exists -{ - return self.range.location != NSNotFound; -} - -- (NSDecimalNumber *)evaluateWithError:(MPParseError *__autoreleasing *)error -{ - NSDecimalNumber *value = [[MPEvaluationContext sharedContext] valueForVariableName:self.variableName]; - if (!value) { - *error = MPParseError(self.range, @"Undefined Variable."); - return nil; - } - return value; -} - -@end diff --git a/MathPad/MPRange.h b/MathPad/MPRange.h deleted file mode 100644 index 8492ec2..0000000 --- a/MathPad/MPRange.h +++ /dev/null @@ -1,39 +0,0 @@ -// -// MPRange.h -// MathPad -// -// Created by Kim Wittenburg on 18.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -@interface MPRange : NSObject - -#pragma mark Creation Methods - -- (instancetype)init; -- (instancetype)initWithLocation:(NSIndexPath *)location - length:(NSUInteger)length; -- (instancetype)initWithRange:(NSRange)aRange; - -+ (instancetype)emptyRange; -+ (instancetype)rangeWithLocation:(NSIndexPath *)location - length:(NSUInteger)length; -+ (instancetype)rangeWithRange:(NSRange)aRange; - -#pragma mark Properties - -@property (nonatomic, strong) NSIndexPath *location; -@property (nonatomic) NSUInteger length; - -- (NSIndexPath *)maxRange; -- (NSRange)rangeAtLastIndex; - -#pragma mark Working with Ranges - -- (BOOL)containsRange:(MPRange *)aRange; -- (BOOL)containsLocation:(NSIndexPath *)location; - -- (BOOL)isEqual:(id)object; -- (BOOL)isEqualToRange:(MPRange *)aRange; - -@end \ No newline at end of file diff --git a/MathPad/MPRange.m b/MathPad/MPRange.m deleted file mode 100644 index b85d0dd..0000000 --- a/MathPad/MPRange.m +++ /dev/null @@ -1,140 +0,0 @@ -// -// MPRange.m -// MathPad -// -// Created by Kim Wittenburg on 18.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "MPRange.h" - -@implementation MPRange - -#pragma mark Creation Methods - -- (instancetype)init -{ - return [self initWithLocation:[[NSIndexPath alloc] init] - length:0]; -} - -- (instancetype)initWithLocation:(NSIndexPath *)location - length:(NSUInteger)length -{ - self = [super init]; - if (self) { - _location = location; - _length = length; - } - return self; -} - -- (instancetype)initWithRange:(NSRange)aRange -{ - return [self initWithLocation:[[NSIndexPath alloc] initWithIndex:aRange.location] - length:aRange.length]; -} - -+ (instancetype)emptyRange -{ - return [[self alloc] init]; -} - -+ (instancetype)rangeWithLocation:(NSIndexPath *)location - length:(NSUInteger)length -{ - return [[self alloc] initWithLocation:location - length:length]; -} - -+ (instancetype)rangeWithRange:(NSRange)aRange -{ - return [[self alloc] initWithRange:aRange]; -} - -#pragma mark Properties - -- (NSIndexPath *)maxRange -{ - NSUInteger lastIndex = [self.location indexAtPosition:self.location.length-1]; - NSUInteger newLastIndex = lastIndex + self.length; - return [[self.location indexPathByRemovingLastIndex] indexPathByAddingIndex:newLastIndex]; -} - -- (NSRange)rangeAtLastIndex -{ - return NSMakeRange([self.location indexAtPosition:self.location.length-1], self.length); -} - -#pragma mark Working with Ranges - -- (BOOL)containsRange:(MPRange *)aRange -{ - if (aRange.location.length < self.location.length) { - return NO; - } - // Compare indices (except the last one) - for (NSUInteger pos = 0; pos < self.location.length-1; pos++) { - NSUInteger selfIndex = [self.location indexAtPosition:pos]; - NSUInteger otherIndex = [aRange.location indexAtPosition:pos]; - if (selfIndex != otherIndex) { - return NO; - } - } - // Compare range at last index - NSUInteger selfIndex = [self.location indexAtPosition:self.location.length-1]; - NSUInteger otherIndex = [aRange.location indexAtPosition:self.location.length-1]; - if (aRange.location.length > self.location.length) { - return NSLocationInRange(otherIndex, self.rangeAtLastIndex); - } else { - return otherIndex >= selfIndex && NSMaxRange(aRange.rangeAtLastIndex) <= NSMaxRange(self.rangeAtLastIndex); - } -} - -- (BOOL)containsLocation:(NSIndexPath *)location -{ - return [self containsRange:[[MPRange alloc] initWithLocation:location length:0]]; -} - -- (BOOL)isEqual:(id)object -{ - if (self == object) { - return YES; - } - if (object == nil) { - return NO; - } - if (![object isKindOfClass:[MPRange class]]) { - return NO; - } - return [self isEqualToRange:(MPRange *)object]; -} - -- (BOOL)isEqualToRange:(MPRange *)aRange -{ - return [self.location isEqual:aRange.location] && self.length == aRange.length; -} - -#pragma mark - NSCopying - -- (id)copyWithZone:(NSZone *)zone -{ - MPRange *copy = [[MPRange allocWithZone:zone] initWithLocation:self.location.copy length:self.length]; - return copy; -} - -#pragma mark - NSCoding - -- (id)initWithCoder:(NSCoder *)aDecoder -{ - return [self initWithLocation:[aDecoder decodeObjectForKey:@"location"] - length:[aDecoder decodeIntegerForKey:@"length"]]; -} - -- (void)encodeWithCoder:(NSCoder *)aCoder -{ - [aCoder encodeObject:self.location forKey:@"location"]; - [aCoder encodeInteger:self.length forKey:@"length"]; -} - -@end diff --git a/MathPad/MPView.h b/MathPad/MPView.h deleted file mode 100644 index 825212a..0000000 --- a/MathPad/MPView.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// MPView.h -// MathPad -// -// Created by Kim Wittenburg on 21.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -/* - This is a convenience header which imports all view classes defined by MathPad. - */ - -#ifndef MathPad_MPView_h -#define MathPad_MPView_h - -#import "MPExpressionView.h" -#import "MPExpressionStorage.h" - -#endif diff --git a/MathPad/NSIndexPath+MPRemoveFirstIndex.h b/MathPad/NSIndexPath+MPRemoveFirstIndex.h deleted file mode 100644 index 5cdb721..0000000 --- a/MathPad/NSIndexPath+MPRemoveFirstIndex.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// NSIndexPath+MPRemoveFirstIndex.h -// MathPad -// -// Created by Kim Wittenburg on 23.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import - -@interface NSIndexPath (MPRemoveFirstIndex) - -/*! - @method indexPathByRemovingFirstIndex - @brief Provides an index path with the indexes in the receiving index path, excluding the first one. - @discussion Returns an empty NSIndexPath instance if the receiving index path’s length is 1 or less. - @return New index path with the receiving index path’s indexes, excluding the first one. - */ -- (NSIndexPath *)indexPathByRemovingFirstIndex; - -@end diff --git a/MathPad/NSIndexPath+MPRemoveFirstIndex.m b/MathPad/NSIndexPath+MPRemoveFirstIndex.m deleted file mode 100644 index 99997af..0000000 --- a/MathPad/NSIndexPath+MPRemoveFirstIndex.m +++ /dev/null @@ -1,27 +0,0 @@ -// -// NSIndexPath+MPRemoveFirstIndex.m -// MathPad -// -// Created by Kim Wittenburg on 23.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "NSIndexPath+MPRemoveFirstIndex.h" - -@implementation NSIndexPath (MPRemoveFirstIndex) - -- (NSIndexPath *)indexPathByRemovingFirstIndex -{ - if (self.length <= 1) { - return [[NSIndexPath alloc] init]; - } - NSUInteger indexes[self.length]; - [self getIndexes:indexes]; - NSUInteger newIndexes[self.length-1]; - for (NSUInteger i = 0; i < self.length-1; i++) { - newIndexes[i] = indexes[i+1]; - } - return [[NSIndexPath alloc] initWithIndexes:newIndexes length:self.length-1]; -} - -@end diff --git a/MathPad/NSIndexPath+MPReverseIndexPath.h b/MathPad/NSIndexPath+MPReverseIndexPath.h deleted file mode 100644 index b9bc20e..0000000 --- a/MathPad/NSIndexPath+MPReverseIndexPath.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// NSIndexPath+MPRemoveFirstIndex.h -// MathPad -// -// Created by Kim Wittenburg on 23.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import - -@interface NSIndexPath (MPReverseIndexPath) - -/*! - @method indexPathByRemovingFirstIndex - @brief Provides an index path with the indexes in the receiving index path, excluding the first one. - @discussion Returns an empty NSIndexPath instance if the receiving index path’s length is 1 or less. - @return New index path with the receiving index path’s indexes, excluding the first one. - */ -- (NSIndexPath *)indexPathByRemovingFirstIndex; - -- (NSIndexPath *)indexPathByPrecedingIndex:(NSUInteger)index; - -@end diff --git a/MathPad/NSIndexPath+MPReverseIndexPath.m b/MathPad/NSIndexPath+MPReverseIndexPath.m deleted file mode 100644 index b04fd86..0000000 --- a/MathPad/NSIndexPath+MPReverseIndexPath.m +++ /dev/null @@ -1,37 +0,0 @@ -// -// NSIndexPath+MPRemoveFirstIndex.m -// MathPad -// -// Created by Kim Wittenburg on 23.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "NSIndexPath+MPReverseIndexPath.h" - -@implementation NSIndexPath (MPReverseIndexPath) - -- (NSIndexPath *)indexPathByRemovingFirstIndex -{ - if (self.length <= 1) { - return [[NSIndexPath alloc] init]; - } - NSUInteger indexes[self.length]; - [self getIndexes:indexes]; - NSUInteger newIndexes[self.length-1]; - for (NSUInteger i = 0; i < self.length-1; i++) { - newIndexes[i] = indexes[i+1]; - } - return [[NSIndexPath alloc] initWithIndexes:newIndexes length:self.length-1]; -} - -- (NSIndexPath *)indexPathByPrecedingIndex:(NSUInteger)index -{ - NSUInteger newIndexes[self.length+1]; - newIndexes[0] = index; - for (NSUInteger i = 0; i < self.length; i++) { - newIndexes[i+1] = [self indexAtPosition:i]; - } - return [[NSIndexPath alloc] initWithIndexes:newIndexes length:self.length+1]; -} - -@end diff --git a/MathPad/NSObject+MPStringTest.h b/MathPad/NSObject+MPStringTest.h deleted file mode 100644 index 8e6a32b..0000000 --- a/MathPad/NSObject+MPStringTest.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// NSObject+MPStringTest.h -// MathPad -// -// Created by Kim Wittenburg on 20.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import - -@interface NSObject (MPStringTest) - -/*! - @method isString - @brief Returns wether the receiver is a string object. - @discussion A string object is an instance of the @c NSString class or any of its subclasses (for example @c NSMutableString). For an @c NSAttributedString this method returns @c NO. - @return @c YES if the receiver is an instance of @c NSString or a subclass, @c NO otherwise. - */ -- (BOOL)isString; - -@end diff --git a/MathPad/NSObject+MPStringTest.m b/MathPad/NSObject+MPStringTest.m deleted file mode 100644 index 6a3fe2f..0000000 --- a/MathPad/NSObject+MPStringTest.m +++ /dev/null @@ -1,18 +0,0 @@ -// -// NSObject+MPStringTest.m -// MathPad -// -// Created by Kim Wittenburg on 20.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "NSObject+MPStringTest.h" - -@implementation NSObject (MPStringTest) - -- (BOOL)isString -{ - return [self isKindOfClass:[NSString class]]; -} - -@end diff --git a/MathPad/NSTextStorage+MPSetContents.h b/MathPad/NSTextStorage+MPSetContents.h deleted file mode 100644 index ff1a798..0000000 --- a/MathPad/NSTextStorage+MPSetContents.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// NSTextStorage+MPSetContents.h -// MathPad -// -// Created by Kim Wittenburg on 21.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import - -@interface NSTextStorage (MPSetContents) - -/*! - @method setString: - @brief Replaces the contents of the receiver with @c aString. - @discussion This method sends the receiver a @c replaceCharactersInRange:withString: with a range including all characters of the receiver and @c aString. See @c replaceCharactersInRange:withString: for details. - @param aString A string specifying the characters to replace the receiver's current contents. - */ -- (void)setString:(NSString *)aString; - -@end diff --git a/MathPad/NSTextStorage+MPSetContents.m b/MathPad/NSTextStorage+MPSetContents.m deleted file mode 100644 index c1f2b4d..0000000 --- a/MathPad/NSTextStorage+MPSetContents.m +++ /dev/null @@ -1,19 +0,0 @@ -// -// NSTextStorage+MPSetContents.m -// MathPad -// -// Created by Kim Wittenburg on 21.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import "NSTextStorage+MPSetContents.h" - -@implementation NSTextStorage (MPSetContents) - -- (void)setString:(NSString *)string -{ - NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string]; - [self setAttributedString:attributedString]; -} - -@end diff --git a/MathPadTests/MPMutableExpressionTests.m b/MathPadTests/MPMutableExpressionTests.m deleted file mode 100644 index 532ab02..0000000 --- a/MathPadTests/MPMutableExpressionTests.m +++ /dev/null @@ -1,61 +0,0 @@ -// -// MPMutableExpressionTests.m -// MathPad -// -// Created by Kim Wittenburg on 19.04.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import -#import "MPExpression.h" -#import "MPFunction.h" - -@interface MPMutableExpressionTests : XCTestCase - -@end - -@implementation MPMutableExpressionTests - -- (void)testMutating { - MPMutableExpression *testExpression = [[MPMutableExpression alloc] initWithSymbols:@[@"1234", [[MPFunction alloc] init], @"5678", [[MPFunction alloc] init]]]; - - [testExpression appendString:@"90"]; - XCTAssertEqual([testExpression numberOfSymbols], 5); - // 1234 [] 5678 [] 90 - - [testExpression deleteSymbolsInRange:NSMakeRange(2, 4)]; - XCTAssertEqual([testExpression numberOfSymbols], 3); - // 12678 [] 90 - - [testExpression insertFunction:[[MPFunction alloc] init] - atIndex:2]; - XCTAssertEqual([testExpression numberOfSymbols], 5); - // 12 [] 678 [] 90 - - [testExpression replaceSymbolsInRange:NSMakeRange(2, 5) - withSymbols:@[[[MPFunction alloc] init]]]; - XCTAssertEqual([testExpression numberOfSymbols], 3); - // 12 [] 90 - - [testExpression setString:@"abc"]; - XCTAssertEqual([testExpression numberOfSymbols], 1); - // abc - - [testExpression setString:@""]; - XCTAssertEqual([testExpression numberOfSymbols], 0); - // - - [testExpression setString:@"1234"]; - XCTAssertEqual([testExpression numberOfSymbols], 1); -} - -- (void)testInvalidMutatingRange { - @try { - MPMutableExpression *testExpression = [[MPMutableExpression alloc] initWithSymbols:@[@"1234", [[MPFunction alloc] init], @"5678", [[MPFunction alloc] init]]]; - [testExpression deleteSymbolsInRange:NSMakeRange(5, 17)]; - XCTFail(@"Should have raised an exception"); - } - @catch (NSException *exception) {} -} - -@end diff --git a/MathPadTests/MathPadTests.m b/MathPadTests/MathPadTests.m deleted file mode 100644 index 8afb77f..0000000 --- a/MathPadTests/MathPadTests.m +++ /dev/null @@ -1,34 +0,0 @@ -// -// MathPadTests.m -// MathPadTests -// -// Created by Kim Wittenburg on 23.03.14. -// Copyright (c) 2014 Kim Wittenburg. All rights reserved. -// - -#import - -@interface MathPadTests : XCTestCase - -@end - -@implementation MathPadTests - -- (void)setUp -{ - [super setUp]; - // Put setup code here. This method is called before the invocation of each test method in the class. -} - -- (void)tearDown -{ - // Put teardown code here. This method is called after the invocation of each test method in the class. - [super tearDown]; -} - -- (void)testExample -{ - XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); -} - -@end