• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ANTLRIntStream < 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 ANTLRCharStreamEOF (-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 - (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