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