Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
2 parents f6ab6eb + bf97476 commit f3ecdaf815c5e25b7c705f3bb36e15d9bb3efa94 @andrimarjonsson andrimarjonsson committed Aug 22, 2012
@@ -128,6 +128,10 @@
1F9F83A613B732AC006E939D /* Term.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F9F83A413B732AC006E939D /* Term.h */; };
1F9F83AC13B7CABA006E939D /* CPRHSItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F9F83AA13B7CAB9006E939D /* CPRHSItem.h */; };
1F9F83AD13B7CABA006E939D /* CPRHSItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F9F83AB13B7CABA006E939D /* CPRHSItem.m */; };
+ 1FA6430215E2B9790004FCD3 /* NSObject+IsCoreParseObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FA6430015E2B9790004FCD3 /* NSObject+IsCoreParseObject.h */; };
+ 1FA6430315E2B9790004FCD3 /* NSObject+IsCoreParseObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FA6430115E2B9790004FCD3 /* NSObject+IsCoreParseObject.m */; };
+ 1FA6430715E2C5130004FCD3 /* NSArray+Functional.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FA6430515E2C5130004FCD3 /* NSArray+Functional.h */; };
+ 1FA6430815E2C5130004FCD3 /* NSArray+Functional.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FA6430615E2C5130004FCD3 /* NSArray+Functional.m */; };
1FA68DA014DE98C4005519B9 /* CPErrorToken.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FA68D9E14DE98C4005519B9 /* CPErrorToken.h */; settings = {ATTRIBUTES = (Public, ); }; };
1FA68DA114DE98C4005519B9 /* CPErrorToken.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FA68D9F14DE98C4005519B9 /* CPErrorToken.m */; };
1FA68DA514DE9D3D005519B9 /* CPTestErrorHandlingDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FA68DA314DE9D3D005519B9 /* CPTestErrorHandlingDelegate.h */; };
@@ -140,6 +144,7 @@
1FA798261567DC58003AC8AE /* CPTestMapCSSTokenisingDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FB81325132FF16E0095982D /* CPTestMapCSSTokenisingDelegate.m */; };
1FA798271567DC5C003AC8AE /* CPTestErrorHandlingDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FA68DA414DE9D3D005519B9 /* CPTestErrorHandlingDelegate.m */; };
1FA866B715DFAEBC005350EE /* CPRule+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FA866B515DFAEBB005350EE /* CPRule+Internal.h */; };
+ 1FA866C015E18F68005350EE /* CPRHSItem+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FA866BE15E18F67005350EE /* CPRHSItem+Private.h */; };
1FB3EB24132BA02C00ACC453 /* CPTestEvaluatorDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FB3EB22132BA02C00ACC453 /* CPTestEvaluatorDelegate.h */; };
1FB3EB25132BA02C00ACC453 /* CPTestEvaluatorDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FB3EB23132BA02C00ACC453 /* CPTestEvaluatorDelegate.m */; };
1FB3EB2C132BB2F200ACC453 /* CPLR1Parser.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FB3EB2A132BB2E600ACC453 /* CPLR1Parser.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -269,11 +274,16 @@
1F9F83A513B732AC006E939D /* Term.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Term.m; sourceTree = "<group>"; };
1F9F83AA13B7CAB9006E939D /* CPRHSItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPRHSItem.h; sourceTree = "<group>"; };
1F9F83AB13B7CABA006E939D /* CPRHSItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPRHSItem.m; sourceTree = "<group>"; };
+ 1FA6430015E2B9790004FCD3 /* NSObject+IsCoreParseObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+IsCoreParseObject.h"; sourceTree = "<group>"; };
+ 1FA6430115E2B9790004FCD3 /* NSObject+IsCoreParseObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+IsCoreParseObject.m"; sourceTree = "<group>"; };
+ 1FA6430515E2C5130004FCD3 /* NSArray+Functional.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+Functional.h"; sourceTree = "<group>"; };
+ 1FA6430615E2C5130004FCD3 /* NSArray+Functional.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Functional.m"; sourceTree = "<group>"; };
1FA68D9E14DE98C4005519B9 /* CPErrorToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPErrorToken.h; sourceTree = "<group>"; };
1FA68D9F14DE98C4005519B9 /* CPErrorToken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPErrorToken.m; sourceTree = "<group>"; };
1FA68DA314DE9D3D005519B9 /* CPTestErrorHandlingDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPTestErrorHandlingDelegate.h; sourceTree = "<group>"; };
1FA68DA414DE9D3D005519B9 /* CPTestErrorHandlingDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPTestErrorHandlingDelegate.m; sourceTree = "<group>"; };
1FA866B515DFAEBB005350EE /* CPRule+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPRule+Internal.h"; sourceTree = "<group>"; };
+ 1FA866BE15E18F67005350EE /* CPRHSItem+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CPRHSItem+Private.h"; sourceTree = "<group>"; };
1FB3EB22132BA02C00ACC453 /* CPTestEvaluatorDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPTestEvaluatorDelegate.h; sourceTree = "<group>"; };
1FB3EB23132BA02C00ACC453 /* CPTestEvaluatorDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CPTestEvaluatorDelegate.m; sourceTree = "<group>"; };
1FB3EB2A132BB2E600ACC453 /* CPLR1Parser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CPLR1Parser.h; sourceTree = "<group>"; };
@@ -398,6 +408,10 @@
DA2B1DF41566B311002FDBD7 /* CPSenTestKitAssertions.h */,
1F38820B132432A1000C8876 /* NSSetFunctional.h */,
1F38820C132432AA000C8876 /* NSSetFunctional.m */,
+ 1FA6430515E2C5130004FCD3 /* NSArray+Functional.h */,
+ 1FA6430615E2C5130004FCD3 /* NSArray+Functional.m */,
+ 1FA6430015E2B9790004FCD3 /* NSObject+IsCoreParseObject.h */,
+ 1FA6430115E2B9790004FCD3 /* NSObject+IsCoreParseObject.m */,
);
path = CoreParse;
sourceTree = "<group>";
@@ -553,6 +567,7 @@
1FA866B515DFAEBB005350EE /* CPRule+Internal.h */,
1FB3EB38132D096700ACC453 /* CPGrammarSymbol.h */,
1FB3EB39132D096800ACC453 /* CPGrammarSymbol.m */,
+ 1FA866BE15E18F67005350EE /* CPRHSItem+Private.h */,
1F9F83AA13B7CAB9006E939D /* CPRHSItem.h */,
1F9F83AB13B7CABA006E939D /* CPRHSItem.m */,
1FC00D4E14544EDC00DC8D35 /* CPRHSItemResult.h */,
@@ -653,6 +668,9 @@
1FA68DA514DE9D3D005519B9 /* CPTestErrorHandlingDelegate.h in Headers */,
1F893A2314DEF40D00316FF7 /* CPTestErrorEvaluatorDelegate.h in Headers */,
1FA866B715DFAEBC005350EE /* CPRule+Internal.h in Headers */,
+ 1FA866C015E18F68005350EE /* CPRHSItem+Private.h in Headers */,
+ 1FA6430215E2B9790004FCD3 /* NSObject+IsCoreParseObject.h in Headers */,
+ 1FA6430715E2C5130004FCD3 /* NSArray+Functional.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -902,6 +920,8 @@
1FA68DA614DE9D3D005519B9 /* CPTestErrorHandlingDelegate.m in Sources */,
1F893A2014DEEBFC00316FF7 /* CPRecoveryAction.m in Sources */,
1F893A2414DEF40D00316FF7 /* CPTestErrorEvaluatorDelegate.m in Sources */,
+ 1FA6430315E2B9790004FCD3 /* NSObject+IsCoreParseObject.m in Sources */,
+ 1FA6430815E2C5130004FCD3 /* NSArray+Functional.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -16,6 +16,7 @@
typedef enum
{
CPErrorCodeCouldNotParseEBNF = 1,
+ CPErrorCodeDuplicateTag = 2,
} CPErrorCode;
/**
@@ -314,7 +314,11 @@ - (id)initWithStart:(NSString *)initStart backusNaurForm:(NSString *)bnf error:(
return nil;
}
- NSArray *newRules = [self tidyRightHandSides:initRules];
+ NSArray *newRules = [self tidyRightHandSides:initRules error:error];
+ if (nil == newRules)
+ {
+ return nil;
+ }
return [self initWithStart:initStart rules:newRules];
}
@@ -29,7 +29,7 @@
- (NSString *)uniqueSymbolNameBasedOnName:(NSString *)name;
- (NSString *)symbolNameNotInSet:(NSSet *)symbols basedOnName:(NSString *)name;
-- (NSArray *)tidyRightHandSides:(NSArray *)oldRules;
+- (NSArray *)tidyRightHandSides:(NSArray *)oldRules error:(NSError **)error;
- (NSSet *)collectRHSElementsForNewRules:(NSArray *)rightHandSide;
- (NSDictionary *)nameNewRules:(NSSet *)rhsElements withRules:(NSArray *)oldRules;
- (NSArray *)addRHSRules:(NSDictionary *)rules toRules:(NSArray *)oldRules;
@@ -15,6 +15,7 @@
#import "CPLR1Item.h"
#import "CPRHSItem.h"
+#import "CPRHSItem+Private.h"
#import "CPRHSItemResult.h"
#import "NSSetFunctional.h"
@@ -240,8 +241,15 @@ - (NSString *)symbolNameNotInSet:(NSSet *)symbols basedOnName:(NSString *)name
return testName;
}
-- (NSArray *)tidyRightHandSides:(NSArray *)oldRules
+- (NSArray *)tidyRightHandSides:(NSArray *)oldRules error:(NSError **)error
{
+ NSError *invalidRuleError = [self checkRulesForErrors:oldRules];
+ if (nil != invalidRuleError)
+ {
+ *error = invalidRuleError;
+ return nil;
+ }
+
NSMutableSet *rhsElements = [NSMutableSet set];
for (CPRule *r in oldRules)
{
@@ -253,6 +261,54 @@ - (NSArray *)tidyRightHandSides:(NSArray *)oldRules
return [self addRHSRules:names toRules:oldRules];
}
+- (NSError *)checkRulesForErrors:(NSArray *)rules
+{
+ NSError *error = nil;
+ Class itemClass = [CPRHSItem class];
+ for (CPRule *rule in rules)
+ {
+ NSArray *rightHandSide = [rule rightHandSideElements];
+ NSMutableSet *tagNames = [NSMutableSet set];
+ for (id element in rightHandSide)
+ {
+ if ([element isKindOfClass:itemClass])
+ {
+ NSSet *newTagNames = [(CPRHSItem *)element tagNamesWithError:&error];
+ if (nil != error)
+ {
+ return error;
+ }
+ NSMutableSet *duplicateTags = [[tagNames mutableCopy] autorelease];
+ [duplicateTags intersectSet:newTagNames];
+ if ([duplicateTags count] > 0)
+ {
+ return [NSError errorWithDomain:CPEBNFParserErrorDomain
+ code:CPErrorCodeDuplicateTag
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSString stringWithFormat:@"Duplicate tag names %@ in same part of alternative is not allowed in \"%@\".", duplicateTags, rule], NSLocalizedDescriptionKey,
+ nil]];
+ }
+ [tagNames unionSet:newTagNames];
+ NSString *tagName = [(CPRHSItem *)element tag];
+ if (nil != tagName)
+ {
+ if ([tagNames containsObject:tagName])
+ {
+ return [NSError errorWithDomain:CPEBNFParserErrorDomain
+ code:CPErrorCodeDuplicateTag
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSString stringWithFormat:@"Duplicate tag names (%@) in same part of alternative is not allowed in \"%@\".", tagName, rule], NSLocalizedDescriptionKey,
+ nil]];
+ }
+ [tagNames addObject:tagName];
+ }
+ }
+ }
+ }
+
+ return nil;
+}
+
- (NSSet *)collectRHSElementsForNewRules:(NSArray *)rightHandSide
{
NSMutableSet *ret = [NSMutableSet set];
@@ -0,0 +1,15 @@
+//
+// CPRHSItem+Private.h
+// CoreParse
+//
+// Created by Tom Davie on 19/08/2012.
+// Copyright (c) 2012 In The Beginning... All rights reserved.
+//
+
+#import "CPRHSItem.h"
+
+@interface CPRHSItem (Private)
+
+- (NSSet *)tagNamesWithError:(NSError **)err;
+
+@end
@@ -8,6 +8,9 @@
#import "CPRHSItem.h"
+#import "CPRHSItem+Private.h"
+#import "CPGrammar.h"
+
@implementation CPRHSItem
@synthesize alternatives = _alternatives;
@@ -28,8 +31,8 @@ - (BOOL)isEqual:(id)object
[self repeats] == [object repeats] &&
[self mayNotExist] == [object mayNotExist] &&
[self shouldCollapse] == [object shouldCollapse] &&
- (([self tag] == nil && [object tag] == nil) ||
- [[self tag] isEqualToString:[object tag]]));
+ (([self tag] == nil && [(CPRHSItem *)object tag] == nil) ||
+ [[self tag] isEqualToString:[(CPRHSItem *)object tag]]));
}
- (id)copyWithZone:(NSZone *)zone
@@ -91,3 +94,68 @@ - (NSString *)description
}
@end
+
+@implementation CPRHSItem (Private)
+
+- (NSSet *)tagNamesWithError:(NSError **)err
+{
+ Class itemClass = [CPRHSItem class];
+ NSMutableSet *tagNames = [NSMutableSet set];
+
+ for (NSArray *components in [self alternatives])
+ {
+ NSMutableSet *tagNamesInAlternative = [NSMutableSet set];
+ for (id comp in components)
+ {
+ if ([comp isKindOfClass:itemClass])
+ {
+ NSSet *newTagNames = [(CPRHSItem *)comp tagNamesWithError:err];
+ if (nil != *err)
+ {
+ return nil;
+ }
+ NSMutableSet *duplicateTags = [[tagNamesInAlternative mutableCopy] autorelease];
+ [duplicateTags intersectSet:newTagNames];
+ if ([duplicateTags count] > 0)
+ {
+ *err = [NSError errorWithDomain:CPEBNFParserErrorDomain
+ code:CPErrorCodeDuplicateTag
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSString stringWithFormat:@"Duplicate tag names %@ in same part of alternative is not allowed in \"%@\".", duplicateTags, self], NSLocalizedDescriptionKey,
+ nil]];
+ return nil;
+ }
+ [tagNamesInAlternative unionSet:newTagNames];
+ NSString *tagName = [(CPRHSItem *)comp tag];
+ if (nil != tagName)
+ {
+ if ([tagNamesInAlternative containsObject:tagName])
+ {
+ *err = [NSError errorWithDomain:CPEBNFParserErrorDomain
+ code:CPErrorCodeDuplicateTag
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSString stringWithFormat:@"Duplicate tag names (%@) in same part of alternative is not allowed in \"%@\".", tagName, self], NSLocalizedDescriptionKey,
+ nil]];
+ return nil;
+ }
+ [tagNamesInAlternative addObject:tagName];
+ }
+ }
+ }
+ [tagNames unionSet:tagNamesInAlternative];
+ }
+
+ if ([tagNames count] > 0 && [self repeats])
+ {
+ *err = [NSError errorWithDomain:CPEBNFParserErrorDomain
+ code:CPErrorCodeDuplicateTag
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSString stringWithFormat:@"Tag names are not allowed within repeating section of rule \"%@\".", self], NSLocalizedDescriptionKey,
+ nil]];
+ return nil;
+ }
+
+ return tagNames;
+}
+
+@end
@@ -0,0 +1,15 @@
+//
+// NSArray+Functional.h
+// CoreParse
+//
+// Created by Tom Davie on 20/08/2012.
+// Copyright (c) 2012 In The Beginning... All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSArray (Functional)
+
+- (NSArray *)map:(id(^)(id obj))block;
+
+@end
@@ -0,0 +1,34 @@
+//
+// NSArray+Functional.m
+// CoreParse
+//
+// Created by Tom Davie on 20/08/2012.
+// Copyright (c) 2012 In The Beginning... All rights reserved.
+//
+
+#import "NSArray+Functional.h"
+
+@implementation NSArray (Functional)
+
+- (NSArray *)map:(id(^)(id obj))block
+{
+ NSUInteger c = [self count];
+ id *resultingObjects = malloc(c * sizeof(id));
+
+ NSUInteger nonNilCount = 0;
+ for (id obj in self)
+ {
+ id r = block(obj);
+ if (nil != r)
+ {
+ resultingObjects[nonNilCount] = r;
+ nonNilCount++;
+ }
+ }
+
+ NSArray *a = [NSArray arrayWithObjects:resultingObjects count:nonNilCount];
+ free(resultingObjects);
+ return a;
+}
+
+@end
@@ -0,0 +1,15 @@
+//
+// NSObject+IsCoreParseObject.h
+// CoreParse
+//
+// Created by Tom Davie on 20/08/2012.
+// Copyright (c) 2012 In The Beginning... All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSObject (IsCoreParseObject)
+
+- (BOOL)isCPItem;
+
+@end
@@ -0,0 +1,18 @@
+//
+// NSObject+IsCoreParseObject.m
+// CoreParse
+//
+// Created by Tom Davie on 20/08/2012.
+// Copyright (c) 2012 In The Beginning... All rights reserved.
+//
+
+#import "NSObject+IsCoreParseObject.h"
+
+@implementation NSObject (IsCoreParseObject)
+
+- (BOOL)isCPItem
+{
+ return NO;
+}
+
+@end
Oops, something went wrong.

0 comments on commit f3ecdaf

Please sign in to comment.