src/jdk/nashorn/internal/parser/TokenType.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.parser;
  27 

  28 import static jdk.nashorn.internal.parser.TokenKind.BINARY;
  29 import static jdk.nashorn.internal.parser.TokenKind.BRACKET;
  30 import static jdk.nashorn.internal.parser.TokenKind.FUTURE;
  31 import static jdk.nashorn.internal.parser.TokenKind.FUTURESTRICT;
  32 import static jdk.nashorn.internal.parser.TokenKind.IR;
  33 import static jdk.nashorn.internal.parser.TokenKind.KEYWORD;
  34 import static jdk.nashorn.internal.parser.TokenKind.LITERAL;
  35 import static jdk.nashorn.internal.parser.TokenKind.SPECIAL;
  36 import static jdk.nashorn.internal.parser.TokenKind.UNARY;
  37 
  38 /**
  39  * Description of all the JavaScript tokens.
  40  */
  41 @SuppressWarnings("javadoc")
  42 public enum TokenType {
  43     ERROR          (SPECIAL,  null),
  44     EOF            (SPECIAL,  null),
  45     EOL            (SPECIAL,  null),
  46 
  47     NOT            (UNARY,   "!",    14, false),


 232      * @param noIn TRUE if IN operator should be ignored.
 233      * @return TRUE if valid operator.
 234      */
 235     public boolean isOperator(final boolean noIn) {
 236         return kind == BINARY && (!noIn || this != IN) && precedence != 0;
 237     }
 238 
 239     /**
 240      * Accessors.
 241      */
 242     public int getLength() {
 243         assert name != null : "Token name not set";
 244         return name.length();
 245     }
 246 
 247     public String getName() {
 248         return name;
 249     }
 250 
 251     public String getNameOrType() {
 252         return name == null ? super.name().toLowerCase() : name;
 253     }
 254 
 255     public TokenType getNext() {
 256         return next;
 257     }
 258 
 259     public void setNext(final TokenType next) {
 260         this.next = next;
 261     }
 262 
 263     public TokenKind getKind() {
 264         return kind;
 265     }
 266 
 267     public int getPrecedence() {
 268         return precedence;
 269     }
 270 
 271     public boolean isLeftAssociative() {
 272         return isLeftAssociative;


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.nashorn.internal.parser;
  27 
  28 import java.util.Locale;
  29 import static jdk.nashorn.internal.parser.TokenKind.BINARY;
  30 import static jdk.nashorn.internal.parser.TokenKind.BRACKET;
  31 import static jdk.nashorn.internal.parser.TokenKind.FUTURE;
  32 import static jdk.nashorn.internal.parser.TokenKind.FUTURESTRICT;
  33 import static jdk.nashorn.internal.parser.TokenKind.IR;
  34 import static jdk.nashorn.internal.parser.TokenKind.KEYWORD;
  35 import static jdk.nashorn.internal.parser.TokenKind.LITERAL;
  36 import static jdk.nashorn.internal.parser.TokenKind.SPECIAL;
  37 import static jdk.nashorn.internal.parser.TokenKind.UNARY;
  38 
  39 /**
  40  * Description of all the JavaScript tokens.
  41  */
  42 @SuppressWarnings("javadoc")
  43 public enum TokenType {
  44     ERROR          (SPECIAL,  null),
  45     EOF            (SPECIAL,  null),
  46     EOL            (SPECIAL,  null),
  47 
  48     NOT            (UNARY,   "!",    14, false),


 233      * @param noIn TRUE if IN operator should be ignored.
 234      * @return TRUE if valid operator.
 235      */
 236     public boolean isOperator(final boolean noIn) {
 237         return kind == BINARY && (!noIn || this != IN) && precedence != 0;
 238     }
 239 
 240     /**
 241      * Accessors.
 242      */
 243     public int getLength() {
 244         assert name != null : "Token name not set";
 245         return name.length();
 246     }
 247 
 248     public String getName() {
 249         return name;
 250     }
 251 
 252     public String getNameOrType() {
 253         return name == null ? super.name().toLowerCase(Locale.ENGLISH) : name;
 254     }
 255 
 256     public TokenType getNext() {
 257         return next;
 258     }
 259 
 260     public void setNext(final TokenType next) {
 261         this.next = next;
 262     }
 263 
 264     public TokenKind getKind() {
 265         return kind;
 266     }
 267 
 268     public int getPrecedence() {
 269         return precedence;
 270     }
 271 
 272     public boolean isLeftAssociative() {
 273         return isLeftAssociative;