Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (65 sloc) 2.03 KB
// Copyright 2010 Todd Ditchendorf
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <ParseKit/PKRepetition.h>
#import <ParseKit/PKAssembly.h>
@interface PKParser ()
- (NSSet *)matchAndAssemble:(NSSet *)inAssemblies;
@end
@interface PKRepetition ()
@property (nonatomic, readwrite, retain) PKParser *subparser;
@end
@implementation PKRepetition
+ (PKRepetition *)repetitionWithSubparser:(PKParser *)p {
return [[[self alloc] initWithSubparser:p] autorelease];
}
- (id)init {
return [self initWithSubparser:nil];
}
- (id)initWithSubparser:(PKParser *)p {
//NSParameterAssert(p);
self = [super init];
if (self) {
self.subparser = p;
}
return self;
}
- (void)dealloc {
self.subparser = nil;
[super dealloc];
}
- (PKParser *)parserNamed:(NSString *)s {
if ([name isEqualToString:s]) {
return self;
} else {
return [subparser parserNamed:s];
}
}
- (NSSet *)allMatchesFor:(NSSet *)inAssemblies {
NSParameterAssert(inAssemblies);
//NSMutableSet *outAssemblies = [[[NSMutableSet alloc] initWithSet:inAssemblies copyItems:YES] autorelease];
NSMutableSet *outAssemblies = [[inAssemblies mutableCopy] autorelease];
NSSet *s = inAssemblies;
while ([s count]) {
s = [subparser matchAndAssemble:s];
[outAssemblies unionSet:s];
}
return outAssemblies;
}
- (void)add:(PKParser *)p {
NSParameterAssert([p isKindOfClass:[PKParser class]]);
NSAssert(!subparser, @"");
self.subparser = p;
}
@synthesize subparser;
@end