Permalink
Browse files

Sorted build settings for iOS core parse; Added check to see that all…

… used non-terminals are defined in a grammar.
  • Loading branch information...
1 parent 07964a5 commit 77ff439ca5f0d9c5c62d1356d473be8c1868fb56 Tom Davie committed Oct 12, 2012
@@ -1062,7 +1062,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = "";
SUPPORTED_PLATFORMS = macosx;
- VALID_ARCHS = "armv6 i386 x86_64 armv7";
+ VALID_ARCHS = "i386 x86_64 armv7 armv7s";
};
name = Debug;
};
@@ -1098,7 +1098,7 @@
ONLY_ACTIVE_ARCH = NO;
SDKROOT = "";
SUPPORTED_PLATFORMS = macosx;
- VALID_ARCHS = "armv6 i386 x86_64 armv7";
+ VALID_ARCHS = "i386 x86_64 armv7 armv7s";
};
name = Release;
};
@@ -1236,24 +1236,21 @@
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
+ ONLY_ACTIVE_ARCH = NO;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = CoreParse;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
- VALID_ARCHS = "armv6 armv7";
+ VALID_ARCHS = "armv7 armv7s";
};
name = Debug;
};
1F92819F145C11050033BC34 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- ARCHS = (
- i386,
- armv7,
- armv7s,
- );
+ ARCHS = "$(ARCHS_STANDARD_32_BIT)";
COPY_PHASE_STRIP = YES;
DSTROOT = /tmp/iOSCoreParse.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
@@ -1266,7 +1263,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
VALIDATE_PRODUCT = YES;
- VALID_ARCHS = "armv6 armv7";
+ VALID_ARCHS = "armv7 armv7s";
};
name = Release;
};
@@ -15,8 +15,9 @@
typedef enum
{
- CPErrorCodeCouldNotParseEBNF = 1,
- CPErrorCodeDuplicateTag = 2,
+ CPErrorCodeCouldNotParseEBNF = 1,
+ CPErrorCodeDuplicateTag = 2,
+ CPErrorCodeUndefinedNonTerminal = 3,
} CPErrorCode;
/**
@@ -315,12 +315,25 @@ - (id)initWithStart:(NSString *)initStart backusNaurForm:(NSString *)bnf error:(
{
*error = [[[del err] copy] autorelease];
}
+ [self release];
+ return nil;
+ }
+
+ NSError *e = [self checkForMissingNonTerminalsInRules:initRules];
+ if (nil != e)
+ {
+ if (NULL != error)
+ {
+ *error = e;
+ }
+ [self release];
return nil;
}
NSArray *newRules = [self tidyRightHandSides:initRules error:error];
if (nil == newRules)
{
+ [self release];
return nil;
}
@@ -367,6 +380,46 @@ - (NSSet *)allRules
return [NSSet setWithArray:[self rules]];
}
+- (NSError *)checkForMissingNonTerminalsInRules:(NSArray *)rules
+{
+ NSMutableSet *definedNonTerminals = [NSMutableSet setWithCapacity:[rules count]];
+ for (CPRule *rule in rules)
+ {
+ [definedNonTerminals addObject:[rule name]];
+ }
+
+ for (CPRule *rule in rules)
+ {
+ for (id item in [rule rightHandSideElements])
+ {
+ if ([item isGrammarSymbol] && ![(CPGrammarSymbol *)item isTerminal] && ![definedNonTerminals containsObject:[(CPGrammarSymbol *)item name]])
+ {
+ return [NSError errorWithDomain:CPEBNFParserErrorDomain
+ code:CPErrorCodeUndefinedNonTerminal
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSString stringWithFormat:@"Could not find definition of %@, used in %@", [item name], rule], NSLocalizedDescriptionKey,
+ nil]];
+ }
+ else if ([item isRHSItem])
+ {
+ NSSet *usedNonTerminals = [(CPRHSItem *)item nonTerminalsUsed];
+ if (![usedNonTerminals isSubsetOfSet:definedNonTerminals])
+ {
+ NSMutableSet *mutableUsedNonTerminals = [[usedNonTerminals mutableCopy] autorelease];
+ [mutableUsedNonTerminals minusSet:definedNonTerminals];
+ return [NSError errorWithDomain:CPEBNFParserErrorDomain
+ code:CPErrorCodeUndefinedNonTerminal
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSString stringWithFormat:@"Could not find definition of %@, used in %@", [mutableUsedNonTerminals anyObject], rule], NSLocalizedDescriptionKey,
+ nil]];
+ }
+ }
+ }
+ }
+
+ return nil;
+}
+
- (NSArray *)allNonTerminalNames
{
return [[self rulesByNonTerminal] allKeys];
@@ -19,6 +19,8 @@
@property (readwrite,assign) BOOL shouldCollapse;
+- (NSSet *)nonTerminalsUsed;
+
@end
@interface NSObject (CPIsRHSItem)
@@ -113,6 +113,26 @@ - (void)setTags:(NSSet *)tags
}
}
+- (NSSet *)nonTerminalsUsed
+{
+ NSMutableSet *nonTerminals = [NSMutableSet set];
+ for (NSArray *alternative in [self alternatives])
+ {
+ for (id item in alternative)
+ {
+ if ([item isGrammarSymbol] && ![(CPGrammarSymbol *)item isTerminal])
+ {
+ [nonTerminals addObject:[(CPGrammarSymbol *)item name]];
+ }
+ else if ([item isRHSItem])
+ {
+ [nonTerminals unionSet:[(CPRHSItem *)item nonTerminalsUsed]];
+ }
+ }
+ }
+ return nonTerminals;
+}
+
@end
@implementation CPRHSItem (Private)
@@ -889,4 +889,15 @@ - (void)testErrorRecovery
STAssertEquals([result intValue], 45, @"Parsed expression had incorrect value", nil);
}
+- (void)testValidGrammar
+{
+ NSString *bnf =
+ @"A ::= <B> <C>;"
+ @"B ::= 'B';";
+ NSError *err = nil;
+ CPGrammar *grammar = [CPGrammar grammarWithStart:@"A" backusNaurForm:bnf error:&err];
+ STAssertNil(grammar, @"Grammar returned for invalid BNF");
+ STAssertNotNil(err, @"No error returned for creating a grammar with invalid BNF");
+}
+
@end

0 comments on commit 77ff439

Please sign in to comment.