• 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 #import <Foundation/Foundation.h>
28 #import "TokenStream.h"
29 #import "TokenSource.h"
30 #import "ANTLRBitSet.h"
31 #import "CommonToken.h"
32 #import "AMutableArray.h"
33 
34 @interface BufferedTokenStream : NSObject <TokenStream>
35 {
36 __strong id<TokenSource> tokenSource;
37 
38     /** Record every single token pulled from the source so we can reproduce
39      *  chunks of it later.  The buffer in LookaheadStream overlaps sometimes
40      *  as its moving window moves through the input.  This list captures
41      *  everything so we can access complete input text.
42      */
43 __strong AMutableArray *tokens;
44 
45     /** Track the last mark() call result value for use in rewind(). */
46 NSInteger lastMarker;
47 
48     /** The index into the tokens list of the current token (next token
49      *  to consume).  tokens[index] should be LT(1).  index=-1 indicates need
50      *  to initialize with first token.  The ctor doesn't get a token.
51      *  First call to LT(1) or whatever gets the first token and sets index=0;
52      */
53 NSInteger index;
54 
55 NSInteger range; // how deep have we gone?
56 
57 }
58 @property (retain, getter=getTokenSource,setter=setTokenSource:) id<TokenSource> tokenSource;
59 @property (retain, getter=getTokens,setter=setTokens:) AMutableArray *tokens;
60 @property (assign, getter=getLastMarker,setter=setLastMarker:) NSInteger lastMarker;
61 @property (assign) NSInteger index;
62 @property (assign, getter=getRange,setter=setRange:) NSInteger range;
63 
64 + (BufferedTokenStream *) newBufferedTokenStream;
65 + (BufferedTokenStream *) newBufferedTokenStreamWith:(id<TokenSource>)aSource;
66 - (id) initWithTokenSource:(id<TokenSource>)aSource;
67 - (void)dealloc;
68 - (id) copyWithZone:(NSZone *)aZone;
69 - (NSUInteger)charPositionInLine;
70 - (NSUInteger)line;
71 - (NSInteger) getRange;
72 - (void) setRange:(NSInteger)anInt;
73 - (NSInteger) mark;
74 - (void) release:(NSInteger) marker;
75 - (void) rewind:(NSInteger) marker;
76 - (void) rewind;
77 - (void) reset;
78 - (void) seek:(NSInteger) anIndex;
79 - (NSInteger) size;
80 - (void) consume;
81 - (void) sync:(NSInteger) i;
82 - (void) fetch:(NSInteger) n;
83 - (id<Token>) getToken:(NSInteger) i;
84 - (AMutableArray *)getFrom:(NSInteger)startIndex To:(NSInteger) stopIndex;
85 - (NSInteger) LA:(NSInteger)i;
86 - (id<Token>) LB:(NSInteger) k;
87 - (id<Token>) LT:(NSInteger) k;
88 - (void) setup;
89 - (id<TokenSource>) getTokenSource;
90 - (void) setTokenSource:(id<TokenSource>) aTokenSource;
91 - (AMutableArray *)getTokens;
92 - (NSString *) getSourceName;
93 - (AMutableArray *)getTokensFrom:(NSInteger)startIndex To:(NSInteger)stopIndex;
94 - (AMutableArray *)getTokensFrom:(NSInteger)startIndex To:(NSInteger)stopIndex With:(ANTLRBitSet *)types;
95 - (AMutableArray *)getTokensFrom:(NSInteger)startIndex To:(NSInteger)stopIndex WithList:(AMutableArray *)types;
96 - (AMutableArray *)getTokensFrom:(NSInteger)startIndex To:(NSInteger)stopIndex WithType:(NSInteger)ttype;
97 - (NSString *) toString;
98 - (NSString *) toStringFromStart:(NSInteger)startIndex ToEnd:(NSInteger)stopIndex;
99 - (NSString *) toStringFromToken:(id<Token>)startIndex ToToken:(id<Token>)stopIndex;
100 - (void) fill;
101 
102 @end
103