• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //  ANTLRBufferedTreeNodeStream.h
3 //  ANTLR
4 //
5 // [The "BSD licence"]
6 // Copyright (c) 2010 Ian Michell 2010 Alan Condit
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions
11 // are met:
12 // 1. Redistributions of source code must retain the above copyright
13 //    notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 //    notice, this list of conditions and the following disclaimer in the
16 //    documentation and/or other materials provided with the distribution.
17 // 3. The name of the author may not be used to endorse or promote products
18 //    derived from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #import <Cocoa/Cocoa.h>
32 #import "ANTLRTree.h"
33 #import "ANTLRCommonTreeAdaptor.h"
34 #import "ANTLRTokenStream.h"
35 #import "ANTLRCommonTreeNodeStream.h"
36 #import "ANTLRLookaheadStream.h"
37 #import "ANTLRTreeIterator.h"
38 #import "ANTLRIntArray.h"
39 
40 #define DEFAULT_INITIAL_BUFFER_SIZE 100
41 #define INITIAL_CALL_STACK_SIZE 10
42 
43 #ifdef DONTUSENOMO
44 @interface ANTLRStreamIterator : ANTLRTreeIterator
45 {
46     NSInteger idx;
47     ANTLRBufferedTreeNodeStream input;
48     NSMutableArray *nodes;
49 }
50 
51 + (id) newANTLRStreamIterator:(ANTLRBufferedTreeNodeStream *) theStream;
52 
53 - (id) initWithStream:(ANTLRBufferedTreeNodeStream *) theStream;
54 
55 - (BOOL) hasNext;
56 - (id) next;
57 - (void) remove;
58 @end
59 #endif
60 
61 @interface ANTLRBufferedTreeNodeStream : NSObject <ANTLRTreeNodeStream>
62 {
63 	id<ANTLRTree> up;
64 	id<ANTLRTree> down;
65 	id<ANTLRTree> eof;
66 
67 	NSMutableArray *nodes;
68 
69 	id<ANTLRTree> root; // root
70 
71 	id<ANTLRTokenStream> tokens;
72 	ANTLRCommonTreeAdaptor *adaptor;
73 
74 	BOOL uniqueNavigationNodes;
75 	NSInteger p;
76 	NSInteger lastMarker;
77 	ANTLRIntArray *calls;
78 
79 	NSEnumerator *e;
80     id currentSymbol;
81 
82 }
83 
84 @property (retain, getter=getUp, setter=setUp:) id<ANTLRTree> up;
85 @property (retain, getter=getDown, setter=setDown:) id<ANTLRTree> down;
86 @property (retain, getter=getEof, setter=setEof:) id<ANTLRTree> eof;
87 @property (retain, getter=getNodes, setter=setNodes:) NSMutableArray *nodes;
88 @property (retain, getter=getTreeSource, setter=setTreeSource:) id<ANTLRTree> root;
89 @property (retain, getter=getTokenStream, setter=setTokenStream:) id<ANTLRTokenStream> tokens;
90 @property (retain, getter=getAdaptor, setter=setAdaptor:) ANTLRCommonTreeAdaptor *adaptor;
91 @property (assign, getter=getUniqueNavigationNodes, setter=setUniqueNavigationNodes:) BOOL uniqueNavigationNodes;
92 @property (assign, getter=getIndex, setter=setIndex:) NSInteger p;
93 @property (assign, getter=getLastMarker, setter=setLastMarker:) NSInteger lastMarker;
94 @property (retain, getter=getCalls, setter=setCalls:) ANTLRIntArray *calls;
95 @property (retain, getter=getEnum, setter=setEnum:) NSEnumerator *e;
96 @property (retain, getter=getCurrentSymbol, setter=setCurrentSymbol:) id currentSymbol;
97 
98 + (ANTLRBufferedTreeNodeStream *) newANTLRBufferedTreeNodeStream:(id<ANTLRTree>)tree;
99 + (ANTLRBufferedTreeNodeStream *) newANTLRBufferedTreeNodeStream:(id<ANTLRTreeAdaptor>)adaptor Tree:(id<ANTLRTree>)tree;
100 + (ANTLRBufferedTreeNodeStream *) newANTLRBufferedTreeNodeStream:(id<ANTLRTreeAdaptor>)adaptor Tree:(id<ANTLRTree>)tree withBufferSize:(NSInteger)initialBufferSize;
101 
102 #pragma mark Constructor
103 - (id) initWithTree:(id<ANTLRTree>)tree;
104 - (id) initWithTreeAdaptor:(ANTLRCommonTreeAdaptor *)anAdaptor Tree:(id<ANTLRTree>)tree;
105 - (id) initWithTreeAdaptor:(ANTLRCommonTreeAdaptor *)anAdaptor Tree:(id<ANTLRTree>)tree WithBufferSize:(NSInteger)bufferSize;
106 
107 - (id) copyWithZone:(NSZone *)aZone;
108 
109 // protected methods. DO NOT USE
110 #pragma mark Protected Methods
111 - (void) fillBuffer;
112 - (void) fillBufferWithTree:(id<ANTLRTree>) tree;
113 - (NSInteger) getNodeIndex:(id<ANTLRTree>) node;
114 - (void) addNavigationNode:(NSInteger) type;
115 - (id) getNode:(NSInteger) i;
116 - (id) LT:(NSInteger) k;
117 - (id) getCurrentSymbol;
118 - (id) LB:(NSInteger) i;
119 #pragma mark General Methods
120 - (NSString *) getSourceName;
121 
122 - (id<ANTLRTokenStream>) getTokenStream;
123 - (void) setTokenStream:(id<ANTLRTokenStream>) tokens;
124 - (id<ANTLRTreeAdaptor>) getTreeAdaptor;
125 - (void) setTreeAdaptor:(id<ANTLRTreeAdaptor>) anAdaptor;
126 
127 - (BOOL)getUniqueNavigationNodes;
128 - (void) setUniqueNavigationNodes:(BOOL)aVal;
129 
130 - (void) consume;
131 - (NSInteger) LA:(NSInteger) i;
132 - (NSInteger) mark;
133 - (void) release:(NSInteger) marker;
134 - (NSInteger) getIndex;
135 - (void) setIndex:(NSInteger) idx;
136 - (void) rewind:(NSInteger) marker;
137 - (void) rewind;
138 - (void) seek:(NSInteger) idx;
139 
140 - (void) push:(NSInteger) i;
141 - (NSInteger) pop;
142 
143 - (void) reset;
144 - (NSUInteger) count;
145 - (NSEnumerator *) objectEnumerator;
146 - (void) replaceChildren:(id)parent From:(NSInteger)startChildIndex To:(NSInteger)stopChildIndex With:(id) t;
147 
148 - (NSString *) toTokenTypeString;
149 - (NSString *) toTokenString:(NSInteger)aStart ToEnd:(NSInteger)aStop;
150 - (NSString *) toStringFromNode:(id)aStart ToNode:(id)aStop;
151 
152 // getters and setters
153 - (NSMutableArray *) getNodes;
154 - (id<ANTLRTree>) getEof;
155 
156 @end
157