1*16467b97STreehugger Robot //
2*16467b97STreehugger Robot // TreeWizard.h
3*16467b97STreehugger Robot // ANTLR
4*16467b97STreehugger Robot //
5*16467b97STreehugger Robot // Created by Alan Condit on 6/18/10.
6*16467b97STreehugger Robot // [The "BSD licence"]
7*16467b97STreehugger Robot // Copyright (c) 2010 Alan Condit
8*16467b97STreehugger Robot // All rights reserved.
9*16467b97STreehugger Robot //
10*16467b97STreehugger Robot // Redistribution and use in source and binary forms, with or without
11*16467b97STreehugger Robot // modification, are permitted provided that the following conditions
12*16467b97STreehugger Robot // are met:
13*16467b97STreehugger Robot // 1. Redistributions of source code must retain the above copyright
14*16467b97STreehugger Robot // notice, this list of conditions and the following disclaimer.
15*16467b97STreehugger Robot // 2. Redistributions in binary form must reproduce the above copyright
16*16467b97STreehugger Robot // notice, this list of conditions and the following disclaimer in the
17*16467b97STreehugger Robot // documentation and/or other materials provided with the distribution.
18*16467b97STreehugger Robot // 3. The name of the author may not be used to endorse or promote products
19*16467b97STreehugger Robot // derived from this software without specific prior written permission.
20*16467b97STreehugger Robot //
21*16467b97STreehugger Robot // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22*16467b97STreehugger Robot // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23*16467b97STreehugger Robot // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24*16467b97STreehugger Robot // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25*16467b97STreehugger Robot // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26*16467b97STreehugger Robot // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27*16467b97STreehugger Robot // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28*16467b97STreehugger Robot // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29*16467b97STreehugger Robot // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30*16467b97STreehugger Robot // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*16467b97STreehugger Robot
32*16467b97STreehugger Robot #import <Foundation/Foundation.h>
33*16467b97STreehugger Robot #import "CommonTreeAdaptor.h"
34*16467b97STreehugger Robot #import "CommonTree.h"
35*16467b97STreehugger Robot #import "MapElement.h"
36*16467b97STreehugger Robot #import "Map.h"
37*16467b97STreehugger Robot #import "AMutableArray.h"
38*16467b97STreehugger Robot
39*16467b97STreehugger Robot @class ANTLRVisitor;
40*16467b97STreehugger Robot
41*16467b97STreehugger Robot @protocol ANTLRContextVisitor <NSObject>
42*16467b97STreehugger Robot // TODO: should this be called visit or something else?
43*16467b97STreehugger Robot - (void) visit:(CommonTree *)t Parent:(CommonTree *)parent ChildIndex:(NSInteger)childIndex Map:(Map *)labels;
44*16467b97STreehugger Robot
45*16467b97STreehugger Robot @end
46*16467b97STreehugger Robot
47*16467b97STreehugger Robot @interface ANTLRVisitor : NSObject <ANTLRContextVisitor> {
48*16467b97STreehugger Robot NSInteger action;
49*16467b97STreehugger Robot id actor;
50*16467b97STreehugger Robot id object1;
51*16467b97STreehugger Robot id object2;
52*16467b97STreehugger Robot }
53*16467b97STreehugger Robot + (ANTLRVisitor *)newANTLRVisitor:(NSInteger)anAction Actor:(id)anActor Object:(id)anObject1 Object:(id)anObject2;
54*16467b97STreehugger Robot - (id) initWithAction:(NSInteger)anAction Actor:(id)anActor Object:(id)anObject1 Object:(id)anObject2;
55*16467b97STreehugger Robot
56*16467b97STreehugger Robot - (void) visit:(CommonTree *)t;
57*16467b97STreehugger Robot - (void) visit:(CommonTree *)t Parent:(CommonTree *)parent ChildIndex:(NSInteger)childIndex Map:(Map *)labels;
58*16467b97STreehugger Robot
59*16467b97STreehugger Robot @property NSInteger action;
60*16467b97STreehugger Robot @property (retain) id actor;
61*16467b97STreehugger Robot @property (retain) id object1;
property(retain)62*16467b97STreehugger Robot @property (retain) id object2;
63*16467b97STreehugger Robot @end
64*16467b97STreehugger Robot
65*16467b97STreehugger Robot /** When using %label:TOKENNAME in a tree for parse(), we must
66*16467b97STreehugger Robot * track the label.
67*16467b97STreehugger Robot */
68*16467b97STreehugger Robot @interface TreePattern : CommonTree {
69*16467b97STreehugger Robot NSString *label;
70*16467b97STreehugger Robot BOOL hasTextArg;
71*16467b97STreehugger Robot }
72*16467b97STreehugger Robot @property (retain, getter=getLabel, setter=setLabel:) NSString *label;
73*16467b97STreehugger Robot @property (assign, getter=getHasTextArg, setter=setHasTextArg:) BOOL hasTextArg;
74*16467b97STreehugger Robot
75*16467b97STreehugger Robot + (CommonTree *)newTreePattern:(id<Token>)payload;
76*16467b97STreehugger Robot
77*16467b97STreehugger Robot - (id) initWithToken:(id<Token>)payload;
78*16467b97STreehugger Robot - (NSString *)toString;
79*16467b97STreehugger Robot @end
80*16467b97STreehugger Robot
81*16467b97STreehugger Robot @interface ANTLRWildcardTreePattern : TreePattern {
82*16467b97STreehugger Robot }
83*16467b97STreehugger Robot
84*16467b97STreehugger Robot + (ANTLRWildcardTreePattern *)newANTLRWildcardTreePattern:(id<Token>)payload;
85*16467b97STreehugger Robot - (id) initWithToken:(id<Token>)payload;
86*16467b97STreehugger Robot @end
87*16467b97STreehugger Robot
88*16467b97STreehugger Robot /** This adaptor creates TreePattern objects for use during scan() */
89*16467b97STreehugger Robot @interface TreePatternTreeAdaptor : CommonTreeAdaptor {
90*16467b97STreehugger Robot }
91*16467b97STreehugger Robot + (TreePatternTreeAdaptor *)newTreeAdaptor;
92*16467b97STreehugger Robot - (id) init;
93*16467b97STreehugger Robot - (CommonTree *)createTreePattern:(id<Token>)payload;
94*16467b97STreehugger Robot
95*16467b97STreehugger Robot @end
96*16467b97STreehugger Robot
97*16467b97STreehugger Robot @interface TreeWizard : NSObject {
98*16467b97STreehugger Robot id<TreeAdaptor> adaptor;
99*16467b97STreehugger Robot Map *tokenNameToTypeMap;
100*16467b97STreehugger Robot }
101*16467b97STreehugger Robot + (TreeWizard *) newTreeWizard:(id<TreeAdaptor>)anAdaptor;
102*16467b97STreehugger Robot + (TreeWizard *)newTreeWizard:(id<TreeAdaptor>)adaptor Map:(Map *)aTokenNameToTypeMap;
103*16467b97STreehugger Robot + (TreeWizard *)newTreeWizard:(id<TreeAdaptor>)adaptor TokenNames:(NSArray *)theTokNams;
104*16467b97STreehugger Robot + (TreeWizard *)newTreeWizardWithTokenNames:(NSArray *)theTokNams;
105*16467b97STreehugger Robot - (id) init;
106*16467b97STreehugger Robot - (id) initWithAdaptor:(id<TreeAdaptor>)adaptor;
107*16467b97STreehugger Robot - (id) initWithAdaptor:(id<TreeAdaptor>)adaptor Map:(Map *)tokenNameToTypeMap;
108*16467b97STreehugger Robot - (id) initWithTokenNames:(NSArray *)theTokNams;
109*16467b97STreehugger Robot - (id) initWithTokenNames:(id<TreeAdaptor>)anAdaptor TokenNames:(NSArray *)theTokNams;
110*16467b97STreehugger Robot - (void) dealloc;
111*16467b97STreehugger Robot - (Map *)computeTokenTypes:(NSArray *)theTokNams;
112*16467b97STreehugger Robot - (NSInteger)getTokenType:(NSString *)tokenName;
113*16467b97STreehugger Robot - (Map *)index:(CommonTree *)t;
114*16467b97STreehugger Robot - (void) _index:(CommonTree *)t Map:(Map *)m;
115*16467b97STreehugger Robot - (AMutableArray *)find:(CommonTree *) t Pattern:(NSString *)pattern;
116*16467b97STreehugger Robot - (TreeWizard *)findFirst:(CommonTree *) t Type:(NSInteger)ttype;
117*16467b97STreehugger Robot - (TreeWizard *)findFirst:(CommonTree *) t Pattern:(NSString *)pattern;
118*16467b97STreehugger Robot - (void) visit:(CommonTree *)t Type:(NSInteger)ttype Visitor:(ANTLRVisitor *)visitor;
119*16467b97STreehugger Robot - (void) _visit:(CommonTree *)t
120*16467b97STreehugger Robot Parent:(CommonTree *)parent
121*16467b97STreehugger Robot ChildIndex:(NSInteger)childIndex
122*16467b97STreehugger Robot Type:(NSInteger)ttype
123*16467b97STreehugger Robot Visitor:(ANTLRVisitor *)visitor;
124*16467b97STreehugger Robot - (void)visit:(CommonTree *)t Pattern:(NSString *)pattern Visitor:(ANTLRVisitor *)visitor;
125*16467b97STreehugger Robot - (BOOL)parse:(CommonTree *)t Pattern:(NSString *)pattern Map:(Map *)labels;
126*16467b97STreehugger Robot - (BOOL) parse:(CommonTree *) t Pattern:(NSString *)pattern;
127*16467b97STreehugger Robot - (BOOL) _parse:(CommonTree *)t1 Pattern:(CommonTree *)tpattern Map:(Map *)labels;
128*16467b97STreehugger Robot - (CommonTree *) createTree:(NSString *)pattern;
129*16467b97STreehugger Robot - (BOOL)equals:(id)t1 O2:(id)t2 Adaptor:(id<TreeAdaptor>)anAdaptor;
130*16467b97STreehugger Robot - (BOOL)equals:(id)t1 O2:(id)t2;
131*16467b97STreehugger Robot - (BOOL) _equals:(id)t1 O2:(id)t2 Adaptor:(id<TreeAdaptor>)anAdaptor;
132*16467b97STreehugger Robot
133*16467b97STreehugger Robot @property (retain) id<TreeAdaptor> adaptor;
134*16467b97STreehugger Robot @property (retain) Map *tokenNameToTypeMap;
135*16467b97STreehugger Robot @end
136*16467b97STreehugger Robot
137