protected Token getTokenFromCode()

in javascript/extractor/src/com/semmle/jcorn/Parser.java [645:756]


  protected Token getTokenFromCode(int code) {
    switch (code) {
        // The interpretation of a dot depends on whether it is followed
        // by a digit or another two dots.
      case 46: // '.'
        return this.readToken_dot();

        // Punctuation tokens.
      case 40:
        ++this.pos;
        return this.finishToken(TokenType.parenL);
      case 41:
        ++this.pos;
        return this.finishToken(TokenType.parenR);
      case 59:
        ++this.pos;
        return this.finishToken(TokenType.semi);
      case 44:
        ++this.pos;
        return this.finishToken(TokenType.comma);
      case 91:
        ++this.pos;
        return this.finishToken(TokenType.bracketL);
      case 93:
        ++this.pos;
        return this.finishToken(TokenType.bracketR);
      case 123:
        ++this.pos;
        return this.finishToken(TokenType.braceL);
      case 125:
        ++this.pos;
        return this.finishToken(TokenType.braceR);
      case 58:
        ++this.pos;
        return this.finishToken(TokenType.colon);
      case 35:
        ++this.pos;
        return this.finishToken(TokenType.pound);
      case 63:
        return this.readToken_question();

      case 96: // '`'
        if (this.options.ecmaVersion() < 6) break;
        ++this.pos;
        return this.finishToken(TokenType.backQuote);

      case 48: // '0'
        int next = charAt(this.pos + 1);
        if (next == 120 || next == 88) return this.readRadixNumber(16); // '0x', '0X' - hex number
        if (this.options.ecmaVersion() >= 6) {
          if (next == 111 || next == 79)
            return this.readRadixNumber(8); // '0o', '0O' - octal number
          if (next == 98 || next == 66)
            return this.readRadixNumber(2); // '0b', '0B' - binary number
        }
        // Anything else beginning with a digit is an integer, octal
        // number, or float.
      case 49:
      case 50:
      case 51:
      case 52:
      case 53:
      case 54:
      case 55:
      case 56:
      case 57: // 1-9
        return this.readNumber(false);

        // Quotes produce strings.
      case 34:
      case 39: // '"', "'"
        return this.readString((char) code);

        // Operators are parsed inline in tiny state machines. '=' (61) is
        // often referred to. `finishOp` simply skips the amount of
        // characters it is given as second argument, and returns a token
        // of the type given by its first argument.

      case 47: // '/'
        return this.readToken_slash();

      case 37:
      case 42: // '%*'
        return this.readToken_mult_modulo_exp(code);

      case 124: // '|'
      case 38: // '&'
        return this.readToken_pipe_amp(code);

      case 94: // '^'
        return this.readToken_caret();

      case 43:
      case 45: // '+-'
        return this.readToken_plus_min(code);

      case 60:
      case 62: // '<>'
        return this.readToken_lt_gt(code);

      case 61:
      case 33: // '=!'
        return this.readToken_eq_excl(code);

      case 126: // '~'
        return this.finishOp(TokenType.prefix, 1);
    }

    String msg = String.format("Unexpected character '%s' (U+%04X)", codePointToString(code), code);
    this.raise(this.pos, msg);
    return null;
  }