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