001 /*
002 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package com.sun.tools.javac.parser;
027
028 import com.sun.tools.javac.util.*;
029 import com.sun.tools.javac.util.Position.LineMap;
030
031 /**
032 * The lexical analyzer maps an input stream consisting of ASCII
033 * characters and Unicode escapes into a token sequence.
034 *
035 * <p><b>This is NOT part of any API supported by Sun Microsystems.
036 * If you write code that depends on this, you do so at your own risk.
037 * This code and its internal interfaces are subject to change or
038 * deletion without notice.</b>
039 */
040 public interface Lexer {
041
042 /**
043 * Has a @deprecated been encountered in last doc comment?
044 * This needs to be reset by client with resetDeprecatedFlag.
045 */
046 boolean deprecatedFlag();
047
048 void resetDeprecatedFlag();
049
050 /**
051 * Returns the documentation string of the current token.
052 */
053 String docComment();
054
055 /**
056 * Return the last character position of the current token.
057 */
058 int endPos();
059
060 /**
061 * Return the position where a lexical error occurred;
062 */
063 int errPos();
064
065 /**
066 * Set the position where a lexical error occurred;
067 */
068 void errPos(int pos);
069
070 /**
071 * Build a map for translating between line numbers and
072 * positions in the input.
073 *
074 * @return a LineMap
075 */
076 LineMap getLineMap();
077
078 /**
079 * Returns a copy of the input buffer, up to its inputLength.
080 * Unicode escape sequences are not translated.
081 */
082 char[] getRawCharacters();
083
084 /**
085 * Returns a copy of a character array subset of the input buffer.
086 * The returned array begins at the <code>beginIndex</code> and
087 * extends to the character at index <code>endIndex - 1</code>.
088 * Thus the length of the substring is <code>endIndex-beginIndex</code>.
089 * This behavior is like
090 * <code>String.substring(beginIndex, endIndex)</code>.
091 * Unicode escape sequences are not translated.
092 *
093 * @param beginIndex the beginning index, inclusive.
094 * @param endIndex the ending index, exclusive.
095 * @throws IndexOutOfBounds if either offset is outside of the
096 * array bounds
097 */
098 char[] getRawCharacters(int beginIndex, int endIndex);
099
100 /**
101 * Return the name of an identifier or token for the current token.
102 */
103 Name name();
104
105 /**
106 * Read token.
107 */
108 void nextToken();
109
110 /**
111 * Return the current token's position: a 0-based
112 * offset from beginning of the raw input stream
113 * (before unicode translation)
114 */
115 int pos();
116
117 /**
118 * Return the last character position of the previous token.
119 */
120 int prevEndPos();
121
122 /**
123 * Return the radix of a numeric literal token.
124 */
125 int radix();
126
127 /**
128 * The value of a literal token, recorded as a string.
129 * For integers, leading 0x and 'l' suffixes are suppressed.
130 */
131 String stringVal();
132
133 /**
134 * Return the current token, set by nextToken().
135 */
136 Token token();
137
138 /**
139 * Sets the current token.
140 */
141 void token(Token token);
142 }