• 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 
28 #import <Cocoa/Cocoa.h>
29 #import "ANTLRTreeNodeStream.h"
30 #import "ANTLRCommonTokenStream.h"
31 #import "ANTLRCommonTree.h"
32 #import "ANTLRCommonTreeAdaptor.h"
33 
34 @interface ANTLRUnbufferedCommonTreeNodeStream : NSObject < ANTLRTreeNodeStream > {
35 
36 	BOOL shouldUseUniqueNavigationNodes;
37 
38 	ANTLRCommonTree *root;
39 	ANTLRCommonTree *currentNode;
40 	ANTLRCommonTree *previousNode;
41 
42 	id<ANTLRTreeAdaptor> treeAdaptor;
43 
44 	id<ANTLRTokenStream> tokenStream;
45 
46 	NSMutableArray *nodeStack;
47 	NSMutableArray *indexStack;
48 	ANTLRPtrBuffer *markers;
49 	NSInteger lastMarker;
50 
51 	NSInteger currentChildIndex;
52 	NSInteger absoluteNodeIndex;
53 
54 	NSMutableArray *lookahead;
55 	NSUInteger head;
56 	NSUInteger tail;
57 }
58 
59 @property (retain, getter=getRoot, setter=setRoot:) ANTLRCommonTree *root;
60 @property (retain, getter=getCurrentNode, setter=setCurrentNode:) ANTLRCommonTree *currentNode;
61 @property (retain, getter=getPreviousNode, setter=setPreviousNode:) ANTLRCommonTree *previousNode;
62 @property (retain, getter=getTreeAdaptor, setter=setTreeAdaptor:) id<ANTLRTreeAdaptor> treeAdaptor;
63 @property (retain, getter=getTokenStream, setter=setTokenStream:) id<ANTLRTokenStream> tokenStream;
64 @property (retain, getter=getNodeStack, setter=setNodeStack:) NSMutableArray *nodeStack;
65 @property (retain, getter=getIndexStack, setter=setIndexStackStack:) NSMutableArray *indexStack;
66 @property (retain, getter=getMarkers, setter=setMarkers:) ANTLRPtrBuffer *markers;
67 @property (assign, getter=getLastMarker, setter=setLastMarker:) NSInteger lastMarker;
68 @property (assign, getter=getCurrentChildIndex, setter=setCurrentChildIndex:) NSInteger currentChildIndex;
69 @property (assign, getter=getAbsoluteNodeIndex, setter=setAbsoluteNodeIndex:) NSInteger absoluteNodeIndex;
70 @property (retain, getter=getLookahead, setter=setLookahead:) NSMutableArray *lookahead;
71 @property (assign, getter=getHead, setter=setHead:) NSUInteger head;
72 @property (assign, getter=getTail, setter=setTail:) NSUInteger tail;
73 
74 - (id) initWithTree:(ANTLRCommonTree *)theTree;
75 - (id) initWithTree:(ANTLRCommonTree *)theTree treeAdaptor:(ANTLRCommonTreeAdaptor *)theAdaptor;
76 
77 - (void) reset;
78 
79 #pragma mark ANTLRTreeNodeStream conformance
80 
81 - (id) LT:(NSInteger)k;
82 - (id) treeSource;
83 - (id<ANTLRTreeAdaptor>) getTreeAdaptor;
84 - (void)setTreeAdaptor:(id<ANTLRTreeAdaptor>)aTreeAdaptor;
85 - (id<ANTLRTokenStream>) getTokenStream;
86 - (void) setTokenStream:(id<ANTLRTokenStream>)aTokenStream;	///< Added by subclass, not in protocol
87 - (void) setUsesUniqueNavigationNodes:(BOOL)flag;
88 
89 - (id) nodeAtIndex:(NSUInteger) idx;
90 
91 - (NSString *) toString;
92 - (NSString *) toStringWithRange:(NSRange) aRange;
93 - (NSString *) toStringFromNode:(id)startNode toNode:(id)stopNode;
94 
95 #pragma mark ANTLRIntStream conformance
96 - (void) consume;
97 - (NSInteger) LA:(NSUInteger) i;
98 - (NSUInteger) mark;
99 - (NSUInteger) getIndex;
100 - (void) rewind:(NSUInteger) marker;
101 - (void) rewind;
102 - (void) release:(NSUInteger) marker;
103 - (void) seek:(NSUInteger) index;
104 - (NSUInteger) size;
105 
106 #pragma mark Lookahead Handling
107 - (void) addLookahead:(id<ANTLRBaseTree>)aNode;
108 - (NSUInteger) lookaheadSize;
109 - (void) fillBufferWithLookahead:(NSInteger)k;
110 - (id) nextObject;
111 
112 #pragma mark Node visiting
113 - (ANTLRCommonTree *) handleRootNode;
114 - (ANTLRCommonTree *) visitChild:(NSInteger)childNumber;
115 - (void) walkBackToMostRecentNodeWithUnvisitedChildren;
116 - (void) addNavigationNodeWithType:(NSInteger)tokenType;
117 
118 #pragma mark Accessors
119 - (ANTLRCommonTree *) root;
120 - (void) setRoot: (ANTLRCommonTree *) aRoot;
121 
122 @end
123