13447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein/*
23447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein [The "BSD license"]
33447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein Copyright (c) 2005-2009 Terence Parr
43447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein All rights reserved.
53447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
63447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein Redistribution and use in source and binary forms, with or without
73447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein modification, are permitted provided that the following conditions
83447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein are met:
93447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein 1. Redistributions of source code must retain the above copyright
103447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein     notice, this list of conditions and the following disclaimer.
113447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein 2. Redistributions in binary form must reproduce the above copyright
123447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein     notice, this list of conditions and the following disclaimer in the
133447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein     documentation and/or other materials provided with the distribution.
143447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein 3. The name of the author may not be used to endorse or promote products
153447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein     derived from this software without specific prior written permission.
163447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
173447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
183447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
193447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
203447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
213447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
263447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein */
283447a5916aa62f44de24cc441fc9987116ddff52Andrew Sappersteinpackage org.antlr.runtime;
293447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
303447a5916aa62f44de24cc441fc9987116ddff52Andrew Sappersteinpublic interface Token {
313447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public static final int EOR_TOKEN_TYPE = 1;
323447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
333447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** imaginary tree navigation type; traverse "get child" link */
343447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public static final int DOWN = 2;
353447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** imaginary tree navigation type; finish with a child list */
363447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public static final int UP = 3;
373447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
383447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public static final int MIN_TOKEN_TYPE = UP+1;
393447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
403447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein    public static final int EOF = CharStream.EOF;
413447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein    // TODO: remove once we go ANTLR v3.3
423447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein    public static final Token EOF_TOKEN = new CommonToken(EOF);
433447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
443447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public static final int INVALID_TOKEN_TYPE = 0;
453447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public static final Token INVALID_TOKEN = new CommonToken(INVALID_TOKEN_TYPE);
463447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
473447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** In an action, a lexer rule can set token to this SKIP_TOKEN and ANTLR
483447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  will avoid creating a token for this symbol and try to fetch another.
493447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 */
503447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public static final Token SKIP_TOKEN = new CommonToken(INVALID_TOKEN_TYPE);
513447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
523447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** All tokens go to the parser (unless skip() is called in that rule)
533447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  on a particular "channel".  The parser tunes to a particular channel
543447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  so that whitespace etc... can go to the parser on a "hidden" channel.
553447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 */
563447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public static final int DEFAULT_CHANNEL = 0;
573447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
583447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** Anything on different channel than DEFAULT_CHANNEL is not parsed
593447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  by parser.
603447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 */
613447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public static final int HIDDEN_CHANNEL = 99;
623447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
633447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** Get the text of the token */
643447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public String getText();
653447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public void setText(String text);
663447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
673447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public int getType();
683447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public void setType(int ttype);
693447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/**  The line number on which this token was matched; line=1..n */
703447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public int getLine();
713447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein    public void setLine(int line);
723447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
733447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** The index of the first character relative to the beginning of the line 0..n-1 */
743447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public int getCharPositionInLine();
753447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public void setCharPositionInLine(int pos);
763447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
773447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public int getChannel();
783447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public void setChannel(int channel);
793447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
803447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** An index from 0..n-1 of the token object in the input stream.
813447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  This must be valid in order to use the ANTLRWorks debugger.
823447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 */
833447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public int getTokenIndex();
843447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public void setTokenIndex(int index);
853447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein
863447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	/** From what character stream was this token created?  You don't have to
873447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  implement but it's nice to know where a Token comes from if you have
883447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 *  include files etc... on the input.
893447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	 */
903447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public CharStream getInputStream();
913447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein	public void setInputStream(CharStream input);
923447a5916aa62f44de24cc441fc9987116ddff52Andrew Sapperstein}
93