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
38@class ANTLRVisitor;
39
40@protocol ANTLRContextVisitor <NSObject>
41// TODO: should this be called visit or something else?
42- (void) visit:(id<ANTLRTree>)t Parent:(id<ANTLRTree>)parent ChildIndex:(NSInteger)childIndex Map:(ANTLRMap *)labels;
43
44@end
45
46@interface ANTLRVisitor : NSObject <ANTLRContextVisitor> {
47    NSInteger action;
48    id actor;
49    id object1;
50    id object2;
51}
52+ (ANTLRVisitor *)newANTLRVisitor:(NSInteger)anAction Actor:(id)anActor Object:(id)anObject1 Object:(id)anObject2;
53- (id) initWithAction:(NSInteger)anAction Actor:(id)anActor Object:(id)anObject1 Object:(id)anObject2;
54
55- (void) visit:(id<ANTLRTree>)t;
56- (void) visit:(id<ANTLRTree>)t Parent:(id<ANTLRTree>)parent ChildIndex:(NSInteger)childIndex Map:(ANTLRMap *)labels;
57
58@end
59
60/** When using %label:TOKENNAME in a tree for parse(), we must
61 *  track the label.
62 */
63@interface ANTLRTreePattern : ANTLRCommonTree {
64    NSString *label;
65    BOOL      hasTextArg;
66}
67@property (retain, getter=getLabel, setter=setLabel:) NSString *label;
68@property (assign, getter=getHasTextArg, setter=setHasTextArg:) BOOL hasTextArg;
69
70+ (ANTLRTreePattern *)newANTLRTreePattern:(id<ANTLRToken>)payload;
71
72- (id) initWithToken:(id<ANTLRToken>)payload;
73- (NSString *)toString;
74@end
75
76@interface ANTLRWildcardTreePattern : ANTLRTreePattern {
77}
78
79+ (ANTLRWildcardTreePattern *)newANTLRWildcardTreePattern:(id<ANTLRToken>)payload;
80- (id) initWithToken:(id<ANTLRToken>)payload;
81@end
82
83/** This adaptor creates TreePattern objects for use during scan() */
84@interface ANTLRTreePatternTreeAdaptor : ANTLRCommonTreeAdaptor {
85}
86+ (ANTLRTreePatternTreeAdaptor *)newTreeAdaptor;
87#ifdef DONTUSENOMO
88+ (ANTLRTreePatternTreeAdaptor *)newTreeAdaptor:(id<ANTLRToken>)payload;
89#endif
90- (id) init;
91#ifdef DONTUSENOMO
92- initWithToken:(id<ANTLRToken>)payload;
93#endif
94- (id<ANTLRTree>)createTreePattern:(id<ANTLRToken>)payload;
95
96@end
97
98@interface ANTLRTreeWizard : NSObject {
99	id<ANTLRTreeAdaptor> adaptor;
100	ANTLRMap *tokenNameToTypeMap;
101}
102+ (ANTLRTreeWizard *) newANTLRTreeWizard:(id<ANTLRTreeAdaptor>)anAdaptor;
103+ (ANTLRTreeWizard *)newANTLRTreeWizard:(id<ANTLRTreeAdaptor>)adaptor Map:(ANTLRMap *)aTokenNameToTypeMap;
104+ (ANTLRTreeWizard *)newANTLRTreeWizard:(id<ANTLRTreeAdaptor>)adaptor TokenNames:(NSArray *)theTokNams;
105+ (ANTLRTreeWizard *)newANTLRTreeWizardWithTokenNames:(NSArray *)theTokNams;
106- (id) init;
107- (id) initWithAdaptor:(id<ANTLRTreeAdaptor>)adaptor;
108- (id) initWithAdaptor:(id<ANTLRTreeAdaptor>)adaptor Map:(ANTLRMap *)tokenNameToTypeMap;
109- (id) initWithTokenNames:(NSArray *)theTokNams;
110- (id) initWithTokenNames:(id<ANTLRTreeAdaptor>)anAdaptor TokenNames:(NSArray *)theTokNams;
111- (ANTLRMap *)computeTokenTypes:(NSArray *)theTokNams;
112- (NSInteger)getTokenType:(NSString *)tokenName;
113- (ANTLRMap *)index:(id<ANTLRTree>)t;
114- (void) _index:(id<ANTLRTree>)t Map:(ANTLRMap *)m;
115- (NSMutableArray *)find:(id<ANTLRTree>) t Pattern:(NSString *)pattern;
116- (ANTLRTreeWizard *)findFirst:(id<ANTLRTree>) t Type:(NSInteger)ttype;
117- (ANTLRTreeWizard *)findFirst:(id<ANTLRTree>) t Pattern:(NSString *)pattern;
118- (void) visit:(id<ANTLRTree>)t Type:(NSInteger)ttype Visitor:(ANTLRVisitor *)visitor;
119- (void) _visit:(id<ANTLRTree>)t
120         Parent:(id<ANTLRTree>)parent
121     ChildIndex:(NSInteger)childIndex
122           Type:(NSInteger)ttype
123        Visitor:(ANTLRVisitor *)visitor;
124- (void)visit:(id<ANTLRTree>)t Pattern:(NSString *)pattern Visitor:(ANTLRVisitor *)visitor;
125- (BOOL)parse:(id<ANTLRTree>)t Pattern:(NSString *)pattern Map:(ANTLRMap *)labels;
126- (BOOL) parse:(id<ANTLRTree>) t Pattern:(NSString *)pattern;
127- (BOOL) _parse:(id<ANTLRTree>)t1 Pattern:(ANTLRTreePattern *)tpattern Map:(ANTLRMap *)labels;
128- (id<ANTLRTree>) 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@end
134
135