1// [The "BSD licence"] 2// Copyright (c) 2006-2007 Kay Roepke 2010 Alan Condit 3// All rights reserved. 4// 5// Redistribution and use in source and binary forms, with or without 6// modification, are permitted provided that the following conditions 7// are met: 8// 1. Redistributions of source code must retain the above copyright 9// notice, this list of conditions and the following disclaimer. 10// 2. Redistributions in binary form must reproduce the above copyright 11// notice, this list of conditions and the following disclaimer in the 12// documentation and/or other materials provided with the distribution. 13// 3. The name of the author may not be used to endorse or promote products 14// derived from this software without specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27#import <Cocoa/Cocoa.h> 28#import "ANTLRTokenStream.h" 29#import "ANTLRTokenSource.h" 30#import "ANTLRBitSet.h" 31#import "ANTLRCommonToken.h" 32#import "AMutableArray.h" 33 34@interface ANTLRBufferedTokenStream : NSObject <ANTLRTokenStream> 35{ 36__strong id<ANTLRTokenSource> tokenSource; 37 38 /** Record every single token pulled from the source so we can reproduce 39 * chunks of it later. The buffer in LookaheadStream overlaps sometimes 40 * as its moving window moves through the input. This list captures 41 * everything so we can access complete input text. 42 */ 43__strong AMutableArray *tokens; 44 45 /** Track the last mark() call result value for use in rewind(). */ 46NSInteger lastMarker; 47 48 /** The index into the tokens list of the current token (next token 49 * to consume). tokens[index] should be LT(1). index=-1 indicates need 50 * to initialize with first token. The ctor doesn't get a token. 51 * First call to LT(1) or whatever gets the first token and sets index=0; 52 */ 53NSInteger index; 54 55NSInteger range; // how deep have we gone? 56 57} 58@property (retain, getter=getTokenSource,setter=setTokenSource:) id<ANTLRTokenSource> tokenSource; 59@property (retain, getter=getTokens,setter=setTokens:) AMutableArray *tokens; 60@property (assign, getter=getLastMarker,setter=setLastMarker:) NSInteger lastMarker; 61@property (assign) NSInteger index; 62@property (assign, getter=getRange,setter=setRange:) NSInteger range; 63 64+ (ANTLRBufferedTokenStream *) newANTLRBufferedTokenStream; 65+ (ANTLRBufferedTokenStream *) newANTLRBufferedTokenStreamWith:(id<ANTLRTokenSource>)aSource; 66- (id) initWithTokenSource:(id<ANTLRTokenSource>)aSource; 67- (void)dealloc; 68- (id) copyWithZone:(NSZone *)aZone; 69- (NSUInteger)charPositionInLine; 70- (NSUInteger)line; 71- (NSInteger) getRange; 72- (void) setRange:(NSInteger)anInt; 73- (NSInteger) mark; 74- (void) release:(NSInteger) marker; 75- (void) rewind:(NSInteger) marker; 76- (void) rewind; 77- (void) reset; 78- (void) seek:(NSInteger) anIndex; 79- (NSInteger) size; 80- (void) consume; 81- (void) sync:(NSInteger) i; 82- (void) fetch:(NSInteger) n; 83- (id<ANTLRToken>) getToken:(NSInteger) i; 84- (AMutableArray *)getFrom:(NSInteger)startIndex To:(NSInteger) stopIndex; 85- (NSInteger) LA:(NSInteger)i; 86- (id<ANTLRToken>) LB:(NSInteger) k; 87- (id<ANTLRToken>) LT:(NSInteger) k; 88- (void) setup; 89- (id<ANTLRTokenSource>) getTokenSource; 90- (void) setTokenSource:(id<ANTLRTokenSource>) aTokenSource; 91- (AMutableArray *)getTokens; 92- (NSString *) getSourceName; 93- (AMutableArray *)getTokensFrom:(NSInteger)startIndex To:(NSInteger)stopIndex; 94- (AMutableArray *)getTokensFrom:(NSInteger)startIndex To:(NSInteger)stopIndex With:(ANTLRBitSet *)types; 95- (AMutableArray *)getTokensFrom:(NSInteger)startIndex To:(NSInteger)stopIndex WithList:(AMutableArray *)types; 96- (AMutableArray *)getTokensFrom:(NSInteger)startIndex To:(NSInteger)stopIndex WithType:(NSInteger)ttype; 97- (NSString *) toString; 98- (NSString *) toStringFromStart:(NSInteger)startIndex ToEnd:(NSInteger)stopIndex; 99- (NSString *) toStringFromToken:(id<ANTLRToken>)startIndex ToToken:(id<ANTLRToken>)stopIndex; 100- (void) fill; 101 102@end 103