1 /* 2 [The "BSD license"] 3 Copyright (c) 2005-2009 Terence Parr 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions 8 are met: 9 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 // TODO: remove once we go ANTLR v3.3 42 public static final Token EOF_TOKEN = new CommonToken(EOF); 43 44 public static final int INVALID_TOKEN_TYPE = 0; 45 public static final Token INVALID_TOKEN = new CommonToken(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(INVALID_TOKEN_TYPE); 51 52 /** All tokens go to the parser (unless skip() is called in that rule) 53 * on a particular "channel". The parser tunes to a particular channel 54 * so that whitespace etc... can go to the parser on a "hidden" channel. 55 */ 56 public static final int DEFAULT_CHANNEL = 0; 57 58 /** Anything on different channel than DEFAULT_CHANNEL is not parsed 59 * by parser. 60 */ 61 public static final int HIDDEN_CHANNEL = 99; 62 63 /** Get the text of the token */ 64 public String getText(); 65 public void setText(String text); 66 67 public int getType(); 68 public void setType(int ttype); 69 /** The line number on which this token was matched; line=1..n */ 70 public int getLine(); 71 public void setLine(int line); 72 73 /** The index of the first character relative to the beginning of the line 0..n-1 */ 74 public int getCharPositionInLine(); 75 public void setCharPositionInLine(int pos); 76 77 public int getChannel(); 78 public void setChannel(int channel); 79 80 /** An index from 0..n-1 of the token object in the input stream. 81 * This must be valid in order to use the ANTLRWorks debugger. 82 */ 83 public int getTokenIndex(); 84 public void setTokenIndex(int index); 85 86 /** From what character stream was this token created? You don't have to 87 * implement but it's nice to know where a Token comes from if you have 88 * include files etc... on the input. 89 */ 90 public CharStream getInputStream(); 91 public void setInputStream(CharStream input); 92 } 93