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 #import "ANTLRTree.h"
     28 
     29 @protocol ANTLRBaseTree <ANTLRTree>
     30 
     31 @property (retain, getter=getChildren, setter=setChildren) NSMutableArray *children;
     32 
     33 + (id<ANTLRBaseTree>) newANTLRBaseTree;
     34 + (id<ANTLRBaseTree>) newANTLRBaseTree:(id<ANTLRBaseTree>)node;
     35 
     36 - (id<ANTLRBaseTree>) init;
     37 - (id<ANTLRBaseTree>) initWith:(id<ANTLRTree>)node;
     38 
     39 - (id<ANTLRBaseTree>) getChild:(NSUInteger)i;
     40 - (NSMutableArray *)getChildren;
     41 - (void) setChildren:(NSMutableArray *)anArray;
     42 - (id<ANTLRBaseTree>)getFirstChildWithType:(NSInteger)type;
     43 - (NSUInteger) getChildCount;
     44 
     45 // Add t as a child to this node.  If t is null, do nothing.  If t
     46 //  is nil, add all children of t to this' children.
     47 
     48 - (void) addChild:(id<ANTLRTree>) tree;
     49 - (void) addChildren:(NSArray *) theChildren;
     50 //- (void) removeAllChildren;
     51 
     52 - (void) setChild:(NSInteger) i With:(id<ANTLRTree>)t;
     53 - (id) deleteChild:(NSInteger) i;
     54 - (NSMutableArray *) createChildrenList;
     55 - (void) replaceChildrenFrom:(NSInteger)startChildIndex To:(NSInteger)stopChildIndex With:(id) t;
     56 // Indicates the node is a nil node but may still have children, meaning
     57 // the tree is a flat list.
     58 
     59 - (BOOL) isNil;
     60 - (NSInteger) getTokenStartIndex;
     61 - (void) setTokenStartIndex:(NSInteger) index;
     62 - (NSInteger) getTokenStopIndex;
     63 - (void) setTokenStopIndex:(NSInteger) index;
     64 
     65 - (void) freshenParentAndChildIndexes;
     66 - (void) freshenParentAndChildIndexes:(NSInteger) offset;
     67 - (void) sanityCheckParentAndChildIndexes;
     68 - (void) sanityCheckParentAndChildIndexes:(id<ANTLRTree>) parent At:(NSInteger) i;
     69 
     70 - (NSInteger) getChildIndex;
     71 - (void) setChildIndex:(NSInteger)i;
     72 
     73 - (id<ANTLRTree>)getAncestor:(NSInteger)ttype;
     74 - (NSMutableArray *)getAncestors;
     75 
     76 #pragma mark Copying
     77 - (id) copyWithZone:(NSZone *)aZone;	// the children themselves are not copied here!
     78 - (id) deepCopy;					// performs a deepCopyWithZone: with the default zone
     79 - (id) deepCopyWithZone:(NSZone *)aZone;
     80 
     81 #pragma mark Tree Parser support
     82 - (NSInteger) getType;
     83 - (NSString *) getText;
     84 // In case we don't have a token payload, what is the line for errors?
     85 - (NSInteger) getLine;
     86 - (NSInteger) getCharPositionInLine;
     87 
     88 
     89 #pragma mark Informational
     90 - (NSString *) treeDescription;
     91 - (NSString *) description;
     92 
     93 - (NSString *) toString;
     94 - (NSString *) toStringTree;
     95 
     96 @end
     97 
     98 @interface ANTLRBaseTree : NSObject <ANTLRTree>
     99 {
    100 	NSMutableArray *children;
    101     NSException *anException;
    102 }
    103 
    104 @property (retain, getter=getChildren, setter=setChildren) NSMutableArray *children;
    105 
    106 + (id<ANTLRBaseTree>) newANTLRBaseTree;
    107 + (id<ANTLRBaseTree>) newANTLRBaseTree:(id<ANTLRBaseTree>)node;
    108 
    109 - (id<ANTLRTree>) init;
    110 - (id<ANTLRBaseTree>) initWith:(id<ANTLRTree>)node;
    111 
    112 - (id<ANTLRBaseTree>) getChild:(NSUInteger)i;
    113 - (NSMutableArray *)getChildren;
    114 - (void) setChildren:(NSMutableArray *)anArray;
    115 - (id<ANTLRBaseTree>)getFirstChildWithType:(NSInteger)type;
    116 - (NSUInteger) getChildCount;
    117 
    118 //- (void) removeAllChildren;
    119 
    120 // Add t as a child to this node.  If t is null, do nothing.  If t
    121 //  is nil, add all children of t to this' children.
    122 
    123 - (void) addChild:(id<ANTLRTree>) tree;
    124 - (void) addChildren:(NSArray *) theChildren;
    125 
    126 - (void) setChild:(NSInteger) i With:(id<ANTLRTree>)t;
    127 - (id) deleteChild:(NSInteger) i;
    128 - (NSMutableArray *) createChildrenList;
    129 - (void) replaceChildrenFrom:(NSInteger)startChildIndex To:(NSInteger)stopChildIndex With:(id) t;
    130 // Indicates the node is a nil node but may still have children, meaning
    131 	// the tree is a flat list.
    132 
    133 - (BOOL) isNil;
    134 - (NSInteger) getTokenStartIndex;
    135 - (void) setTokenStartIndex:(NSInteger) index;
    136 - (NSInteger) getTokenStopIndex;
    137 - (void) setTokenStopIndex:(NSInteger) index;
    138 
    139 - (void) freshenParentAndChildIndexes;
    140 - (void) freshenParentAndChildIndexes:(NSInteger) offset;
    141 - (void) sanityCheckParentAndChildIndexes;
    142 - (void) sanityCheckParentAndChildIndexes:(id<ANTLRTree>) parent At:(NSInteger) i;
    143 
    144 - (NSInteger) getChildIndex;
    145 - (void) setChildIndex:(NSInteger)i;
    146 
    147 - (BOOL) hasAncestor:(NSInteger) ttype;
    148 - (id<ANTLRTree>)getAncestor:(NSInteger)ttype;
    149 - (NSMutableArray *)getAncestors;
    150 
    151 - (id) copyWithZone:(NSZone *)aZone;
    152 - (id) deepCopy;					// performs a deepCopyWithZone: with the default zone
    153 - (id) deepCopyWithZone:(NSZone *)aZone;
    154 
    155 	// Return a token type; needed for tree parsing
    156 - (NSInteger) getType;
    157 - (NSString *) getText;
    158 
    159 	// In case we don't have a token payload, what is the line for errors?
    160 - (NSInteger) getLine;
    161 - (NSInteger) getCharPositionInLine;
    162 - (void) setCharPositionInLine:(NSInteger)pos;
    163 
    164 - (NSString *) treeDescription;
    165 - (NSString *) description;
    166 - (NSString *) toString;
    167 - (NSString *) toStringTree;
    168 
    169 @end
    170 
    171 @interface ANTLRTreeNavigationNode : ANTLRBaseTree {
    172 }
    173 - (id) copyWithZone:(NSZone *)aZone;
    174 @end
    175 
    176 @interface ANTLRTreeNavigationNodeDown : ANTLRTreeNavigationNode {
    177 }
    178 + (ANTLRTreeNavigationNodeDown *) getNavigationNodeDown;
    179 - (NSInteger) tokenType;
    180 - (NSString *) description;
    181 @end
    182 
    183 @interface ANTLRTreeNavigationNodeUp : ANTLRTreeNavigationNode {
    184 }
    185 + (ANTLRTreeNavigationNodeUp *) getNavigationNodeUp;
    186 - (NSInteger) tokenType;
    187 - (NSString *) description;
    188 @end
    189 
    190 @interface ANTLRTreeNavigationNodeEOF : ANTLRTreeNavigationNode {
    191 }
    192 + (ANTLRTreeNavigationNodeEOF *) getNavigationNodeEOF;
    193 - (NSInteger) tokenType;
    194 - (NSString *) description;
    195 @end
    196 
    197 extern ANTLRTreeNavigationNodeDown *navigationNodeDown;
    198 extern ANTLRTreeNavigationNodeUp *navigationNodeUp;
    199 extern ANTLRTreeNavigationNodeEOF *navigationNodeEOF;
    200