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 <Foundation/Foundation.h>
29 #import "Token.h"
30 #import "CharStream.h"
31 
32 @interface CommonToken : NSObject < Token > {
33 	__strong NSString *text;
34 	NSInteger type;
35 	// information about the Token's position in the input stream
36 	NSUInteger line;
37 	NSUInteger charPositionInLine;
38 	NSUInteger channel;
39 	// this token's position in the TokenStream
40 	NSInteger index;
41 
42 	// indices into the CharStream to avoid copying the text
43 	// can manually override the text by using -setText:
44 	NSInteger startIndex;
45 	NSInteger stopIndex;
46 	// the actual input stream this token was found in
47 	__strong id<CharStream> input;
48 }
49 
50 + (void) initialize;
51 + (NSInteger) DEFAULT_CHANNEL;
52 + (id<Token>)INVALID_TOKEN;
53 + (NSInteger) INVALID_TOKEN_TYPE;
54 + (id<Token>) newToken;
55 + (id<Token>) newToken:(id<CharStream>)anInput
56                        Type:(NSInteger)aTType
57                     Channel:(NSInteger)aChannel
58                       Start:(NSInteger)aStart
59                        Stop:(NSInteger)aStop;
60 + (id<Token>) newToken:(TokenType)aType;
61 + (id<Token>) newToken:(NSInteger)tokenType Text:(NSString *)tokenText;
62 + (id<Token>) newTokenWithToken:(CommonToken *)fromToken;
63 + (id<Token>) eofToken;
64 + (id<Token>) skipToken;
65 + (id<Token>) invalidToken;
66 + (TokenChannel) defaultChannel;
67 
68 // designated initializer. This is used as the default way to initialize a Token in the generated code.
69 - (id) init;
70 - (id) initWithInput:(id<CharStream>)anInput
71                                 Type:(NSInteger)aTType
72                              Channel:(NSInteger)aChannel
73                                Start:(NSInteger)theStart
74                                 Stop:(NSInteger)theStop;
75 - (id) initWithToken:(id<Token>)aToken;
76 - (id) initWithType:(TokenType)aType;
77 - (id) initWithType:(TokenType)aTType Text:(NSString *)tokenText;
78 
79 //----------------------------------------------------------
80 //  text
81 //----------------------------------------------------------
82 - (NSString *)text;
83 - (void) setText:(NSString *)aText;
84 
85 //----------------------------------------------------------
86 //  charPositionInLine
87 //----------------------------------------------------------
88 - (NSUInteger) getCharPositionInLine;
89 - (void) setCharPositionInLine:(NSUInteger)aCharPositionInLine;
90 
91 //----------------------------------------------------------
92 //  line
93 //----------------------------------------------------------
94 - (NSUInteger) getLine;
95 - (void) setLine:(NSUInteger)aLine;
96 
97 //----------------------------------------------------------
98 //  type
99 //----------------------------------------------------------
100 - (NSInteger)type;
101 - (void) setType:(NSInteger)aType;
102 
103 //----------------------------------------------------------
104 //  channel
105 //----------------------------------------------------------
106 - (NSUInteger)channel;
107 - (void) setChannel:(NSUInteger)aChannel;
108 
109 //----------------------------------------------------------
110 //  input
111 //----------------------------------------------------------
112 - (id<CharStream>)input;
113 - (void) setInput:(id<CharStream>)anInput;
114 
115 - (NSInteger)getStart;
116 - (void) setStart: (NSInteger)aStart;
117 
118 - (NSInteger)getStop;
119 - (void) setStop: (NSInteger) aStop;
120 
121 // the index of this Token into the TokenStream
122 - (NSInteger)getTokenIndex;
123 - (void) setTokenIndex:(NSInteger)aTokenIndex;
124 
125 // conform to NSCopying
126 - (id) copyWithZone:(NSZone *)theZone;
127 
128 - (NSString *) description;
129 - (NSString *) toString;
130 
131 @property (retain, getter = text, setter = setText:) NSString *text;
132 @property (assign) NSInteger type;
133 @property (assign, getter = line, setter = setLine:) NSUInteger line;
134 @property (assign, getter=charPositionInLine, setter = setCharPositionInLine:) NSUInteger charPositionInLine;
135 @property (assign) NSUInteger channel;
136 @property (assign) NSInteger index;
137 @property (assign, getter=getStart, setter=setStart:) NSInteger startIndex;
138 @property (assign, getter=getStop, setter=setStop:) NSInteger stopIndex;
139 @property (retain) id<CharStream> input;
140 
141 @end
142