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 <Cocoa/Cocoa.h>
29#import "ANTLRToken.h"
30#import "ANTLRCharStream.h"
31
32@interface ANTLRCommonToken : NSObject < ANTLRToken > {
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<ANTLRCharStream> input;
48}
49
50+ (void) initialize;
51+ (NSInteger) DEFAULT_CHANNEL;
52+ (id<ANTLRToken>)INVALID_TOKEN;
53+ (NSInteger) INVALID_TOKEN_TYPE;
54+ (id<ANTLRToken>) newToken;
55+ (id<ANTLRToken>) newToken:(id<ANTLRCharStream>)anInput
56                       Type:(NSInteger)aTType
57                    Channel:(NSInteger)aChannel
58                      Start:(NSInteger)aStart
59                       Stop:(NSInteger)aStop;
60+ (id<ANTLRToken>) newToken:(ANTLRTokenType)aType;
61+ (id<ANTLRToken>) newToken:(NSInteger)tokenType Text:(NSString *)tokenText;
62+ (id<ANTLRToken>) newTokenWithToken:(ANTLRCommonToken *)fromToken;
63+ (id<ANTLRToken>) eofToken;
64+ (id<ANTLRToken>) skipToken;
65+ (id<ANTLRToken>) invalidToken;
66+ (ANTLRTokenChannel) 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<ANTLRCharStream>)anInput
71                                Type:(NSInteger)aTType
72                             Channel:(NSInteger)aChannel
73                               Start:(NSInteger)theStart
74                                Stop:(NSInteger)theStop;
75- (id) initWithToken:(id<ANTLRToken>)aToken;
76- (id) initWithType:(ANTLRTokenType)aType;
77- (id) initWithType:(ANTLRTokenType)aTType Text:(NSString *)tokenText;
78
79//----------------------------------------------------------
80//  text
81//----------------------------------------------------------
82- (NSString *)text;
83- (void) setText:(NSString *)aText;
84
85//----------------------------------------------------------
86//  type
87//----------------------------------------------------------
88- (NSInteger)type;
89- (void) setType:(NSInteger)aType;
90
91//----------------------------------------------------------
92//  channel
93//----------------------------------------------------------
94- (NSUInteger)channel;
95- (void) setChannel:(NSUInteger)aChannel;
96
97//----------------------------------------------------------
98//  input
99//----------------------------------------------------------
100- (id<ANTLRCharStream>)input;
101- (void) setInput:(id<ANTLRCharStream>)anInput;
102
103- (NSInteger)getStart;
104- (void) setStart: (NSInteger)aStart;
105
106- (NSInteger)getStop;
107- (void) setStop: (NSInteger) aStop;
108
109// the index of this Token into the TokenStream
110- (NSInteger)getTokenIndex;
111- (void) setTokenIndex:(NSInteger)aTokenIndex;
112
113// conform to NSCopying
114- (id) copyWithZone:(NSZone *)theZone;
115
116- (NSString *) description;
117- (NSString *) toString;
118
119@property (retain, getter = text, setter = setText:) NSString *text;
120@property (assign) NSInteger type;
121@property (assign, getter = line, setter = setLine:) NSUInteger line;
122@property (assign, getter=charPositionInLine, setter = setCharPositionInLine:) NSUInteger charPositionInLine;
123@property (assign) NSUInteger channel;
124@property (assign) NSInteger index;
125@property (assign, getter=getStart, setter=setStart:) NSInteger startIndex;
126@property (assign, getter=getStop, setter=setStop:) NSInteger stopIndex;
127@property (retain) id<ANTLRCharStream> input;
128
129@end
130