Skip to content
Browse files

Significant optimisations, appears to nearly double parsing speed.

  • Loading branch information...
1 parent bf97476 commit ae776244b7feb9e2862333974a955bcf41f6a162 @beelsebob committed
Showing with 397 additions and 162 deletions.
  1. +0 −8 CoreParse.xcodeproj/project.pbxproj
  2. +1 −1 CoreParse/Built In Parsers/CPJSONParser.m
  3. +10 −9 CoreParse/Grammar/CPGrammar.m
  4. +3 −13 CoreParse/Grammar/CPGrammarInternal.m
  5. +1 −2 CoreParse/Grammar/CPGrammarPrivate.m
  6. +6 −0 CoreParse/Grammar/CPGrammarSymbol.h
  7. +17 −7 CoreParse/Grammar/CPGrammarSymbol.m
  8. +6 −0 CoreParse/Grammar/CPRHSItem.h
  9. +16 −3 CoreParse/Grammar/CPRHSItem.m
  10. +6 −0 CoreParse/Grammar/CPRHSItemResult.h
  11. +14 −0 CoreParse/Grammar/CPRHSItemResult.m
  12. +6 −0 CoreParse/Grammar/CPRule.h
  13. +18 −10 CoreParse/Grammar/CPRule.m
  14. +0 −15 CoreParse/NSObject+IsCoreParseObject.h
  15. +0 −18 CoreParse/NSObject+IsCoreParseObject.m
  16. +2 −2 CoreParse/Parsers/CPShiftReduceParser.m
  17. +8 −0 CoreParse/Parsers/CPShiftReduceParsers/CPItem.h
  18. +16 −4 CoreParse/Parsers/CPShiftReduceParsers/CPItem.m
  19. +6 −0 CoreParse/Parsers/CPShiftReduceParsers/CPLR1Item.h
  20. +18 −7 CoreParse/Parsers/CPShiftReduceParsers/CPLR1Item.m
  21. +6 −0 CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceAction.h
  22. +14 −1 CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceAction.m
  23. +6 −0 CoreParse/Syntax Tree/CPSyntaxTree.h
  24. +17 −6 CoreParse/Syntax Tree/CPSyntaxTree.m
  25. +6 −0 CoreParse/Tokenisation/CPTokenStream.h
  26. +15 −5 CoreParse/Tokenisation/CPTokenStream.m
  27. +6 −0 CoreParse/Tokenisation/Token Types/CPEOFToken.h
  28. +15 −2 CoreParse/Tokenisation/Token Types/CPEOFToken.m
  29. +6 −0 CoreParse/Tokenisation/Token Types/CPErrorToken.h
  30. +15 −1 CoreParse/Tokenisation/Token Types/CPErrorToken.m
  31. +7 −0 CoreParse/Tokenisation/Token Types/CPIdentifierToken.h
  32. +16 −6 CoreParse/Tokenisation/Token Types/CPIdentifierToken.m
  33. +6 −0 CoreParse/Tokenisation/Token Types/CPKeywordToken.h
  34. +15 −6 CoreParse/Tokenisation/Token Types/CPKeywordToken.m
  35. +6 −0 CoreParse/Tokenisation/Token Types/CPNumberToken.h
  36. +15 −10 CoreParse/Tokenisation/Token Types/CPNumberToken.m
  37. +6 −0 CoreParse/Tokenisation/Token Types/CPQuotedToken.h
  38. +17 −5 CoreParse/Tokenisation/Token Types/CPQuotedToken.m
  39. +6 −0 CoreParse/Tokenisation/Token Types/CPToken.h
  40. +11 −6 CoreParse/Tokenisation/Token Types/CPToken.m
  41. +6 −0 CoreParse/Tokenisation/Token Types/CPWhiteSpaceToken.h
  42. +17 −5 CoreParse/Tokenisation/Token Types/CPWhiteSpaceToken.m
  43. +4 −4 CoreParseTests/CPTestErrorEvaluatorDelegate.m
  44. +4 −4 CoreParseTests/CPTestMapCSSTokenisingDelegate.m
  45. +1 −2 CoreParseTests/CPTestWhiteSpaceIgnoringDelegate.m
