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