01: /*
02: [The "BSD licence"]
03: Copyright (c) 2005-2007 Terence Parr
04: All rights reserved.
05:
06: Redistribution and use in source and binary forms, with or without
07: modification, are permitted provided that the following conditions
08: are met:
09: 1. Redistributions of source code must retain the above copyright
10: notice, this list of conditions and the following disclaimer.
11: 2. Redistributions in binary form must reproduce the above copyright
12: notice, this list of conditions and the following disclaimer in the
13: documentation and/or other materials provided with the distribution.
14: 3. The name of the author may not be used to endorse or promote products
15: derived from this software without specific prior written permission.
16:
17: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27: */
28: package org.antlr.runtime;
29:
30: public interface Token {
31: public static final int EOR_TOKEN_TYPE = 1;
32:
33: /** imaginary tree navigation type; traverse "get child" link */
34: public static final int DOWN = 2;
35: /** imaginary tree navigation type; finish with a child list */
36: public static final int UP = 3;
37:
38: public static final int MIN_TOKEN_TYPE = UP + 1;
39:
40: public static final int EOF = CharStream.EOF;
41: public static final Token EOF_TOKEN = new CommonToken(EOF);
42:
43: public static final int INVALID_TOKEN_TYPE = 0;
44: public static final Token INVALID_TOKEN = new CommonToken(
45: INVALID_TOKEN_TYPE);
46:
47: /** In an action, a lexer rule can set token to this SKIP_TOKEN and ANTLR
48: * will avoid creating a token for this symbol and try to fetch another.
49: */
50: public static final Token SKIP_TOKEN = new CommonToken(
51: INVALID_TOKEN_TYPE);
52:
53: /** All tokens go to the parser (unless skip() is called in that rule)
54: * on a particular "channel". The parser tunes to a particular channel
55: * so that whitespace etc... can go to the parser on a "hidden" channel.
56: */
57: public static final int DEFAULT_CHANNEL = 0;
58:
59: /** Anything on different channel than DEFAULT_CHANNEL is not parsed
60: * by parser.
61: */
62: public static final int HIDDEN_CHANNEL = 99;
63:
64: /** Get the text of the token */
65: public abstract String getText();
66:
67: public abstract void setText(String text);
68:
69: public abstract int getType();
70:
71: public abstract void setType(int ttype);
72:
73: /** The line number on which this token was matched; line=1..n */
74: public abstract int getLine();
75:
76: public abstract void setLine(int line);
77:
78: /** The index of the first character relative to the beginning of the line 0..n-1 */
79: public abstract int getCharPositionInLine();
80:
81: public abstract void setCharPositionInLine(int pos);
82:
83: public abstract int getChannel();
84:
85: public abstract void setChannel(int channel);
86:
87: /** An index from 0..n-1 of the token object in the input stream.
88: * This must be valid in order to use the ANTLRWorks debugger.
89: */
90: public abstract int getTokenIndex();
91:
92: public abstract void setTokenIndex(int index);
93: }
|