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 28#import <Cocoa/Cocoa.h> 29#import "ANTLRCharStream.h" 30#import "ANTLRCharStreamState.h" 31#import "ANTLRPtrBuffer.h" 32 33@interface ANTLRStringStream : NSObject < ANTLRCharStream > { 34 NSString *data; 35 NSInteger n; 36 NSInteger p; 37 NSInteger line; 38 NSInteger charPositionInLine; 39 NSInteger markDepth; 40 ANTLRPtrBuffer *markers; 41 NSInteger lastMarker; 42 NSString *name; 43 ANTLRCharStreamState *charState; 44} 45 46@property (retain, getter=getData,setter=setData:) NSString *data; 47@property (getter=getP,setter=setP:) NSInteger p; 48@property (getter=getN,setter=setN:) NSInteger n; 49@property (getter=getLine,setter=setLine:) NSInteger line; 50@property (getter=getCharPositionInLine,setter=setCharPositionInLine:) NSInteger charPositionInLine; 51@property (getter=getMarkDepth,setter=setMarkDepth:) NSInteger markDepth; 52@property (retain, getter=getMarkers, setter=setMarkers:) ANTLRPtrBuffer *markers; 53@property (getter=getLastMarker,setter=setLastMarker:) NSInteger lastMarker; 54@property (retain, getter=getSourceName, setter=setSourceName:) NSString *name; 55@property (retain, getter=getCharState, setter=setCharState:) ANTLRCharStreamState *charState; 56 57+ newANTLRStringStream; 58 59+ newANTLRStringStream:(NSString *)aString; 60 61+ newANTLRStringStream:(char *)myData Count:(NSInteger)numBytes; 62 63- (id) init; 64 65// this initializer copies the string 66- (id) initWithString:(NSString *) theString; 67 68// This is the preferred constructor as no data is copied 69- (id) initWithStringNoCopy:(NSString *) theString; 70 71- (id) initWithData:(char *)myData Count:(NSInteger)numBytes; 72 73- (void) dealloc; 74 75- (id) copyWithZone:(NSZone *)aZone; 76 77// reset the stream's state, but keep the data to feed off 78- (void) reset; 79// consume one character from the stream 80- (void) consume; 81 82// look ahead i characters 83- (NSInteger) LA:(NSInteger) i; 84- (NSInteger) LT:(NSInteger) i; 85 86// returns the position of the current input symbol 87- (NSInteger) getIndex; 88// total length of the input data 89- (NSInteger) size; 90 91// seek and rewind in the stream 92- (NSInteger) mark; 93- (void) rewind:(NSInteger) marker; 94- (void) rewind; 95- (void) release:(NSInteger) marker; 96- (void) seek:(NSInteger) index; 97 98// provide the streams data (e.g. for tokens using indices) 99- (NSString *) substring:(NSInteger)startIndex To:(NSInteger)stopIndex; 100- (NSString *) substringWithRange:(NSRange) theRange; 101 102// used for tracking the current position in the input stream 103- (NSInteger) getLine; 104- (void) setLine:(NSInteger) theLine; 105- (NSInteger) getCharPositionInLine; 106- (void) setCharPositionInLine:(NSInteger) thePos; 107 108- (NSInteger) getN; 109- (void) setN:(NSInteger)num; 110 111- (NSInteger) getP; 112- (void) setP:(NSInteger)num; 113 114- (ANTLRPtrBuffer *)getMarkers; 115- (void) setMarkers:(ANTLRPtrBuffer *)aMarkerList; 116 117- (NSString *)getSourceName; 118 119- (NSString *)toString; 120 121// accessors to the raw data of this stream 122- (NSString *) getData; 123- (void) setData: (NSString *) aData; 124 125 126@end 127