ANTLRIntStream.h revision 324c4644fee44b9898524c09511bd33c3f12e2df
158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// [The "BSD licence"] 258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Copyright (c) 2006-2007 Kay Roepke 2010 Alan Condit 358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// All rights reserved. 458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// 558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Redistribution and use in source and binary forms, with or without 658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// modification, are permitted provided that the following conditions 758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// are met: 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// 1. Redistributions of source code must retain the above copyright 923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)// notice, this list of conditions and the following disclaimer. 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 2. Redistributions in binary form must reproduce the above copyright 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// notice, this list of conditions and the following disclaimer in the 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// documentation and/or other materials provided with the distribution. 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 3. The name of the author may not be used to endorse or promote products 1458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// derived from this software without specific prior written permission. 1558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// 1658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 2758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#ifndef DEBUG_DEALLOC 2858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#define DEBUG_DEALLOC 2958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#endif 3058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)@protocol ANTLRIntStream < NSObject, NSCopying > 3258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)- (void) consume; 3458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Get unichar at current input pointer + i ahead where i=1 is next character as int for including ANTLRCharStreamEOF (-1) in the data range 3658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)- (NSInteger) LA:(NSInteger) i; 3758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 3858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Tell the stream to start buffering if it hasn't already. Return 3958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// current input position, index(), or some other marker so that 4058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// when passed to rewind() you get back to the same spot. 4158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// rewind(mark()) should not affect the input cursor. 4258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// TODO: problem in that lexer stream returns not index but some marker 4358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 4458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)- (NSInteger) mark; 45 46// Return the current input symbol index 0..n where n indicates the 47// last symbol has been read. 48 49- (NSInteger) index; 50 51- (NSUInteger) line; 52 53- (NSUInteger) charPositionInLine; 54 55// Reset the stream so that next call to index would return marker. 56// The marker will usually be -index but it doesn't have to be. It's 57// just a marker to indicate what state the stream was in. This is 58// essentially calling -release: and -seek:. If there are markers 59// created after this marker argument, this routine must unroll them 60// like a stack. Assume the state the stream was in when this marker 61// was created. 62 63- (void) rewind; 64- (void) rewind:(NSInteger) marker; 65 66// You may want to commit to a backtrack but don't want to force the 67// stream to keep bookkeeping objects around for a marker that is 68// no longer necessary. This will have the same behavior as 69// rewind() except it releases resources without the backward seek. 70 71- (void) release:(NSInteger) marker; 72 73// Set the input cursor to the position indicated by index. This is 74// normally used to seek ahead in the input stream. No buffering is 75// required to do this unless you know your stream will use seek to 76// move backwards such as when backtracking. 77// This is different from rewind in its multi-directional 78// requirement and in that its argument is strictly an input cursor (index). 79// 80// For char streams, seeking forward must update the stream state such 81// as line number. For seeking backwards, you will be presumably 82// backtracking using the mark/rewind mechanism that restores state and 83// so this method does not need to update state when seeking backwards. 84// 85// Currently, this method is only used for efficient backtracking, but 86// in the future it may be used for incremental parsing. 87 88- (void) seek:(NSInteger) anIndex; 89 90/** Only makes sense for streams that buffer everything up probably, but 91 * might be useful to display the entire stream or for testing. This 92 * value includes a single EOF. 93 */ 94- (NSUInteger) size; 95/** Where are you getting symbols from? Normally, implementations will 96 * pass the buck all the way to the lexer who can ask its input stream 97 * for the file name or whatever. 98 */ 99- (NSString *)getSourceName; 100 101//@property (assign) NSInteger index; 102//@property (assign) NSUInteger line; 103//@property (assign) NSUInteger charPositionInLine; 104 105 106@end 107