1324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** \file
2324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * \brief Defines the interface for a common token.
3324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *
4324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * All token streams should provide their tokens using an instance
5324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * of this common token. A custom pointer is provided, wher you may attach
6324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * a further structure to enhance the common token if you feel the need
7324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * to do so. The C runtime will assume that a token provides implementations
8324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * of the interface functions, but all of them may be rplaced by your own
9324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * implementation if you require it.
10324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
11324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#ifndef	_ANTLR3_COMMON_TOKEN_H
12324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	_ANTLR3_COMMON_TOKEN_H
13324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
14324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// [The "BSD licence"]
15324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
16324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// http://www.temporal-wave.com
17324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// http://www.linkedin.com/in/jimidle
18324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//
19324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// All rights reserved.
20324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//
21324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// Redistribution and use in source and binary forms, with or without
22324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// modification, are permitted provided that the following conditions
23324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// are met:
24324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// 1. Redistributions of source code must retain the above copyright
25324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//    notice, this list of conditions and the following disclaimer.
26324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// 2. Redistributions in binary form must reproduce the above copyright
27324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//    notice, this list of conditions and the following disclaimer in the
28324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//    documentation and/or other materials provided with the distribution.
29324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// 3. The name of the author may not be used to endorse or promote products
30324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//    derived from this software without specific prior written permission.
31324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//
32324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
43324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#include    <antlr3defs.h>
44324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
45324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** How many tokens to allocate at once in the token factory
46324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
47324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	ANTLR3_FACTORY_POOL_SIZE    1024
48324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
49324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* Base token types, which all lexer/parser tokens come after in sequence.
50324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
51324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
52324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** Indicator of an invalid token
53324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
54324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	ANTLR3_TOKEN_INVALID	0
55324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
56324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	ANTLR3_EOR_TOKEN_TYPE	1
57324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
58324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** Imaginary token type to cause a traversal of child nodes in a tree parser
59324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
60324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	ANTLR3_TOKEN_DOWN		2
61324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
62324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** Imaginary token type to signal the end of a stream of child nodes.
63324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
64324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	ANTLR3_TOKEN_UP		3
65324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
66324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** First token that can be used by users/generated code
67324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
68324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
69324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	ANTLR3_MIN_TOKEN_TYPE	ANTLR3_TOKEN_UP + 1
70324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
71324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** End of file token
72324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
73324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	ANTLR3_TOKEN_EOF	(ANTLR3_CHARSTREAM_EOF & 0xFFFFFFFF)
74324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
75324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** Default channel for a token
76324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
77324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	ANTLR3_TOKEN_DEFAULT_CHANNEL	0
78324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
79324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** Reserved channel number for a HIDDEN token - a token that
80324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *  is hidden from the parser.
81324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
82324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	HIDDEN				99
83324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
84324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#ifdef __cplusplus
85324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverextern "C" {
86324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#endif
87324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
88324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// Indicates whether this token is carrying:
89324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//
90324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// State | Meaning
91324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// ------+--------------------------------------
92324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//     0 | Nothing (neither rewrite text, nor setText)
93324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//     1 | char * to user supplied rewrite text
94324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//     2 | pANTLR3_STRING because of setText or similar action
95324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver//
96324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	ANTLR3_TEXT_NONE	0
97324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	ANTLR3_TEXT_CHARP	1
98324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#define	ANTLR3_TEXT_STRING	2
99324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
100324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** The definition of an ANTLR3 common token structure, which all implementations
101324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * of a token stream should provide, installing any further structures in the
102324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * custom pointer element of this structure.
103324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *
104324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * \remark
105324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * Token streams are in essence provided by lexers or other programs that serve
106324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * as lexers.
107324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
108324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruvertypedef	struct ANTLR3_COMMON_TOKEN_struct
109324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{
110324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** The actual type of this token
111324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
112324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_UINT32   type;
113324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
114324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Indicates that a token was produced from the token factory and therefore
115324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  the the freeToken() method should not do anything itself because
116324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  token factory is responsible for deleting it.
117324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
118324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_BOOLEAN  factoryMade;
119324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
120324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	/// A string factory that we can use if we ever need the text of a token
121324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	/// and need to manufacture a pANTLR3_STRING
122324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	///
123324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	pANTLR3_STRING_FACTORY	strFactory;
124324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
125324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** The line number in the input stream where this token was derived from
126324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
127324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_UINT32   line;
128324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
129324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** The offset into the input stream that the line in which this
130324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  token resides starts.
131324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
132324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void	    * lineStart;
133324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
134324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** The character position in the line that this token was derived from
135324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
136324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_INT32    charPosition;
137324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
138324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** The virtual channel that this token exists in.
139324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
140324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_UINT32   channel;
141324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
142324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to the input stream that this token originated in.
143324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
144324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    pANTLR3_INPUT_STREAM    input;
145324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
146324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** What the index of this token is, 0, 1, .., n-2, n-1 tokens
147324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
148324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_MARKER   index;
149324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
150324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** The character offset in the input stream where the text for this token
151324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  starts.
152324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
153324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_MARKER   start;
154324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
155324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** The character offset in the input stream where the text for this token
156324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  stops.
157324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
158324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_MARKER   stop;
159324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
160324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	/// Indicates whether this token is carrying:
161324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	///
162324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	/// State | Meaning
163324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	/// ------+--------------------------------------
164324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	///     0 | Nothing (neither rewrite text, nor setText)
165324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	///     1 | char * to user supplied rewrite text
166324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	///     2 | pANTLR3_STRING because of setText or similar action
167324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	///
168324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	/// Affects the union structure tokText below
169324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	/// (uses 32 bit so alignment is always good)
170324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	///
171324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	ANTLR3_UINT32	textState;
172324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
173324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	union
174324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	{
175324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		/// Pointer that is used when the token just has a pointer to
176324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		/// a char *, such as when a rewrite of an imaginary token supplies
177324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		/// a string in the grammar. No sense in constructing a pANTLR3_STRING just
178324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		/// for that, as mostly the text will not be accessed - if it is, then
179324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		/// we will build a pANTLR3_STRING for it a that point.
180324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		///
181324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		pANTLR3_UCHAR	chars;
182324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
183324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		/// Some token types actually do carry around their associated text, hence
184324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		/// (*getText)() will return this pointer if it is not NULL
185324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		///
186324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		pANTLR3_STRING	text;
187324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver	}
188324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver		tokText;
189324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
190324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /**  Because it is a bit more of a hassle to override an ANTLR3_COMMON_TOKEN
191324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *   as the standard structure for a token, a number of user programmable
192324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *	 elements are allowed in a token. This is one of them.
193324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
194324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_UINT32   user1;
195324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
196324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /**  Because it is a bit more of a hassle to override an ANTLR3_COMMON_TOKEN
197324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *   as the standard structure for a token, a number of user programmable
198324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *	 elements are allowed in a token. This is one of them.
199324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
200324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_UINT32   user2;
201324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
202324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /**  Because it is a bit more of a hassle to override an ANTLR3_COMMON_TOKEN
203324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *   as the standard structure for a token, a number of user programmable
204324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *	 elements are allowed in a token. This is one of them.
205324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
206324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_UINT32   user3;
207324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
208324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a custom element that the ANTLR3 programmer may define and install
209324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
210324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void    * custom;
211324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
212324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that knows how to free the custom structure when the
213324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  token is destroyed.
214324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
215324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void    (*freeCustom)(void * custom);
216324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
217324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /* ==============================
218324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     * API
219324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
220324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
221324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to function that returns the text pointer of a token, use
222324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  toString() if you want a pANTLR3_STRING version of the token.
223324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
224324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    pANTLR3_STRING  (*getText)(struct ANTLR3_COMMON_TOKEN_struct * token);
225324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
226324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that 'might' be able to set the text associated
227324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  with a token. Imaginary tokens such as an ANTLR3_CLASSIC_TOKEN may actually
228324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  do this, however many tokens such as ANTLR3_COMMON_TOKEN do not actaully have
229324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  strings associated with them but just point into the current input stream. These
230324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  tokens will implement this function with a function that errors out (probably
231324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  drastically.
232324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
233324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void	    (*setText)(struct ANTLR3_COMMON_TOKEN_struct * token, pANTLR3_STRING text);
234324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
235324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that 'might' be able to set the text associated
236324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  with a token. Imaginary tokens such as an ANTLR3_CLASSIC_TOKEN may actually
237324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  do this, however many tokens such as ANTLR3_COMMON_TOKEN do not actully have
238324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  strings associated with them but just point into the current input stream. These
239324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  tokens will implement this function with a function that errors out (probably
240324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  drastically.
241324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
242324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void	    (*setText8)(struct ANTLR3_COMMON_TOKEN_struct * token, pANTLR3_UINT8 text);
243324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
244324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that returns the token type of this token
245324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
246324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_UINT32   (*getType)(struct ANTLR3_COMMON_TOKEN_struct * token);
247324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
248324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that sets the type of this token
249324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
250324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void	    (*setType)(struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_UINT32 ttype);
251324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
252324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that gets the 'line' number where this token resides
253324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
254324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_UINT32   (*getLine)(struct ANTLR3_COMMON_TOKEN_struct * token);
255324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
256324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that sets the 'line' number where this token reside
257324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
258324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void	    (*setLine)(struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_UINT32 line);
259324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
260324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that gets the offset in the line where this token exists
261324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
262324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_INT32    (*getCharPositionInLine)	(struct ANTLR3_COMMON_TOKEN_struct * token);
263324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
264324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that sets the offset in the line where this token exists
265324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
266324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void	    (*setCharPositionInLine)	(struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_INT32 pos);
267324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
268324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that gets the channel that this token was placed in (parsers
269324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  can 'tune' to these channels.
270324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
271324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_UINT32   (*getChannel)	(struct ANTLR3_COMMON_TOKEN_struct * token);
272324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
273324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that sets the channel that this token should belong to
274324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
275324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void	    (*setChannel)	(struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_UINT32 channel);
276324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
277324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that returns an index 0...n-1 of the token in the token
278324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  input stream.
279324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
280324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_MARKER   (*getTokenIndex)	(struct ANTLR3_COMMON_TOKEN_struct * token);
281324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
282324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that can set the token index of this token in the token
283324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  input stream.
284324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
285324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void			(*setTokenIndex)	(struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_MARKER);
286324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
287324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that gets the start index in the input stream for this token.
288324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
289324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_MARKER   (*getStartIndex)	(struct ANTLR3_COMMON_TOKEN_struct * token);
290324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
291324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that sets the start index in the input stream for this token.
292324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
293324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void			(*setStartIndex)	(struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_MARKER index);
294324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
295324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that gets the stop index in the input stream for this token.
296324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
297324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_MARKER   (*getStopIndex)	(struct ANTLR3_COMMON_TOKEN_struct * token);
298324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
299324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that sets the stop index in the input stream for this token.
300324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
301324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void			(*setStopIndex)	(struct ANTLR3_COMMON_TOKEN_struct * token, ANTLR3_MARKER index);
302324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
303324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that returns this token as a text representation that can be
304324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  printed with embedded control codes such as \n replaced with the printable sequence "\\n"
305324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  This also yields a string structure that can be used more easily than the pointer to
306324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  the input stream in certain situations.
307324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
308324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    pANTLR3_STRING  (*toString)		(struct ANTLR3_COMMON_TOKEN_struct * token);
309324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}
310324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_COMMON_TOKEN;
311324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
312324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** \brief ANTLR3 Token factory interface to create lots of tokens efficiently
313324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver *  rather than creating and freeing lots of little bits of memory.
314324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */
315324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruvertypedef	struct ANTLR3_TOKEN_FACTORY_struct
316324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{
317324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointers to the array of tokens that this factory has produced so far
318324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
319324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    pANTLR3_COMMON_TOKEN    *pools;
320324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
321324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Current pool tokens we are allocating from
322324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
323324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_INT32	    thisPool;
324324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
325324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Maximum pool count we have available
326324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
327324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_INT32            maxPool;
328324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
329324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** The next token to throw out from the pool, will cause a new pool allocation
330324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  if this exceeds the available tokenCount
331324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
332324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_UINT32	    nextToken;
333324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
334324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Trick to initialize tokens and their API quickly, we set up this token when the
335324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  factory is created, then just copy the memory it uses into the new token.
336324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
337324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_COMMON_TOKEN	    unTruc;
338324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
339324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to an input stream that is using this token factory (may be NULL)
340324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  which will be assigned to the tokens automatically.
341324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
342324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    pANTLR3_INPUT_STREAM    input;
343324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
344324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that returns a new token
345324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
346324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    pANTLR3_COMMON_TOKEN    (*newToken)	    (struct ANTLR3_TOKEN_FACTORY_struct * factory);
347324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
348324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that resets the factory so you can reuse the pools it
349324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  has laready allocated
350324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
351324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void                    (*reset)	    (struct ANTLR3_TOKEN_FACTORY_struct * factory);
352324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
353324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function that changes teh curent inptu stream so that
354324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     *  new tokens are created with reference to their originating text.
355324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
356324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void		    (*setInputStream)	(struct ANTLR3_TOKEN_FACTORY_struct * factory, pANTLR3_INPUT_STREAM input);
357324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    /** Pointer to a function the destroys the factory
358324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver     */
359324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    void		    (*close)	    (struct ANTLR3_TOKEN_FACTORY_struct * factory);
360324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}
361324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    ANTLR3_TOKEN_FACTORY;
362324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
363324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#ifdef __cplusplus
364324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}
365324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#endif
366324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
367324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#endif
368