Scanner.java revision 673
553N/A * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 553N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 553N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 553N/A * or visit www.oracle.com if you need additional information or have any 0N/A/** The lexical analyzer maps an input stream consisting of 0N/A * ASCII characters and Unicode escapes into a token sequence. 580N/A * <p><b>This is NOT part of any supported API. 580N/A * If you write code that depends on this, you do so at your own risk. 0N/A * This code and its internal interfaces are subject to change or 0N/A * deletion without notice.</b> 0N/A /** A factory for creating scanners. */ 0N/A /** The context key for the scanner factory. */ 0N/A /** Get the Factory instance for this context. */ 0N/A /** Create a new scanner factory. */ 0N/A /* Output variables; set by nextToken(): 0N/A /** The token, set by nextToken(). 0N/A /** Allow hex floating-point literals. 408N/A /** Allow binary literals. 408N/A /** Allow underscores in literals. 673N/A /** Allow exotic identifiers. 408N/A /** The source language setting. 0N/A /** The token's position, 0-based offset from beginning of text. 0N/A /** Character position just after the last character of the token. 0N/A /** The last character position of the previous token. 0N/A /** The position where a lexical error occurred; 0N/A /** The name of an identifier or token: 0N/A /** The radix of a numeric literal token. 0N/A /** Has a @deprecated been encountered in last doc comment? 0N/A * this needs to be reset by client. 0N/A /** A character buffer for literals. 0N/A private char[]
sbuf =
new char[
128];
0N/A /** The input buffer, index of next chacter to be read, 0N/A * index of one past last character in buffer. 0N/A /** The current character. 0N/A /** The buffer index of the last converted unicode character 0N/A /** The log to be used for error reporting. 0N/A /** The name table. */ 0N/A /** The keyword table. */ 0N/A /** Common code for constructors. */ 0N/A /** Create a scanner from the input buffer. buffer must implement 0N/A * array() and compact(), and remaining() must be less than limit(). 0N/A * Create a scanner from the input array. This method might 0N/A * modify the array. To avoid copying the input array, ensure 0N/A * that {@code inputLength < input.length} or 0N/A * {@code input[input.length -1]} is a white space character. 0N/A * @param fac the factory which created this Scanner 0N/A * @param input the input, might be modified 0N/A * @param inputLength the size of the input. 0N/A * Must be positive and less than or equal to input.length. 0N/A /** Report an error at the given position using the provided arguments. 0N/A /** Report an error at the current token position using the provided 0N/A /** Convert an ASCII digit from its base (8, 10, or 16) 0N/A /** Convert unicode escape; bp points to initial '\' character 0N/A /** Read next character. 0N/A /** Read next character in comment, skipping over double '\' characters. 0N/A /** Append a character to sbuf. 0N/A /** For debugging purposes: print character. 0N/A /** Read next character in character or string literal and copy into sbuf. 0N/A case '0':
case '1':
case '2':
case '3':
0N/A case '4':
case '5':
case '6':
case '7':
266N/A case '|':
case ',':
case '?':
case '%':
266N/A case '^':
case '_':
case '{':
case '}':
266N/A case '!':
case '-':
case '=':
266N/A // Accept escape sequences for dangerous bytecode chars. 266N/A // This is illegal in normal Java string or character literals. 266N/A // Note that the escape sequence itself is passed through. 266N/A /** Read next character in an exotic name #"foo" 266N/A // reject any "dangerous" char which is illegal somewhere in the JVM spec 266N/A case '/':
case '.':
case ';':
// illegal everywhere 266N/A case '<':
case '>':
// illegal in methods, dangerous in classes 266N/A case '[':
// illegal in classes 0N/A /** Read fractional part of hexadecimal floating point number. 0N/A /** Read fractional part of floating point number. 0N/A /** Read fractional part and 'd' or 'f' suffix of floating point number. 0N/A /** Read fractional part and 'd' or 'f' suffix of floating point number. 408N/A * @param radix The radix of the number; one of 2, j8, 10, 16. 0N/A // for octal, allow base-10 digit in case it's a float literal 0N/A /** Read an identifier. 0N/A // optimization, was: putChar(ch); 0N/A case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
0N/A case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
0N/A case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
0N/A case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
0N/A case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
0N/A case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
0N/A case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
0N/A case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
0N/A case 'p':
case 'q':
case 'r':
case 's':
case 't':
0N/A case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
0N/A case '0':
case '1':
case '2':
case '3':
case '4':
0N/A case '5':
case '6':
case '7':
case '8':
case '9':
0N/A case '\u0000':
case '\u0001':
case '\u0002':
case '\u0003':
0N/A case '\u0004':
case '\u0005':
case '\u0006':
case '\u0007':
0N/A case '\u0008':
case '\u000E':
case '\u000F':
case '\u0010':
0N/A case '\u0011':
case '\u0012':
case '\u0013':
case '\u0014':
0N/A case '\u0015':
case '\u0016':
case '\u0017':
0N/A case '\u0018':
case '\u0019':
case '\u001B':
0N/A case '\u001A':
// EOI is also a legal identifier part 0N/A // all ASCII range chars already handled, above 0N/A /** Are surrogates supported? 0N/A /** Scan surrogate pairs. If 'ch' is a high surrogate and 0N/A * the next character is a low surrogate, then put the low 0N/A * surrogate in 'ch', and return the high surrogate. 0N/A * otherwise, just return 0. 0N/A /** Return true if ch can be part of an operator. 0N/A case '!':
case '%':
case '&':
case '*':
case '?':
0N/A case '+':
case '-':
case ':':
case '<':
case '=':
0N/A case '>':
case '^':
case '|':
case '~':
0N/A /** Read longest possible sequence of special characters and convert 0N/A * Scan a documention comment; determine if a deprecated tag is present. 0N/A * Called once the initial /, * have been skipped, positioned at the second * 0N/A * (which is treated as the beginning of the first line). 0N/A * Stops positioned at the closing '/'. 0N/A // Skip optional WhiteSpace at beginning of line 0N/A // Skip optional consecutive Stars 0N/A // Skip optional WhiteSpace after Stars 0N/A // At beginning of line in the JavaDoc sense. 0N/A // Skip rest of line 0N/A /* fall through to LF case */ 0N/A /** The value of a literal token, recorded as a string. 0N/A * For integers, leading 0x and 'l' suffixes are suppressed. 0N/A case ' ':
// (Spec 3.6) 0N/A case '\t':
// (Spec 3.6) 0N/A case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
0N/A case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
0N/A case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
0N/A case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
0N/A case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
0N/A case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
0N/A case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
0N/A case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
0N/A case 'p':
case 'q':
case 'r':
case 's':
case 't':
0N/A case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
0N/A case '1':
case '2':
case '3':
case '4':
0N/A case '5':
case '6':
case '7':
case '8':
case '9':
0N/A // all ASCII range chars already handled, above 0N/A /** Return the current token, set by nextToken(). 0N/A /** Sets the current token. 0N/A /** Return the current token's position: a 0-based 0N/A * offset from beginning of the raw input stream 0N/A * (before unicode translation) 0N/A /** Return the last character position of the current token. 0N/A /** Return the last character position of the previous token. 0N/A /** Return the position where a lexical error occurred; 0N/A /** Set the position where a lexical error occurred; 0N/A /** Return the name of an identifier or token for the current token. 0N/A /** Return the radix of a numeric literal token. 0N/A /** Has a @deprecated been encountered in last doc comment? 0N/A * This needs to be reset by client with resetDeprecatedFlag. 0N/A * Returns the documentation string of the current token. 0N/A * Returns a copy of the input buffer, up to its inputLength. 0N/A * Unicode escape sequences are not translated. 0N/A * Returns a copy of a character array subset of the input buffer. 0N/A * The returned array begins at the <code>beginIndex</code> and 0N/A * extends to the character at index <code>endIndex - 1</code>. 0N/A * Thus the length of the substring is <code>endIndex-beginIndex</code>. 0N/A * This behavior is like 0N/A * <code>String.substring(beginIndex, endIndex)</code>. 0N/A * Unicode escape sequences are not translated. 0N/A * @param beginIndex the beginning index, inclusive. 0N/A * @param endIndex the ending index, exclusive. 0N/A * @throws IndexOutOfBounds if either offset is outside of the 0N/A * Called when a complete comment has been scanned. pos and endPos 0N/A * will mark the comment boundary. 0N/A * Called when a complete whitespace run has been scanned. pos and endPos 0N/A * will mark the whitespace boundary. 0N/A * Called when a line terminator has been processed. 0N/A /** Build a map for translating between line numbers and 0N/A * positions in the input. 0N/A * @return a LineMap */