View
8 CoreParse.xcodeproj/project.pbxproj
@@ -128,8 +128,6 @@
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, ); }; };
@@ -274,8 +272,6 @@
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>"; };
@@ -410,8 +406,6 @@
1F38820C132432AA000C8876 /* NSSetFunctional.m */,
1FA6430515E2C5130004FCD3 /* NSArray+Functional.h */,
1FA6430615E2C5130004FCD3 /* NSArray+Functional.m */,
- 1FA6430015E2B9790004FCD3 /* NSObject+IsCoreParseObject.h */,
- 1FA6430115E2B9790004FCD3 /* NSObject+IsCoreParseObject.m */,
);
path = CoreParse;
sourceTree = "<group>";
@@ -669,7 +663,6 @@
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;
@@ -920,7 +913,6 @@
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;
View
2 CoreParse/Built In Parsers/CPJSONParser.m
@@ -127,7 +127,7 @@ - (BOOL)tokeniser:(CPTokeniser *)tokeniser shouldConsumeToken:(CPToken *)token
- (NSArray *)tokeniser:(CPTokeniser *)tokeniser willProduceToken:(CPToken *)token
{
- if ([token isKindOfClass:[CPWhiteSpaceToken class]])
+ if ([token isWhiteSpaceToken])
{
return [NSArray array];
}
View
19 CoreParse/Grammar/CPGrammar.m
@@ -106,7 +106,7 @@ - (id)parser:(CPParser *)parser didProduceSyntaxTree:(CPSyntaxTree *)syntaxTree
case 11:
{
id i = [children objectAtIndex:2];
- if ([i isKindOfClass:[CPRHSItem class]])
+ if ([i isRHSItem])
{
[(CPRHSItem *)i setTag:[[children objectAtIndex:0] identifier]];
return i;
@@ -190,7 +190,7 @@ - (BOOL)tokeniser:(CPTokeniser *)tokeniser shouldConsumeToken:(CPToken *)token
- (NSArray *)tokeniser:(CPTokeniser *)tokeniser willProduceToken:(CPToken *)token
{
- if ([token isKindOfClass:[CPWhiteSpaceToken class]])
+ if ([token isWhiteSpaceToken])
{
return [NSArray array];
}
@@ -390,15 +390,16 @@ - (NSUInteger)hash
return [[self start] hash] << 16 + [[self rules] hash];
}
+- (BOOL)isGrammar
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPGrammar class]])
- {
- CPGrammar *other = (CPGrammar *)object;
- return [[other start] isEqualToString:[self start]] && [[other rules] isEqualToArray:[self rules]];
- }
-
- return NO;
+ return ([object isGrammar] &&
+ [((CPGrammar *)object)->start isEqualToString:start] &&
+ [[(CPGrammar *)object rules] isEqualToArray:[self rules]]);
}
@end
View
16 CoreParse/Grammar/CPGrammarInternal.m
@@ -264,14 +264,13 @@ - (NSArray *)tidyRightHandSides:(NSArray *)oldRules error:(NSError **)error
- (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])
+ if ([element isRHSItem])
{
NSSet *newTagNames = [(CPRHSItem *)element tagNamesWithError:&error];
if (nil != error)
@@ -312,10 +311,9 @@ - (NSError *)checkRulesForErrors:(NSArray *)rules
- (NSSet *)collectRHSElementsForNewRules:(NSArray *)rightHandSide
{
NSMutableSet *ret = [NSMutableSet set];
- Class itemClass = [CPRHSItem class];
for (id element in rightHandSide)
{
- if ([element isKindOfClass:itemClass])
+ if ([element isRHSItem])
{
[ret addObject:element];
for (NSArray *contents in [(CPRHSItem *)element alternatives])
@@ -411,21 +409,13 @@ - (NSArray *)addRHSRules:(NSDictionary *)newRules toRules:(NSArray *)oldRules
}
}
- Class itemClass = [CPRHSItem class];
for (CPRule *rule in rules)
{
NSArray *rhsElements = [rule rightHandSideElements];
NSMutableArray *newRightHandSideElements = [NSMutableArray arrayWithCapacity:[rhsElements count]];
for (id element in rhsElements)
{
- if ([element isKindOfClass:itemClass])
- {
- [newRightHandSideElements addObject:[CPGrammarSymbol nonTerminalWithName:[newRules objectForKey:element]]];
- }
- else
- {
- [newRightHandSideElements addObject:element];
- }
+ [newRightHandSideElements addObject:[element isRHSItem] ? [CPGrammarSymbol nonTerminalWithName:[newRules objectForKey:element]] : element];
}
[rule setRightHandSideElements:newRightHandSideElements];
}
View
3 CoreParse/Grammar/CPGrammarPrivate.m
@@ -124,13 +124,12 @@ - (NSSet *)symbolNamesInRules:(NSArray *)rules
{
NSMutableSet *symbols = [NSMutableSet set];
- Class grammarSymbolClass = [CPGrammarSymbol class];
for (CPRule *rule in rules)
{
[symbols addObject:[rule name]];
for (id sym in [rule rightHandSideElements])
{
- if ([sym isKindOfClass:grammarSymbolClass])
+ if ([sym isGrammarSymbol])
{
[symbols addObject:[sym name]];
}
View
6 CoreParse/Grammar/CPGrammarSymbol.h
@@ -68,3 +68,9 @@
@property (readwrite, assign, getter=isTerminal) BOOL terminal;
@end
+
+@interface NSObject (CPGrammarSymbol)
+
+- (BOOL)isGrammarSymbol;
+
+@end
View
24 CoreParse/Grammar/CPGrammarSymbol.m
@@ -8,7 +8,6 @@
#import "CPGrammarSymbol.h"
-
@implementation CPGrammarSymbol
@synthesize name;
@@ -64,14 +63,16 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
[aCoder encodeBool:[self isTerminal] forKey:CPGrammarSymbolTerminalKey];
}
+- (BOOL)isGrammarSymbol
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPGrammarSymbol class]])
- {
- CPGrammarSymbol *other = (CPGrammarSymbol *)object;
- return [other isTerminal] == [self isTerminal] && [[other name] isEqualToString:[self name]];
- }
- return NO;
+ return ([object isGrammarSymbol] &&
+ ((CPGrammarSymbol *)object)->terminal == terminal &&
+ [((CPGrammarSymbol *)object)->name isEqualToString:name]);
}
- (NSUInteger)hash
@@ -99,3 +100,12 @@ - (void)dealloc
}
@end
+
+@implementation NSObject (CPGrammarSymbol)
+
+- (BOOL)isGrammarSymbol
+{
+ return NO;
+}
+
+@end
View
6 CoreParse/Grammar/CPRHSItem.h
@@ -20,3 +20,9 @@
@property (readwrite,assign) BOOL shouldCollapse;
@end
+
+@interface NSObject (CPIsRHSItem)
+
+- (BOOL)isRHSItem;
+
+@end
View
19 CoreParse/Grammar/CPRHSItem.m
@@ -24,9 +24,14 @@ - (NSUInteger)hash
return [[self alternatives] hash] << 2 + ([self repeats] ? 0x2 : 0x0) + ([self mayNotExist] ? 0x1 : 0x0);
}
+- (BOOL)isRHSItem
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- return ([object isKindOfClass:[CPRHSItem class]] &&
+ return ([object isRHSItem] &&
[[self alternatives] isEqualToArray:[object alternatives]] &&
[self repeats] == [object repeats] &&
[self mayNotExist] == [object mayNotExist] &&
@@ -99,7 +104,6 @@ @implementation CPRHSItem (Private)
- (NSSet *)tagNamesWithError:(NSError **)err
{
- Class itemClass = [CPRHSItem class];
NSMutableSet *tagNames = [NSMutableSet set];
for (NSArray *components in [self alternatives])
@@ -107,7 +111,7 @@ - (NSSet *)tagNamesWithError:(NSError **)err
NSMutableSet *tagNamesInAlternative = [NSMutableSet set];
for (id comp in components)
{
- if ([comp isKindOfClass:itemClass])
+ if ([comp isRHSItem])
{
NSSet *newTagNames = [(CPRHSItem *)comp tagNamesWithError:err];
if (nil != *err)
@@ -159,3 +163,12 @@ - (NSSet *)tagNamesWithError:(NSError **)err
}
@end
+
+@implementation NSObject (CPIsRHSItem)
+
+- (BOOL)isRHSItem
+{
+ return NO;
+}
+
+@end
View
6 CoreParse/Grammar/CPRHSItemResult.h
@@ -18,3 +18,9 @@
@property (readwrite, copy ) NSDictionary *tagValues;
@end
+
+@interface NSObject (CPIsRHSItemResult)
+
+- (BOOL)isRHSItemResult;
+
+@end
View
14 CoreParse/Grammar/CPRHSItemResult.m
@@ -67,4 +67,18 @@ - (void)dealloc
[super dealloc];
}
+- (BOOL)isRHSItemResult
+{
+ return YES;
+}
+
+@end
+
+@implementation NSObject(CPIsRHSItemResult)
+
+- (BOOL)isRHSItemResult
+{
+ return NO;
+}
+
@end
View
6 CoreParse/Grammar/CPRule.h
@@ -136,3 +136,9 @@
@property (readwrite, assign) Class representitiveClass;
@end
+
+@interface NSObject (CPIsRule)
+
+- (BOOL)isRule;
+
+@end
View
28 CoreParse/Grammar/CPRule.m
@@ -137,18 +137,18 @@ - (NSUInteger)hash
return [name hash] << 16 + [self tag] ;
}
+- (BOOL)isRule
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPRule class]])
- {
- CPRule *other = (CPRule *)object;
- return ([other tag] == tag &&
- [[other name] isEqualToString:name] &&
- [[other rightHandSideElements] isEqualToArray:rightHandSide] &&
- (_tagName == nil || [[other tagName] isEqualToString:_tagName]));
- }
-
- return NO;
+ return ([object isRule] &&
+ ((CPRule *)object)->tag == tag &&
+ [((CPRule *)object)->name isEqualToString:name] &&
+ [((CPRule *)object)->rightHandSide isEqualToArray:rightHandSide] &&
+ (_tagName == nil || [((CPRule *)object)->_tagName isEqualToString:_tagName]));
}
@end
@@ -181,3 +181,11 @@ - (void)setTagName:(NSString *)tagName
@end
+@implementation NSObject (CPIsRule)
+
+- (BOOL)isRule
+{
+ return NO;
+}
+
+@end
View
15 CoreParse/NSObject+IsCoreParseObject.h
@@ -1,15 +0,0 @@
-//
-// 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
View
18 CoreParse/NSObject+IsCoreParseObject.m
@@ -1,18 +0,0 @@
-//
-// 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
View
4 CoreParse/Parsers/CPShiftReduceParser.m
@@ -125,7 +125,7 @@ - (id)parse:(CPTokenStream *)tokenStream
usingBlock:^(CPShiftReduceState *state, NSUInteger idx, BOOL *stop)
{
id o = [state object];
- if ([o isKindOfClass:[CPRHSItemResult class]])
+ if ([o isRHSItemResult])
{
CPRHSItemResult *r = o;
@@ -187,7 +187,7 @@ - (id)parse:(CPTokenStream *)tokenStream
CPRecoveryAction *recoveryAction = [self error:tokenStream expecting:[self acceptableTokenNamesForState:[(CPShiftReduceState *)[stateStack lastObject] state]]];
if (nil == recoveryAction)
{
- if ([nextToken isKindOfClass:[CPErrorToken class]] && [stateStack count] > 0)
+ if ([nextToken isErrorToken] && [stateStack count] > 0)
{
[stateStack removeLastObject];
}
View
8 CoreParse/Parsers/CPShiftReduceParsers/CPItem.h
@@ -25,4 +25,12 @@
- (id)itemByMovingDotRight;
+- (BOOL)isEqualToItem:(CPItem *)item;
+
+@end
+
+@interface NSObject (CPIsItem)
+
+- (BOOL)isItem;
+
@end
View
20 CoreParse/Parsers/CPShiftReduceParsers/CPItem.m
@@ -8,8 +8,6 @@
#import "CPItem.h"
-#import "NSObject+IsCoreParseObject.h"
-
@interface CPItem ()
@property (readwrite,retain) CPRule *rule;
@@ -78,14 +76,19 @@ - (id)itemByMovingDotRight
return [c autorelease];
}
-- (BOOL)isCPItem
+- (BOOL)isItem
{
return YES;
}
- (BOOL)isEqual:(id)object
{
- return [object isCPItem] && ((CPItem *)object)->position == position && ((CPItem *)object)->rule == rule;
+ return [object isItem] && ((CPItem *)object)->position == position && ((CPItem *)object)->rule == rule;
+}
+
+- (BOOL)isEqualToItem:(CPItem *)item
+{
+ return item->position == position && item->rule == rule;
}
- (NSUInteger)hash
@@ -115,3 +118,12 @@ - (NSString *)description
}
@end
+
+@implementation NSObject (CPIsItem)
+
+- (BOOL)isItem
+{
+ return NO;
+}
+
+@end
View
6 CoreParse/Parsers/CPShiftReduceParsers/CPLR1Item.h
@@ -20,3 +20,9 @@
- (id)initWithRule:(CPRule *)rule position:(NSUInteger)position terminal:(CPGrammarSymbol *)terminal;
@end
+
+@interface NSObject (CPIsLR1Item)
+
+- (BOOL)isLR1Item;
+
+@end
View
25 CoreParse/Parsers/CPShiftReduceParsers/CPLR1Item.m
@@ -52,19 +52,21 @@ - (void)dealloc
[super dealloc];
}
+- (BOOL)isLR1Item
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPLR1Item class]])
- {
- CPLR1Item *other = (CPLR1Item *)object;
- return [super isEqual:object] && [[other terminal] isEqual:[self terminal]];
- }
- return NO;
+ return ([object isLR1Item] &&
+ [super isEqualToItem:(CPLR1Item *)object] &&
+ [((CPLR1Item *)object)->terminal isEqual:terminal]);
}
- (NSUInteger)hash
{
- return [[self rule] hash] << 16 + [[self terminal] hash] + [self position];
+ return [[self rule] hash] << 16 + [terminal hash] + [self position];
}
- (NSString *)description
@@ -73,3 +75,12 @@ - (NSString *)description
}
@end
+
+@implementation NSObject(CPIsLR1Item)
+
+- (BOOL)isLR1Item
+{
+ return NO;
+}
+
+@end
View
6 CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceAction.h
@@ -31,3 +31,9 @@
- (NSString *)descriptionWithGrammar:(CPGrammar *)g;
@end
+
+@interface NSObject (CPIsShiftReduceAction)
+
+- (BOOL)isShiftReduceAction;
+
+@end
View
15 CoreParse/Parsers/CPShiftReduceParsers/CPShiftReduceAction.m
@@ -166,9 +166,14 @@ - (NSUInteger)hash
return type;
}
+- (BOOL)isShiftReduceAction
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPShiftReduceAction class]] && ((CPShiftReduceAction *)object)->type == type)
+ if ([object isShiftReduceAction] && ((CPShiftReduceAction *)object)->type == type)
{
CPShiftReduceAction *other = (CPShiftReduceAction *)object;
switch (type)
@@ -211,5 +216,13 @@ - (NSString *)descriptionWithGrammar:(CPGrammar *)g
}
}
+@end
+
+@implementation NSObject(CPIsShiftReduceAction)
+
+- (BOOL)isShiftReduceAction
+{
+ return NO;
+}
@end
View
6 CoreParse/Syntax Tree/CPSyntaxTree.h
@@ -105,3 +105,9 @@
- (id)childAtIndex:(NSUInteger)idx;
@end
+
+@interface NSObject (CPIsSyntaxTree)
+
+- (BOOL)isSyntaxTree;
+
+@end
View
23 CoreParse/Syntax Tree/CPSyntaxTree.m
@@ -79,14 +79,16 @@ - (NSUInteger)hash
return [[self rule] hash];
}
+- (BOOL)isSyntaxTree
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPSyntaxTree class]])
- {
- CPSyntaxTree *other = (CPSyntaxTree *)object;
- return [other rule] == [self rule] && [[other children] isEqualToArray:[self children]];
- }
- return NO;
+ return ([object isSyntaxTree] &&
+ ((CPSyntaxTree *)object)->rule == rule &&
+ [((CPSyntaxTree *)object)->children isEqualToArray:children]);
}
- (NSString *)description
@@ -101,3 +103,12 @@ - (NSString *)description
}
@end
+
+@implementation NSObject(CPIsSyntaxTree)
+
+- (BOOL)isSyntaxTree
+{
+ return NO;
+}
+
+@end
View
6 CoreParse/Tokenisation/CPTokenStream.h
@@ -93,3 +93,9 @@
- (void)closeTokenStream;
@end
+
+@interface NSObject (CPIsTokenStream)
+
+- (BOOL)isTokenStream;
+
+@end
View
20 CoreParse/Tokenisation/CPTokenStream.m
@@ -155,13 +155,23 @@ - (NSUInteger)hash
return [[self tokens] hash];
}
+- (BOOL)isTokenStream
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPTokenStream class]])
- {
- CPTokenStream *other = (CPTokenStream *)object;
- return [[other tokens] isEqualToArray:[self tokens]];
- }
+ return ([object isTokenStream] &&
+ [((CPTokenStream *)object)->tokens isEqualToArray:tokens]);
+}
+
+@end
+
+@implementation NSObject (CPIsTokenStream)
+
+- (BOOL)isTokenStream
+{
return NO;
}
View
6 CoreParse/Tokenisation/Token Types/CPEOFToken.h
@@ -25,3 +25,9 @@
+ (id)eof;
@end
+
+@interface NSObject (CPIsEOFToken)
+
+- (BOOL)isEOFToken;
+
+@end
View
17 CoreParse/Tokenisation/Token Types/CPEOFToken.m
@@ -8,7 +8,6 @@
#import "CPEOFToken.h"
-
@implementation CPEOFToken
+ (id)eof
@@ -26,9 +25,23 @@ - (NSUInteger)hash
return 0;
}
+- (BOOL)isEOFToken
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- return [object isKindOfClass:[CPEOFToken class]];
+ return [object isEOFToken];
+}
+
+@end
+
+@implementation NSObject (CPIsEOFToken)
+
+- (BOOL)isEOFToken
+{
+ return NO;
}
@end
View
6 CoreParse/Tokenisation/Token Types/CPErrorToken.h
@@ -37,3 +37,9 @@
- (id)initWithMesage:(NSString *)errorMessage;
@end
+
+@interface NSObject (CPErrorToken)
+
+- (BOOL)isErrorToken;
+
+@end
View
16 CoreParse/Tokenisation/Token Types/CPErrorToken.m
@@ -46,9 +46,23 @@ - (NSUInteger)hash
return 0;
}
+- (BOOL)isErrorToken
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- return [object isKindOfClass:[CPErrorToken class]];
+ return [object isErrorToken];
+}
+
+@end
+
+@implementation NSObject (CPIsErrorToken)
+
+- (BOOL)isErrorToken
+{
+ return NO;
}
@end
View
7 CoreParse/Tokenisation/Token Types/CPIdentifierToken.h
@@ -51,3 +51,10 @@
@property (readwrite,copy) NSString *identifier;
@end
+
+@interface NSObject (CPIsIdentifierToken)
+
+- (BOOL)isIdentifierToken;
+
+@end
+
View
22 CoreParse/Tokenisation/Token Types/CPIdentifierToken.m
@@ -8,7 +8,6 @@
#import "CPIdentifierToken.h"
-
@implementation CPIdentifierToken
{
NSString *identifier;
@@ -41,6 +40,7 @@ - (id)init
- (void)dealloc
{
[identifier release];
+
[super dealloc];
}
@@ -59,13 +59,23 @@ - (NSUInteger)hash
return [[self identifier] hash];
}
+- (BOOL)isIdentifierToken
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPIdentifierToken class]])
- {
- CPIdentifierToken *other = (CPIdentifierToken *)object;
- return [[other identifier] isEqualToString:[self identifier]];
- }
+ return ([object isIdentifierToken] &&
+ [((CPIdentifierToken *)object)->identifier isEqualToString:identifier]);
+}
+
+@end
+
+@implementation NSObject(CPIsIdentifierToken)
+
+- (BOOL)isIdentifierToken
+{
return NO;
}
View
6 CoreParse/Tokenisation/Token Types/CPKeywordToken.h
@@ -53,3 +53,9 @@
@property (readwrite,copy) NSString *keyword;
@end
+
+@interface NSObject (CPIsKeywordToken)
+
+- (BOOL)isKeywordToken;
+
+@end
View
21 CoreParse/Tokenisation/Token Types/CPKeywordToken.m
@@ -55,14 +55,23 @@ - (NSUInteger)hash
return [[self keyword] hash];
}
+- (BOOL)isKeywordToken
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPKeywordToken class]])
- {
- CPKeywordToken *other = (CPKeywordToken *)object;
- return [[other keyword] isEqualToString:[self keyword]];
- }
-
+ return ([object isKeywordToken] &&
+ [((CPKeywordToken *)object)->keyword isEqualToString:keyword]);
+}
+
+@end
+
+@implementation NSObject (CPIsKeywordToken)
+
+- (BOOL)isKeywordToken
+{
return NO;
}
View
6 CoreParse/Tokenisation/Token Types/CPNumberToken.h
@@ -51,3 +51,9 @@
@property (readwrite,copy) NSNumber *number;
@end
+
+@interface NSObject (CPIsNumberToken)
+
+- (BOOL)isNumberToken;
+
+@end
View
25 CoreParse/Tokenisation/Token Types/CPNumberToken.m
@@ -9,10 +9,6 @@
#import "CPNumberToken.h"
@implementation CPNumberToken
-{
-@private
- NSNumber *number;
-}
@synthesize number;
@@ -59,14 +55,23 @@ - (NSUInteger)hash
return [[self number] hash];
}
+- (BOOL)isNumberToken
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPNumberToken class]])
- {
- CPNumberToken *other = (CPNumberToken *)object;
- return [[other number] isEqualToNumber:[self number]];
- }
-
+ return ([object isNumberToken] &&
+ [((CPNumberToken *)object)->number isEqualToNumber:number]);
+}
+
+@end
+
+@implementation NSObject (CPIsNumberToken)
+
+- (BOOL)isNumberToken
+{
return NO;
}
View
6 CoreParse/Tokenisation/Token Types/CPQuotedToken.h
@@ -60,3 +60,9 @@
@property (readwrite,copy) NSString *quoteType;
@end
+
+@interface NSObject (CPIsQuotedToken)
+
+- (BOOL)isQuotedToken;
+
+@end
View
22 CoreParse/Tokenisation/Token Types/CPQuotedToken.m
@@ -68,13 +68,25 @@ - (NSUInteger)hash
return [[self content] hash];
}
+- (BOOL)isQuotedToken
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPQuotedToken class]])
- {
- CPQuotedToken *other = (CPQuotedToken *)object;
- return [[other content] isEqualToString:[self content]] && [[other name] isEqualToString:[self name]] && [[other quoteType] isEqualToString:[self quoteType]];
- }
+ return ([object isQuotedToken] &&
+ [((CPQuotedToken *)object)->content isEqualToString:content] &&
+ [((CPQuotedToken *)object)->name isEqualToString:name] &&
+ [((CPQuotedToken *)object)->quoteType isEqualToString:quoteType]);
+}
+
+@end
+
+@implementation NSObject (CPIsQuotedToken)
+
+- (BOOL)isQuotedToken
+{
return NO;
}
View
6 CoreParse/Tokenisation/Token Types/CPToken.h
@@ -38,3 +38,9 @@
@property (readwrite, assign) NSUInteger characterNumber;
@end
+
+@interface NSObject (CPIsToken)
+
+- (BOOL)isToken;
+
+@end
View
17 CoreParse/Tokenisation/Token Types/CPToken.m
@@ -27,12 +27,8 @@ - (NSUInteger)hash
- (BOOL)isEqual:(id)object
{
- if ([object isKindOfClass:[CPToken class]])
- {
- CPToken *other = (CPToken *)object;
- return [[self name] isEqualToString:[other name]];
- }
- return NO;
+ return ([object isToken] &&
+ [[self name] isEqualToString:[(CPToken *)object name]]);
}
- (NSString *)description
@@ -41,3 +37,12 @@ - (NSString *)description
}
@end
+
+@implementation NSObject (CPIsToken)
+
+- (BOOL)isToken
+{
+ return NO;
+}
+
+@end
View
6 CoreParse/Tokenisation/Token Types/CPWhiteSpaceToken.h
@@ -51,3 +51,9 @@
@property (readwrite,copy) NSString *whiteSpace;
@end
+
+@interface NSObject (CPIsWhiteSpaceToken)
+
+- (BOOL)isWhiteSpaceToken;
+
+@end
View
22 CoreParse/Tokenisation/Token Types/CPWhiteSpaceToken.m
@@ -9,10 +9,6 @@
#import "CPWhiteSpaceToken.h"
@implementation CPWhiteSpaceToken
-{
-@private
- NSString *whiteSpace;
-}
@synthesize whiteSpace;
@@ -40,6 +36,8 @@ - (id)init
- (void)dealloc
{
+ [whiteSpace release];
+
[super dealloc];
}
@@ -53,9 +51,23 @@ - (NSUInteger)hash
return 1;
}
+- (BOOL)isWhiteSpaceToken
+{
+ return YES;
+}
+
- (BOOL)isEqual:(id)object
{
- return [object isKindOfClass:[CPWhiteSpaceToken class]];
+ return [object isWhiteSpaceToken];
+}
+
+@end
+
+@implementation NSObject (CPIsWhiteSpaceToken)
+
+- (BOOL)isWhiteSpaceToken
+{
+ return NO;
}
@end
View
8 CoreParseTests/CPTestErrorEvaluatorDelegate.m
@@ -22,14 +22,14 @@ - (id)parser:(CPParser *)parser didProduceSyntaxTree:(CPSyntaxTree *)syntaxTree
return [c objectAtIndex:0];
case 1:
{
- int v1 = [[c objectAtIndex:0] isKindOfClass:[CPErrorToken class]] ? 0.0 : [[c objectAtIndex:0] intValue];
- int v2 = [[c objectAtIndex:2] isKindOfClass:[CPErrorToken class]] ? 0.0 : [[c objectAtIndex:2] intValue];
+ int v1 = [[c objectAtIndex:0] isErrorToken] ? 0.0 : [[c objectAtIndex:0] intValue];
+ int v2 = [[c objectAtIndex:2] isErrorToken] ? 0.0 : [[c objectAtIndex:2] intValue];
return [NSNumber numberWithInt:v1 + v2];
}
case 3:
{
- int v1 = [[c objectAtIndex:0] isKindOfClass:[CPErrorToken class]] ? 1.0 : [[c objectAtIndex:0] intValue];
- int v2 = [[c objectAtIndex:2] isKindOfClass:[CPErrorToken class]] ? 1.0 : [[c objectAtIndex:2] intValue];
+ int v1 = [[c objectAtIndex:0] isErrorToken] ? 1.0 : [[c objectAtIndex:0] intValue];
+ int v2 = [[c objectAtIndex:2] isErrorToken] ? 1.0 : [[c objectAtIndex:2] intValue];
return [NSNumber numberWithInt:v1 * v2];
}
case 4:
View
8 CoreParseTests/CPTestMapCSSTokenisingDelegate.m
@@ -50,15 +50,15 @@ - (BOOL)tokeniser:(CPTokeniser *)tokeniser shouldConsumeToken:(CPToken *)token
{
inRange = YES;
}
- else if (inRange && ![token isKindOfClass:[CPNumberToken class]] && ![name isEqualToString:@"-"])
+ else if (inRange && ![token isNumberToken] && ![name isEqualToString:@"-"])
{
inRange = NO;
}
- else if (inRange && [token isKindOfClass:[CPNumberToken class]])
+ else if (inRange && [token isNumberToken])
{
return [[(CPNumberToken *)token number] floatValue] >= 0;
}
- else if ([token isKindOfClass:[CPKeywordToken class]])
+ else if ([token isKeywordToken])
{
return 0 == nestingDepth || [symbolsSet characterIsMember:[name characterAtIndex:0]] || [name isEqualToString:@"eval"] || [name isEqualToString:@"url"] || [name isEqualToString:@"set"] || [name isEqualToString:@"pt"] || [name isEqualToString:@"px"];
}
@@ -69,7 +69,7 @@ - (BOOL)tokeniser:(CPTokeniser *)tokeniser shouldConsumeToken:(CPToken *)token
- (NSArray *)tokeniser:(CPTokeniser *)tokeniser willProduceToken:(CPToken *)token
{
NSString *name = [token name];
- if ([token isKindOfClass:[CPWhiteSpaceToken class]])
+ if ([token isWhiteSpaceToken])
{
if (justTokenisedObject)
{
View
3 CoreParseTests/CPTestWhiteSpaceIgnoringDelegate.m
@@ -8,7 +8,6 @@
#import "CPTestWhiteSpaceIgnoringDelegate.h"
-
@implementation CPTestWhiteSpaceIgnoringDelegate
- (BOOL)tokeniser:(CPTokeniser *)tokeniser shouldConsumeToken:(CPToken *)token
@@ -18,7 +17,7 @@ - (BOOL)tokeniser:(CPTokeniser *)tokeniser shouldConsumeToken:(CPToken *)token
- (NSArray *)tokeniser:(CPTokeniser *)tokeniser willProduceToken:(CPToken *)token
{
- if ([token isKindOfClass:[CPWhiteSpaceToken class]] || [[token name] isEqualToString:@"Comment"])
+ if ([token isWhiteSpaceToken] || [[token name] isEqualToString:@"Comment"])
{
return [NSArray array];
}

0 comments on commit ae77624

Please sign in to comment.
Something went wrong with that request. Please try again.