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