1 /**********************************************************************
2 Copyright (c) 2002 IBM Corp. and others.
3 All rights reserved. � This program and the accompanying materials
4 are made available under the terms of the Common Public License v0.5
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v05.html
9 IBM Corporation - initial API and implementation
10 **********************************************************************/
12 package net.sourceforge.phpdt.core.compiler;
15 * Definition of a Java scanner, as returned by the <code>ToolFactory</code>.
16 * The scanner is responsible for tokenizing a given source, providing
17 * information about the nature of the token read, its positions and source
20 * When the scanner has finished tokenizing, it answers an EOF token (<code>
21 * ITerminalSymbols#TokenNameEOF</code>.
23 * When encountering lexical errors, an <code>InvalidInputException</code> is
26 * @see net.sourceforge.phpdt.core.ToolFactory
27 * @see ITerminalSymbols
30 public interface IScanner {
33 * Answers the current identifier source, after unicode escape sequences
34 * have been translated into unicode characters. e.g. if original source was
35 * <code>\\u0061bc</code> then it will answer <code>abc</code>.
37 * @return the current identifier source, after unicode escape sequences
38 * have been translated into unicode characters
40 char[] getCurrentTokenSource();
43 * Answers the starting position of the current token inside the original
44 * source. This position is zero-based and inclusive. It corresponds to the
45 * position of the first character which is part of this token. If this
46 * character was a unicode escape sequence, it points at the first character
49 * @return the starting position of the current token inside the original
52 int getCurrentTokenStartPosition();
55 * Answers the ending position of the current token inside the original
56 * source. This position is zero-based and inclusive. It corresponds to the
57 * position of the last character which is part of this token. If this
58 * character was a unicode escape sequence, it points at the last character
61 * @return the ending position of the current token inside the original
64 int getCurrentTokenEndPosition();
67 * Answers the starting position of a given line number. This line has to
68 * have been encountered already in the tokenization process (i.e. it cannot
69 * be used to compute positions of lines beyond current token). Once the
70 * entire source has been processed, it can be used without any limit. Line
71 * starting positions are zero-based, and start immediately after the
72 * previous line separator (if any).
75 * the given line number
76 * @return the starting position of a given line number
78 int getLineStart(int lineNumber);
81 * Answers the ending position of a given line number. This line has to have
82 * been encountered already in the tokenization process (i.e. it cannot be
83 * used to compute positions of lines beyond current token). Once the entire
84 * source has been processed, it can be used without any limit. Line ending
85 * positions are zero-based, and correspond to the last character of the
86 * line separator (in case multi-character line separators).
89 * the given line number
90 * @return the ending position of a given line number
92 int getLineEnd(int lineNumber);
95 * Answers an array of the ending positions of the lines encountered so far.
96 * Line ending positions are zero-based, and correspond to the last
97 * character of the line separator (in case multi-character line
100 * @return an array of the ending positions of the lines encountered so far
105 * Answers a 1-based line number using the lines which have been encountered
106 * so far. If the position is located beyond the current scanned line, then
107 * the last line number will be answered.
109 * @param charPosition
110 * the given character position
111 * @return a 1-based line number using the lines which have been encountered
114 int getLineNumber(int charPosition);
117 * Read the next token in the source, and answers its ID as specified by
118 * <code>ITerminalSymbols</code>. Note that the actual token ID values
119 * are subject to change if new keywords were added to the language (i.e.
120 * 'assert' keyword in 1.4).
122 * @throws InvalidInputException -
123 * in case a lexical error was detected while reading the
126 int getNextToken() throws InvalidInputException;
129 * Answers the original source being processed (not a copy of it).
131 * @return the original source being processed
136 * Reposition the scanner on some portion of the original source. Once
137 * reaching the given <code>endPosition</code> it will answer EOF tokens (<code>ITerminalSymbols.TokenNameEOF</code>).
139 * @param startPosition
140 * the given start position
142 * the given end position
144 void resetTo(int startPosition, int endPosition);
147 * Set the scanner source to process. By default, the scanner will consider
148 * starting at the beginning of the source until it reaches its end.
153 void setSource(char[] source);