langtools/src/share/classes/com/sun/tools/javac/parser/Scanner.java
author xdono
Wed, 02 Jul 2008 12:56:02 -0700
changeset 735 372aa565a221
parent 731 1dd22bdb9ca5
child 1260 a772ba9ba43d
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
735
372aa565a221 6719955: Update copyright year
xdono
parents: 731
diff changeset
     2
 * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.parser;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.nio.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
731
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 10
diff changeset
    30
import com.sun.tools.javac.code.Source;
1dd22bdb9ca5 6714364: refactor javac File handling code into new javac.file package
jjg
parents: 10
diff changeset
    31
import com.sun.tools.javac.file.JavacFileManager;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import static com.sun.tools.javac.parser.Token.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import static com.sun.tools.javac.util.LayoutCharacters.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
/** The lexical analyzer maps an input stream consisting of
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *  ASCII characters and Unicode escapes into a token sequence.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  you write code that depends on this, you do so at your own risk.
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
public class Scanner implements Lexer {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    private static boolean scannerDebug = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    /** A factory for creating scanners. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    public static class Factory {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        /** The context key for the scanner factory. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
        public static final Context.Key<Scanner.Factory> scannerFactoryKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
            new Context.Key<Scanner.Factory>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
        /** Get the Factory instance for this context. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        public static Factory instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
            Factory instance = context.get(scannerFactoryKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
            if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
                instance = new Factory(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
            return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        final Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
        final Name.Table names;
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        final Source source;
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        final Keywords keywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        /** Create a new scanner factory. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
        protected Factory(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
            context.put(scannerFactoryKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
            this.log = Log.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
            this.names = Name.Table.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
            this.source = Source.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
            this.keywords = Keywords.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        public Scanner newScanner(CharSequence input) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
            if (input instanceof CharBuffer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
                return new Scanner(this, (CharBuffer)input);
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
                char[] array = input.toString().toCharArray();
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
                return newScanner(array, array.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        public Scanner newScanner(char[] input, int inputLength) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
            return new Scanner(this, input, inputLength);
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /* Output variables; set by nextToken():
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /** The token, set by nextToken().
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    private Token token;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    /** Allow hex floating-point literals.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    private boolean allowHexFloats;
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    /** The token's position, 0-based offset from beginning of text.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    private int pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    /** Character position just after the last character of the token.
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    private int endPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    /** The last character position of the previous token.
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    private int prevEndPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    /** The position where a lexical error occurred;
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    private int errPos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    /** The name of an identifier or token:
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    private Name name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    /** The radix of a numeric literal token.
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    private int radix;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    /** Has a @deprecated been encountered in last doc comment?
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     *  this needs to be reset by client.
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    protected boolean deprecatedFlag = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    /** A character buffer for literals.
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    private char[] sbuf = new char[128];
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    private int sp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    /** The input buffer, index of next chacter to be read,
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     *  index of one past last character in buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    private char[] buf;
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    private int bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    private int buflen;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    private int eofPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    /** The current character.
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    private char ch;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    /** The buffer index of the last converted unicode character
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    private int unicodeConversionBp = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    /** The log to be used for error reporting.
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    private final Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    /** The name table. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    private final Name.Table names;
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    /** The keyword table. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    private final Keywords keywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    /** Common code for constructors. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    private Scanner(Factory fac) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
        this.log = fac.log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        this.names = fac.names;
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        this.keywords = fac.keywords;
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        this.allowHexFloats = fac.source.allowHexFloats();
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    private static final boolean hexFloatsWork = hexFloatsWork();
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    private static boolean hexFloatsWork() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
            Float.valueOf("0x1.0p1");
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        } catch (NumberFormatException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    /** Create a scanner from the input buffer.  buffer must implement
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     *  array() and compact(), and remaining() must be less than limit().
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    protected Scanner(Factory fac, CharBuffer buffer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        this(fac, JavacFileManager.toArray(buffer), buffer.limit());
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * Create a scanner from the input array.  This method might
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * modify the array.  To avoid copying the input array, ensure
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     * that {@code inputLength < input.length} or
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     * {@code input[input.length -1]} is a white space character.
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     * @param fac the factory which created this Scanner
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     * @param input the input, might be modified
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     * @param inputLength the size of the input.
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     * Must be positive and less than or equal to input.length.
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    protected Scanner(Factory fac, char[] input, int inputLength) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        this(fac);
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        eofPos = inputLength;
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        if (inputLength == input.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            if (input.length > 0 && Character.isWhitespace(input[input.length - 1])) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
                inputLength--;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
                char[] newInput = new char[inputLength + 1];
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
                System.arraycopy(input, 0, newInput, 0, input.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
                input = newInput;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        buf = input;
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        buflen = inputLength;
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        buf[buflen] = EOI;
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        bp = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    /** Report an error at the given position using the provided arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    private void lexError(int pos, String key, Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        log.error(pos, key, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        token = ERROR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        errPos = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    /** Report an error at the current token position using the provided
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     *  arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    private void lexError(String key, Object... args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        lexError(pos, key, args);
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    /** Convert an ASCII digit from its base (8, 10, or 16)
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
     *  to its value.
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    private int digit(int base) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        char c = ch;
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        int result = Character.digit(c, base);
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        if (result >= 0 && c > 0x7f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            lexError(pos+1, "illegal.nonascii.digit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            ch = "0123456789abcdef".charAt(result);
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    /** Convert unicode escape; bp points to initial '\' character
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     *  (Spec 3.3).
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    private void convertUnicode() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        if (ch == '\\' && unicodeConversionBp != bp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            bp++; ch = buf[bp];
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
            if (ch == 'u') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
                do {
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
                    bp++; ch = buf[bp];
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
                } while (ch == 'u');
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
                int limit = bp + 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
                if (limit < buflen) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
                    int d = digit(16);
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                    int code = d;
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                    while (bp < limit && d >= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                        bp++; ch = buf[bp];
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                        d = digit(16);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                        code = (code << 4) + d;
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
                    if (d >= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
                        ch = (char)code;
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
                        unicodeConversionBp = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
                lexError(bp, "illegal.unicode.esc");
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
                bp--;
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
                ch = '\\';
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    /** Read next character.
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
    private void scanChar() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        ch = buf[++bp];
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        if (ch == '\\') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            convertUnicode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    /** Read next character in comment, skipping over double '\' characters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
    private void scanCommentChar() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        if (ch == '\\') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
            if (buf[bp+1] == '\\' && unicodeConversionBp != bp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
                bp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
                convertUnicode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
    /** Append a character to sbuf.
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
    private void putChar(char ch) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        if (sp == sbuf.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            char[] newsbuf = new char[sbuf.length * 2];
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            System.arraycopy(sbuf, 0, newsbuf, 0, sbuf.length);
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
            sbuf = newsbuf;
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        sbuf[sp++] = ch;
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
    /** For debugging purposes: print character.
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    private void dch() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        System.err.print(ch); System.out.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    /** Read next character in character or string literal and copy into sbuf.
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    private void scanLitChar() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        if (ch == '\\') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
            if (buf[bp+1] == '\\' && unicodeConversionBp != bp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
                bp++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
                putChar('\\');
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
                scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
                scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
                switch (ch) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
                case '0': case '1': case '2': case '3':
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                case '4': case '5': case '6': case '7':
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
                    char leadch = ch;
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
                    int oct = digit(8);
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
                    scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
                    if ('0' <= ch && ch <= '7') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
                        oct = oct * 8 + digit(8);
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
                        scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
                        if (leadch <= '3' && '0' <= ch && ch <= '7') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                            oct = oct * 8 + digit(8);
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
                            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
                    putChar((char)oct);
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                case 'b':
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                    putChar('\b'); scanChar(); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
                case 't':
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
                    putChar('\t'); scanChar(); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
                case 'n':
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
                    putChar('\n'); scanChar(); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
                case 'f':
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
                    putChar('\f'); scanChar(); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
                case 'r':
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
                    putChar('\r'); scanChar(); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
                case '\'':
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
                    putChar('\''); scanChar(); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
                case '\"':
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
                    putChar('\"'); scanChar(); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                case '\\':
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                    putChar('\\'); scanChar(); break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                    lexError(bp, "illegal.esc.char");
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        } else if (bp != buflen) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            putChar(ch); scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
    /** Read fractional part of hexadecimal floating point number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
    private void scanHexExponentAndSuffix() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        if (ch == 'p' || ch == 'P') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
            putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
            if (ch == '+' || ch == '-') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
                putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
                scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
            if ('0' <= ch && ch <= '9') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
                do {
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
                    putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
                    scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
                } while ('0' <= ch && ch <= '9');
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
                if (!allowHexFloats) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
                    lexError("unsupported.fp.lit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
                    allowHexFloats = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
                else if (!hexFloatsWork)
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
                    lexError("unsupported.cross.fp.lit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
            } else
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
                lexError("malformed.fp.lit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
            lexError("malformed.fp.lit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        if (ch == 'f' || ch == 'F') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
            putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
            token = FLOATLITERAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
            if (ch == 'd' || ch == 'D') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
                putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
                scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
            token = DOUBLELITERAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
    /** Read fractional part of floating point number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
    private void scanFraction() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        while (digit(10) >= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
            putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
        int sp1 = sp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        if (ch == 'e' || ch == 'E') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
            putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
            if (ch == '+' || ch == '-') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
                putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
                scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
            if ('0' <= ch && ch <= '9') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
                do {
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
                    putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
                    scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
                } while ('0' <= ch && ch <= '9');
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
            lexError("malformed.fp.lit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
            sp = sp1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
    /** Read fractional part and 'd' or 'f' suffix of floating point number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
    private void scanFractionAndSuffix() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
        this.radix = 10;
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
        scanFraction();
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        if (ch == 'f' || ch == 'F') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
            putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
            token = FLOATLITERAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
            if (ch == 'd' || ch == 'D') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
                putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
                scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
            token = DOUBLELITERAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
    /** Read fractional part and 'd' or 'f' suffix of floating point number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
    private void scanHexFractionAndSuffix(boolean seendigit) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
        this.radix = 16;
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
        assert ch == '.';
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
        putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
        scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        while (digit(16) >= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
            seendigit = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
            putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
        if (!seendigit)
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
            lexError("invalid.hex.number");
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
            scanHexExponentAndSuffix();
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
    /** Read a number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
     *  @param radix  The radix of the number; one of 8, 10, 16.
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
    private void scanNumber(int radix) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
        this.radix = radix;
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
        // for octal, allow base-10 digit in case it's a float literal
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
        int digitRadix = (radix <= 10) ? 10 : 16;
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        boolean seendigit = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        while (digit(digitRadix) >= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
            seendigit = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
            putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        if (radix == 16 && ch == '.') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
            scanHexFractionAndSuffix(seendigit);
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
        } else if (seendigit && radix == 16 && (ch == 'p' || ch == 'P')) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
            scanHexExponentAndSuffix();
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
        } else if (radix <= 10 && ch == '.') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
            putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
            scanFractionAndSuffix();
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        } else if (radix <= 10 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
                   (ch == 'e' || ch == 'E' ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
                    ch == 'f' || ch == 'F' ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
                    ch == 'd' || ch == 'D')) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
            scanFractionAndSuffix();
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
            if (ch == 'l' || ch == 'L') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
                scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
                token = LONGLITERAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
                token = INTLITERAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
    /** Read an identifier.
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
    private void scanIdent() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
        boolean isJavaIdentifierPart;
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
        char high;
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
        do {
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
            if (sp == sbuf.length) putChar(ch); else sbuf[sp++] = ch;
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
            // optimization, was: putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
            switch (ch) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
            case 'A': case 'B': case 'C': case 'D': case 'E':
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
            case 'F': case 'G': case 'H': case 'I': case 'J':
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
            case 'K': case 'L': case 'M': case 'N': case 'O':
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
            case 'P': case 'Q': case 'R': case 'S': case 'T':
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
            case 'U': case 'V': case 'W': case 'X': case 'Y':
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
            case 'Z':
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
            case 'a': case 'b': case 'c': case 'd': case 'e':
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            case 'f': case 'g': case 'h': case 'i': case 'j':
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
            case 'k': case 'l': case 'm': case 'n': case 'o':
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
            case 'p': case 'q': case 'r': case 's': case 't':
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
            case 'u': case 'v': case 'w': case 'x': case 'y':
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
            case 'z':
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
            case '$': case '_':
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
            case '0': case '1': case '2': case '3': case '4':
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
            case '5': case '6': case '7': case '8': case '9':
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
            case '\u0000': case '\u0001': case '\u0002': case '\u0003':
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
            case '\u0004': case '\u0005': case '\u0006': case '\u0007':
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
            case '\u0008': case '\u000E': case '\u000F': case '\u0010':
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            case '\u0011': case '\u0012': case '\u0013': case '\u0014':
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
            case '\u0015': case '\u0016': case '\u0017':
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
            case '\u0018': case '\u0019': case '\u001B':
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
            case '\u007F':
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
            case '\u001A': // EOI is also a legal identifier part
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
                if (bp >= buflen) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
                    name = names.fromChars(sbuf, 0, sp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
                    token = keywords.key(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
                if (ch < '\u0080') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
                    // all ASCII range chars already handled, above
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
                    isJavaIdentifierPart = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
                    high = scanSurrogates();
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
                    if (high != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
                        if (sp == sbuf.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
                            putChar(high);
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
                        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
                            sbuf[sp++] = high;
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
                        isJavaIdentifierPart = Character.isJavaIdentifierPart(
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
                            Character.toCodePoint(high, ch));
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
                        isJavaIdentifierPart = Character.isJavaIdentifierPart(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
                if (!isJavaIdentifierPart) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
                    name = names.fromChars(sbuf, 0, sp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
                    token = keywords.key(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
        } while (true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
    /** Are surrogates supported?
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
    final static boolean surrogatesSupported = surrogatesSupported();
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
    private static boolean surrogatesSupported() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
            Character.isHighSurrogate('a');
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
        } catch (NoSuchMethodError ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
    /** Scan surrogate pairs.  If 'ch' is a high surrogate and
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
     *  the next character is a low surrogate, then put the low
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
     *  surrogate in 'ch', and return the high surrogate.
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
     *  otherwise, just return 0.
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
    private char scanSurrogates() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
        if (surrogatesSupported && Character.isHighSurrogate(ch)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
            char high = ch;
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
            if (Character.isLowSurrogate(ch)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
                return high;
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
            ch = high;
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
        return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
    /** Return true if ch can be part of an operator.
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
    private boolean isSpecial(char ch) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
        switch (ch) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
        case '!': case '%': case '&': case '*': case '?':
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
        case '+': case '-': case ':': case '<': case '=':
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
        case '>': case '^': case '|': case '~':
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
        case '@':
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
    /** Read longest possible sequence of special characters and convert
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
     *  to token.
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
    private void scanOperator() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
        while (true) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
            putChar(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
            Name newname = names.fromChars(sbuf, 0, sp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
            if (keywords.key(newname) == IDENTIFIER) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
                sp--;
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
            name = newname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
            token = keywords.key(newname);
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
            if (!isSpecial(ch)) break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
     * Scan a documention comment; determine if a deprecated tag is present.
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
     * Called once the initial /, * have been skipped, positioned at the second *
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
     * (which is treated as the beginning of the first line).
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
     * Stops positioned at the closing '/'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
    @SuppressWarnings("fallthrough")
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
    private void scanDocComment() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
        boolean deprecatedPrefix = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
        forEachLine:
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
        while (bp < buflen) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
            // Skip optional WhiteSpace at beginning of line
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
            while (bp < buflen && (ch == ' ' || ch == '\t' || ch == FF)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
                scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
            // Skip optional consecutive Stars
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
            while (bp < buflen && ch == '*') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
                scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
                if (ch == '/') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
            // Skip optional WhiteSpace after Stars
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
            while (bp < buflen && (ch == ' ' || ch == '\t' || ch == FF)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
                scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
            deprecatedPrefix = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
            // At beginning of line in the JavaDoc sense.
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
            if (bp < buflen && ch == '@' && !deprecatedFlag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
                scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
                if (bp < buflen && ch == 'd') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
                    scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
                    if (bp < buflen && ch == 'e') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
                        scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
                        if (bp < buflen && ch == 'p') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
                            scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
                            if (bp < buflen && ch == 'r') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
                                scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
                                if (bp < buflen && ch == 'e') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
                                    scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
                                    if (bp < buflen && ch == 'c') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
                                        scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
                                        if (bp < buflen && ch == 'a') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
                                            scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
                                            if (bp < buflen && ch == 't') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
                                                scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
                                                if (bp < buflen && ch == 'e') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
                                                    scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
                                                    if (bp < buflen && ch == 'd') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
                                                        deprecatedPrefix = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
                                                        scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
                                                    }}}}}}}}}}}
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
            if (deprecatedPrefix && bp < buflen) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
                if (Character.isWhitespace(ch)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
                    deprecatedFlag = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
                } else if (ch == '*') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
                    scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
                    if (ch == '/') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
                        deprecatedFlag = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
            // Skip rest of line
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
            while (bp < buflen) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
                switch (ch) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
                case '*':
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
                    scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
                    if (ch == '/') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
                case CR: // (Spec 3.4)
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
                    scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
                    if (ch != LF) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
                        continue forEachLine;
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
                    /* fall through to LF case */
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
                case LF: // (Spec 3.4)
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
                    scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
                    continue forEachLine;
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
                    scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
            } // rest of line
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
        } // forEachLine
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
    /** The value of a literal token, recorded as a string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
     *  For integers, leading 0x and 'l' suffixes are suppressed.
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
    public String stringVal() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
        return new String(sbuf, 0, sp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
    /** Read token.
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
    public void nextToken() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
            prevEndPos = endPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
            sp = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
            while (true) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
                pos = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
                switch (ch) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
                case ' ': // (Spec 3.6)
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
                case '\t': // (Spec 3.6)
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
                case FF: // (Spec 3.6)
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
                    do {
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
                        scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
                    } while (ch == ' ' || ch == '\t' || ch == FF);
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
                    endPos = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
                    processWhiteSpace();
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
                case LF: // (Spec 3.4)
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
                    scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
                    endPos = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
                    processLineTerminator();
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
                case CR: // (Spec 3.4)
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
                    scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
                    if (ch == LF) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
                        scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
                    endPos = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
                    processLineTerminator();
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
                case 'A': case 'B': case 'C': case 'D': case 'E':
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
                case 'F': case 'G': case 'H': case 'I': case 'J':
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
                case 'K': case 'L': case 'M': case 'N': case 'O':
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
                case 'P': case 'Q': case 'R': case 'S': case 'T':
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
                case 'U': case 'V': case 'W': case 'X': case 'Y':
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
                case 'Z':
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
                case 'a': case 'b': case 'c': case 'd': case 'e':
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
                case 'f': case 'g': case 'h': case 'i': case 'j':
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
                case 'k': case 'l': case 'm': case 'n': case 'o':
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
                case 'p': case 'q': case 'r': case 's': case 't':
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
                case 'u': case 'v': case 'w': case 'x': case 'y':
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
                case 'z':
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
                case '$': case '_':
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
                    scanIdent();
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
                case '0':
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
                    scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
                    if (ch == 'x' || ch == 'X') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
                        scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
                        if (ch == '.') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
                            scanHexFractionAndSuffix(false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
                        } else if (digit(16) < 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
                            lexError("invalid.hex.number");
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
                        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
                            scanNumber(16);
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
                        putChar('0');
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
                        scanNumber(8);
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
                case '1': case '2': case '3': case '4':
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
                case '5': case '6': case '7': case '8': case '9':
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
                    scanNumber(10);
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
                case '.':
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
                    scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
                    if ('0' <= ch && ch <= '9') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
                        putChar('.');
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
                        scanFractionAndSuffix();
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
                    } else if (ch == '.') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
                        putChar('.'); putChar('.');
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
                        scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
                        if (ch == '.') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
                            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
                            putChar('.');
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
                            token = ELLIPSIS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
                        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
                            lexError("malformed.fp.lit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
                        token = DOT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
                case ',':
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
                    scanChar(); token = COMMA; return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
                case ';':
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
                    scanChar(); token = SEMI; return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
                case '(':
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
                    scanChar(); token = LPAREN; return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
                case ')':
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
                    scanChar(); token = RPAREN; return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
                case '[':
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
                    scanChar(); token = LBRACKET; return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
                case ']':
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
                    scanChar(); token = RBRACKET; return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
                case '{':
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
                    scanChar(); token = LBRACE; return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
                case '}':
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
                    scanChar(); token = RBRACE; return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
                case '/':
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
                    scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
                    if (ch == '/') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
                        do {
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
                            scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
                        } while (ch != CR && ch != LF && bp < buflen);
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
                        if (bp < buflen) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
                            endPos = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
                            processComment(CommentStyle.LINE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
                    } else if (ch == '*') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
                        scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
                        CommentStyle style;
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
                        if (ch == '*') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
                            style = CommentStyle.JAVADOC;
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
                            scanDocComment();
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
                        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
                            style = CommentStyle.BLOCK;
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
                            while (bp < buflen) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
                                if (ch == '*') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
                                    scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
                                    if (ch == '/') break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
                                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
                                    scanCommentChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
                                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
                        if (ch == '/') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
                            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
                            endPos = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
                            processComment(style);
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
                            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
                        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
                            lexError("unclosed.comment");
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
                            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
                    } else if (ch == '=') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
                        name = names.slashequals;
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
                        token = SLASHEQ;
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
                        scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   887
                        name = names.slash;
06bc494ca11e Initial load
duke
parents:
diff changeset
   888
                        token = SLASH;
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
                case '\'':
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
                    scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
                    if (ch == '\'') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
                        lexError("empty.char.lit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
                        if (ch == CR || ch == LF)
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
                            lexError(pos, "illegal.line.end.in.char.lit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
                        scanLitChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
                        if (ch == '\'') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
                            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
                            token = CHARLITERAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
                        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
                            lexError(pos, "unclosed.char.lit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
                case '\"':
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
                    scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
                    while (ch != '\"' && ch != CR && ch != LF && bp < buflen)
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
                        scanLitChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
                    if (ch == '\"') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
                        token = STRINGLITERAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
                        scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
                        lexError(pos, "unclosed.str.lit");
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
                    if (isSpecial(ch)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
                        scanOperator();
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
                        boolean isJavaIdentifierStart;
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
                        if (ch < '\u0080') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
                            // all ASCII range chars already handled, above
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
                            isJavaIdentifierStart = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
                        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
                            char high = scanSurrogates();
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
                            if (high != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
                                if (sp == sbuf.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
                                    putChar(high);
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
                                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
                                    sbuf[sp++] = high;
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
                                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
                                isJavaIdentifierStart = Character.isJavaIdentifierStart(
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
                                    Character.toCodePoint(high, ch));
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
                            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
                                isJavaIdentifierStart = Character.isJavaIdentifierStart(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
                        if (isJavaIdentifierStart) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
                            scanIdent();
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
                        } else if (bp == buflen || ch == EOI && bp+1 == buflen) { // JLS 3.5
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
                            token = EOF;
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
                            pos = bp = eofPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
                        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
                            lexError("illegal.char", String.valueOf((int)ch));
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
                            scanChar();
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
        } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
            endPos = bp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
            if (scannerDebug)
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
                System.out.println("nextToken(" + pos
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
                                   + "," + endPos + ")=|" +
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
                                   new String(getRawCharacters(pos, endPos))
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
                                   + "|");
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
    /** Return the current token, set by nextToken().
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
    public Token token() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
        return token;
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
    /** Sets the current token.
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
    public void token(Token token) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
        this.token = token;
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
    /** Return the current token's position: a 0-based
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
     *  offset from beginning of the raw input stream
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
     *  (before unicode translation)
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
    public int pos() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
        return pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
    /** Return the last character position of the current token.
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
    public int endPos() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
        return endPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
    /** Return the last character position of the previous token.
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
    public int prevEndPos() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
        return prevEndPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
06bc494ca11e Initial load
duke
parents:
diff changeset
   996
    /** Return the position where a lexical error occurred;
06bc494ca11e Initial load
duke
parents:
diff changeset
   997
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
    public int errPos() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
        return errPos;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
    /** Set the position where a lexical error occurred;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
    public void errPos(int pos) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
        errPos = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
    /** Return the name of an identifier or token for the current token.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
    public Name name() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
        return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
    /** Return the radix of a numeric literal token.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
    public int radix() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
        return radix;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
    /** Has a @deprecated been encountered in last doc comment?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
     *  This needs to be reset by client with resetDeprecatedFlag.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
    public boolean deprecatedFlag() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
        return deprecatedFlag;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
    public void resetDeprecatedFlag() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
        deprecatedFlag = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
     * Returns the documentation string of the current token.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
    public String docComment() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
     * Returns a copy of the input buffer, up to its inputLength.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
     * Unicode escape sequences are not translated.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
    public char[] getRawCharacters() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
        char[] chars = new char[buflen];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
        System.arraycopy(buf, 0, chars, 0, buflen);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
        return chars;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
     * Returns a copy of a character array subset of the input buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
     * The returned array begins at the <code>beginIndex</code> and
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
     * extends to the character at index <code>endIndex - 1</code>.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
     * Thus the length of the substring is <code>endIndex-beginIndex</code>.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
     * This behavior is like
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
     * <code>String.substring(beginIndex, endIndex)</code>.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
     * Unicode escape sequences are not translated.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
     * @param beginIndex the beginning index, inclusive.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
     * @param endIndex the ending index, exclusive.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
     * @throws IndexOutOfBounds if either offset is outside of the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
     *         array bounds
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
    public char[] getRawCharacters(int beginIndex, int endIndex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
        int length = endIndex - beginIndex;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
        char[] chars = new char[length];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
        System.arraycopy(buf, beginIndex, chars, 0, length);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
        return chars;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
    public enum CommentStyle {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
        LINE,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
        BLOCK,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
        JAVADOC,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
     * Called when a complete comment has been scanned. pos and endPos
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
     * will mark the comment boundary.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1078
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
    protected void processComment(CommentStyle style) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
        if (scannerDebug)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
            System.out.println("processComment(" + pos
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
                               + "," + endPos + "," + style + ")=|"
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
                               + new String(getRawCharacters(pos, endPos))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
                               + "|");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
     * Called when a complete whitespace run has been scanned. pos and endPos
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
     * will mark the whitespace boundary.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
    protected void processWhiteSpace() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
        if (scannerDebug)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
            System.out.println("processWhitespace(" + pos
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
                               + "," + endPos + ")=|" +
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
                               new String(getRawCharacters(pos, endPos))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
                               + "|");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
     * Called when a line terminator has been processed.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
    protected void processLineTerminator() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
        if (scannerDebug)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
            System.out.println("processTerminator(" + pos
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
                               + "," + endPos + ")=|" +
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
                               new String(getRawCharacters(pos, endPos))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
                               + "|");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
    /** Build a map for translating between line numbers and
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
     * positions in the input.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
     * @return a LineMap */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
    public Position.LineMap getLineMap() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
        return Position.makeLineMap(buf, buflen, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
}