Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 68bb0b411c
Fetching contributors…

Cannot retrieve contributors at this time

108 lines (87 sloc) 2.784 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/PKSingleLineCommentState.h>
#import <ParseKit/PKCommentState.h>
#import <ParseKit/PKReader.h>
#import <ParseKit/PKTokenizer.h>
#import <ParseKit/PKToken.h>
#import <ParseKit/PKTypes.h>
@interface PKToken ()
@property (nonatomic, readwrite) NSUInteger offset;
@end
@interface PKTokenizerState ()
- (void)resetWithReader:(PKReader *)r;
- (void)append:(PKUniChar)c;
- (void)appendString:(NSString *)s;
- (NSString *)bufferedString;
@end
@interface PKSingleLineCommentState ()
- (void)addStartMarker:(NSString *)start;
- (void)removeStartMarker:(NSString *)start;
@property (nonatomic, retain) NSMutableArray *startMarkers;
@property (nonatomic, retain) NSString *currentStartMarker;
@end
@implementation PKSingleLineCommentState
- (id)init {
if (self = [super init]) {
self.startMarkers = [NSMutableArray array];
}
return self;
}
- (void)dealloc {
self.startMarkers = nil;
self.currentStartMarker = nil;
[super dealloc];
}
- (void)addStartMarker:(NSString *)start {
NSParameterAssert([start length]);
[startMarkers addObject:start];
}
- (void)removeStartMarker:(NSString *)start {
NSParameterAssert([start length]);
[startMarkers removeObject:start];
}
- (PKToken *)nextTokenFromReader:(PKReader *)r startingWith:(PKUniChar)cin tokenizer:(PKTokenizer *)t {
NSParameterAssert(r);
NSParameterAssert(t);
BOOL reportTokens = t.commentState.reportsCommentTokens;
if (reportTokens) {
[self resetWithReader:r];
[self appendString:currentStartMarker];
}
PKUniChar c;
while (1) {
c = [r read];
if ('\n' == c || '\r' == c || PKEOF == c) {
break;
}
if (reportTokens) {
[self append:c];
}
}
if (PKEOF != c) {
[r unread];
}
self.currentStartMarker = nil;
if (reportTokens) {
PKToken *tok = [PKToken tokenWithTokenType:PKTokenTypeComment stringValue:[self bufferedString] floatValue:0.0];
tok.offset = offset;
return tok;
} else {
return [t nextToken];
}
}
@synthesize startMarkers;
@synthesize currentStartMarker;
@end
Jump to Line
Something went wrong with that request. Please try again.