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 #ifndef DEBUG_DEALLOC 28 #define DEBUG_DEALLOC 29 #endif 30 31 @protocol IntStream < NSObject, NSCopying > 32 33 - (void) consume; 34 35 // 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 - (NSInteger) LA:(NSInteger) i; 37 38 // Tell the stream to start buffering if it hasn't already. Return 39 // current input position, index(), or some other marker so that 40 // when passed to rewind() you get back to the same spot. 41 // rewind(mark()) should not affect the input cursor. 42 // TODO: problem in that lexer stream returns not index but some marker 43 44 - (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 // Reset the stream so that next call to index would return marker. 52 // The marker will usually be -index but it doesn't have to be. It's 53 // just a marker to indicate what state the stream was in. This is 54 // essentially calling -release: and -seek:. If there are markers 55 // created after this marker argument, this routine must unroll them 56 // like a stack. Assume the state the stream was in when this marker 57 // was created. 58 59 - (void) rewind; 60 - (void) rewind:(NSInteger) marker; 61 62 // You may want to commit to a backtrack but don't want to force the 63 // stream to keep bookkeeping objects around for a marker that is 64 // no longer necessary. This will have the same behavior as 65 // rewind() except it releases resources without the backward seek. 66 67 - (void) release:(NSInteger) marker; 68 69 // Set the input cursor to the position indicated by index. This is 70 // normally used to seek ahead in the input stream. No buffering is 71 // required to do this unless you know your stream will use seek to 72 // move backwards such as when backtracking. 73 // This is different from rewind in its multi-directional 74 // requirement and in that its argument is strictly an input cursor (index). 75 // 76 // For char streams, seeking forward must update the stream state such 77 // as line number. For seeking backwards, you will be presumably 78 // backtracking using the mark/rewind mechanism that restores state and 79 // so this method does not need to update state when seeking backwards. 80 // 81 // Currently, this method is only used for efficient backtracking, but 82 // in the future it may be used for incremental parsing. 83 84 - (void) seek:(NSInteger) anIndex; 85 86 /** Only makes sense for streams that buffer everything up probably, but 87 * might be useful to display the entire stream or for testing. This 88 * value includes a single EOF. 89 */ 90 - (NSUInteger) size; 91 /** Where are you getting symbols from? Normally, implementations will 92 * pass the buck all the way to the lexer who can ask its input stream 93 * for the file name or whatever. 94 */ 95 - (NSString *)getSourceName; 96 97 //@property (assign) NSInteger index; 98 //@property (assign) NSUInteger line; 99 //@property (assign) NSUInteger charPositionInLine; 100 101 102 @end 103