Decode a table info part of a notify tables or notify MPN subscription request.

@param {Array} tokens the table info part of the message already tokenized
@return {Object} the decoded table info
@private
187933
function readTableInfo(tokens, skipSelector) {
	var tableInfo = {};
	tableInfo.winIndex = protocol.decodeInteger(tokens[1]);
	tableInfo.pubModes = protocol.decodePubModes(tokens[3]);
	tableInfo.groupName = protocol.decodeString(tokens[5]);
	tableInfo.schemaName = protocol.decodeString(tokens[7]);
	tableInfo.firstItemIndex = protocol.decodeInteger(tokens[9]);
	tableInfo.lastItemIndex = protocol.decodeInteger(tokens[11]);
	if (!skipSelector)
		tableInfo.selector = protocol.decodeString(tokens[13]);
	return tableInfo;
}
100590
function AuthChallengeMessage(token) {
  var _token = token || new Buffer(0);

  Response.call(this, 0x0E);

  Object.defineProperty(this, 'token', {
    set: function(val) { _token = val; },
    get: function() { return _token; }
  });
}
924758
function (tokens, response) {
            var token = tokens[0].trim();
            var matches = [];
            var replaceRegex = new RegExp('(' + morpheus.Util.escapeRegex(token) + ')', 'i');
            for (var i = 0; i < allActions.length; i++) {
              if (allActions[i].cb) {
                var name = allActions[i].name;
                if (replaceRegex.test(name)) {
                  matches.push({
                    clear: true,
                    value: name,
                    label: '<span style="margin-left: 10px">'
                    + name.replace(replaceRegex, '<b>$1</b>') + '</span>'
                  });
                }
              }
            }
            response(matches);

          }
1352541
public static String getStringFromTokens(final String[] tokens) {
    final StringBuilder sb = new StringBuilder();
    for (final String tok : tokens) {
      sb.append(tok).append(" ");
    }
    return sb.toString().trim();
  }
608911
def decode_id_token(token, client):
    
    keys = get_client_alg_keys(client)
    return JWS().verify_compact(token, keys=keys)
79654
function parse(tokens) {
    var ast = [];

    var current = ast;

    var _line = 0;
    var _char = 0;

    var openCount = 0;
    var closeCount = 0;

    for (var i = 0; i < tokens.length; i++) {
        var token = tokens[i];

        switch (token.type) {
            case TYPES.open:
                // Every time we open a list, we drop into a sub-array
                var child = [];
                child.parent = current;
                current.push(child);
                current = child;
                openCount += 1;
                break;

            case TYPES.open_array:
            case TYPES.quote:
                var child = [];
                var quote = {"'": child };
                child.parent = current;
                current.push(quote);
                current = child;
                openCount += 1;
                break;

            case TYPES.close_array:
            case TYPES.close:
                // If no current, we probably have too many closing parens
                if (!current) _tooManyClosingParensErr(closeCount, openCount);
                // If we close a list, jump back up to the parent list
                current = current.parent;
                closeCount += 1;
                break;

            case TYPES.identifier:
            case TYPES.suffixed_number:
                current.push(token.string);
                break;

            case TYPES.number:
                current.push(Number(token.string));
                break;

            case TYPES.string:
                // We need to strip the quotes off the string entity
                var dequoted = token.string.slice(1).slice(0, token.string.length - 2);
                current.push(dequoted);
                break;

            case TYPES.json:
                try {
                    var deticked = token.string.slice(1).slice(0, token.string.length - 2);
                    current.push(JSON.parse(deticked));
                }
                catch (e) {
                    throw new Error([
                        'Runiq: Couldn\'t parse inlined JSON!',
                        '--- Error occurred at line ' + _line + ', char ' + _char
                    ].join('\n'));
                }
                break;
        }

        // Capture line numbers and columns for future use
        var lines = token.string.split(NEWLINE);
        _line += lines.length - 1;
        if (lines.length > 1) _char = lines[lines.length - 1].length;
        else _char += token.string.length;
    }

    // Raise error if we have a parentheses mismatch
    if (openCount > closeCount) _tooManyOpenParensErr(closeCount, openCount);
    if (openCount < closeCount) _tooManyClosingParensErr(closeCount, openCount);

    // For both safety and to ensure we actually have a JSON-able AST
    return JSON.parse(JSONStableStringify(ast));
}
542537
def encode_notifications(tokens, notifications):
  
  
  fmt = "!BH32sH%ds"
  structify = lambda t, p: struct.pack(fmt % len(p), 0, 32, t, len(p), p)
  binaryify = lambda t: t.decode('hex')
  if type(notifications) is dict and type(tokens) in (str, unicode):
    tokens, notifications = ([tokens], [notifications])
  if type(notifications) is list and type(tokens) is list:
    return ''.join(map(lambda y: structify(*y), ((binaryify(t), json.dumps(p, separators=(',',':'), ensure_ascii=False).encode('utf-8'))
                                    for t, p in zip(tokens, notifications))))
1277621
function decodeToken (tokenStr) {
  if (!tokenStr || tokenStr === '') return null
  try {
    return jwtDecode(tokenStr)
  } catch (error) {
    logger.error({
      description: 'Error decoding token.',
      error, func: 'decodeToken', file: 'token'
    })
    return null
  }
}
703728
function readGetItems(message, tokens) {
	message.userName = protocol.decodeString(tokens[1]);
	message.groupName = protocol.decodeString(tokens[3]);
	message.sessionId = protocol.decodeString(tokens[5]);
}
589586
function encode(decoded, stack) {
    if (!stack) stack = [];

    if (decoded === undefined) return transferableUndefined;
    if (decoded === null) return null;

    var type = typeof(decoded);

    if (type === 'boolean') return decoded;
    if (type === 'string') return decoded;
    if (type === 'function') return { "!$function$!": decoded.toString() };

    if (type === 'number') {
      if (isNaN(decoded)) {
        return transferableNotANumber;
      } else {
        return decoded;
      }
    }

    if (type === 'object') {

      /* Proxy references */
      if (decoded.hasOwnProperty('!$proxyId$!')) {
        return { "!$proxyId$!": decoded['!$proxyId$!'] };
      }

      /* ArrayBuffers, views, dates, regular expressions, ... */
      if (isBufferOrView(decoded)) return encodeBufferOrView(decoded);
      if (decoded instanceof Date) return transferDate(decoded);
      if (decoded instanceof RegExp) return transferRegExp(decoded);

      /* Error object */
      if (decoded instanceof Error) {
        var name = decoded.name || Object.getPrototypeOf(decoded).name;
        var message = decoded.message;
        var stack = decoded.stack;
        var error = {};
        if (name) error.name = name;
        if (message) error.message = message;
        if (stack) error.stack = stack;
        return { "!$error$!": error };
      }

      /* Normal arrays and arrays from arguments calls */
      if ((decoded.hasOwnProperty('callee') && (typeof(decoded.length) === 'number'))
          || Array.isArray(decoded)) {
        return copy(decoded, [], stack, encode);
      }

      /* Other (normal) object */
      return copy(decoded, {}, stack, encode);

    }

    throw new Error("Unable to transfer " + type);
  }
1357620
function getTokensLength(tokens) {
  if (typeof tokens === 'string') {
    return tokens.length;
  }
  return tokens.reduce((acc, token) => {
    return acc + (token.length ? token.length : 0);
  }, 0);
}
827901
def _decode_token_json(token):
    
    header, payload, raw_signatures, signing_inputs = _unpack_token_json(token)
    token = {
        'header': header,
        'payload': payload,
        'signature': [base64url_encode(rs) for rs in raw_signatures]
    }
    return token
886440
public void unsubscribe(ArrayList<Long> tokens){
        if(ws != null) {
            if (ws.isOpen()) {
                ws.sendText(createTickerJsonObject(tokens, mUnSubscribe).toString());
                subscribedTokens.removeAll(tokens);
                for(int i = 0; i < tokens.size(); i++){
                    modeMap.remove(tokens.get(i));
                }
            }
        }
    }
1319450
def decode(self, subtokens):
    """"""
    if isinstance(subtokens, np.ndarray):
      # Note that list(subtokens) converts subtokens to a python list, but the
      # items remain as np.int32. This converts both the array and its items.
      subtokens = subtokens.tolist()

    if not subtokens:
      return ""

    assert isinstance(subtokens, list) and isinstance(subtokens[0], int), (
        "Subtokens argument passed into decode() must be a list of integers.")

    return _unicode_to_native(
        _join_tokens_to_string(self._subtoken_ids_to_tokens(subtokens)))
429203
public static function parseTokens(&$tokens) {
        do {
		    $typeArray = array_shift($tokens);
            if ($typeArray['token'] == "T_WHITESPACE"){
                continue;
            }
            else {
                break;
            }
        }while(true);

        if ($typeArray['token'] != 'T_TYPE') {
			throw new MoufTypeParserException("Invalid type! Expecting a type name. Got '".$typeArray['match']."'");
		}
		
		$type = new TypeDescriptor();
		$type->type = $typeArray['match'];
		
		if (empty($typeArray)) {
			return $type;
		}
		
		do {
			$continue = false;
			$nextToken = array_shift($tokens);
		
			switch ($nextToken['token']) {
				case 'T_ARRAY';
					$continue = true;
					$subType = $type;
					$type = new TypeDescriptor();
					$type->type = 'array';
					$type->subType = $subType;
					break;
				case 'T_END_ARRAY';
                    array_unshift($tokens, $nextToken);
					break;
				case 'T_START_ARRAY';
					$tok1 = self::getNthTokenWithoutWhitespace($tokens, 1);
					if ($tok1['token'] == 'T_COMA') {
						$tok0 = self::getNthTokenWithoutWhitespace($tokens, 0);
						if ($tok0['token'] != 'T_TYPE') {
							throw new MoufTypeParserException("Invalid type! Expecting a type name. Got ".$tokens['match']);
						}
						$type->keyType = $tok0['match'];
						// Let's shift twice, without counting whitespaces:
						while ($tokens[0] != $tok1) {
							array_shift($tokens);
						}
						array_shift($tokens);
						// TODO: with a state machine, we could handle whitespaces in a best way
						// TODO: develop a statemachine!
						while ($tokens[0]['token'] == 'T_WHITESPACE') {
							array_shift($tokens);
						}
						
					}
					$type->subType = TypeDescriptor::parseTokens($tokens);

                    while ($tokens[0]['token'] == 'T_WHITESPACE') {
                        array_shift($tokens);
                    }

                    if ($tokens[0]['token'] != 'T_END_ARRAY'){
                        throw new MoufTypeParserException("Invalid type! Expecting >. Got '".$tokens[0]['match']."'");
                    }

                    array_shift($tokens);

					break;
				case 'T_OR':
					break;
			}
		} while ($continue);
		
		return $type;
	}
491793
static @Nullable LogMonitorSession readSessionFromJWT(String token) {
		try {
			final Jwt jwt = Jwt.decode(token);
			JSONObject payload = jwt.getPayload();

			LogMonitorSession config = new LogMonitorSession();

			// recipients
			JSONArray recipientsJson = payload.optJSONArray("recipients");
			if (recipientsJson != null) {
				String[] recipients = new String[recipientsJson.length()];
				for (int i = 0; i < recipientsJson.length(); ++i) {
					recipients[i] = recipientsJson.optString(i);
				}

				config.emailRecipients = recipients;
			}

			return config;
		} catch (Exception e) {
			ApptentiveLog.e(e, "Exception while parsing access token: '%s'", token);
			logException(e);
			return null;
		}
	}
1241256
protected function parseCreateTable(SQLTokenIterator $tokens)
    {

        $createTableJob = new CreateTableStatement();
        $createTableJob->setIsTemporaryTable(is_int($tokens->isTokenNum(SqlToken::T_TEMPORARY(), TokenIterator::PREVIOUS)));

        # [IF NOT EXISTS]:
        if ($tokens->seekTokenNum(SqlToken::T_IF())) {
            if (!$tokens->seekTokenNum(SqlToken::T_NOT())
            || !$tokens->seekTokenNum(SqlToken::T_EXISTS())) {
                throw new MalformedSqlException("Invalid create-database statement (invalid 'IF NOT EXISTS')!", $tokens);
            }
            $createTableJob->setIfNotExists(true);
        } else {
            $createTableJob->setIfNotExists(false);
        }

        # NAME

        if ($tokens->seekTokenNum(T_STRING)) {
            $createTableJob->setName($tokens->getCurrentTokenString());

        } elseif ($this->valueParser->canParseTokens($tokens)) {
            $createTableJob->setName($this->valueParser->convertSqlToJob($tokens));

        } else {
            throw new MalformedSqlException("Missing name of table to create!", $tokens);
        }


        # COLUMN DEFINITION

        $checkEndParenthesis = $tokens->seekTokenText('(');

        # LIKE other table?
        if ($tokens->seekTokenNum(SqlToken::T_LIKE())) {
            if (!$this->tableParser->canParseTokens($tokens)) {
                throw new MalformedSqlException("Missing valid table-specifier for 'CREATE TABLE LIKE' statement!", $tokens);
            }
            $createTableJob->setLikeTable($this->tableParser->convertSqlToJob($tokens));

        } elseif ($this->selectParser->canParseTokens($tokens)) {
            $createTableJob->setFromSelectStatement($this->selectParser->convertSqlToJob($tokens));

        # normal column definition
        } else {
            do {
                switch(true){

                    # normal column definition
                    case $this->columnDefinitonParser->canParseTokens($tokens):
                        $createTableJob->addColumnDefinition($this->columnDefinitonParser->convertSqlToJob($tokens));
                        break;

                    # [CONSTRAINT [$keyName]] PRIMARY KEY [$keyType] ($column[, $column, ...])
                    case $tokens->seekTokenNum(SqlToken::T_PRIMARY(), TokenIterator::NEXT, [T_STRING, SqlToken::T_CONSTRAINT()]):

                        $indexJob = new IndexPart();
                        $indexJob->setIsPrimary(true);

                        if ($tokens->isTokenNum(SqlToken::T_CONSTRAINT(), TokenIterator::PREVIOUS, [T_STRING])
                        && $tokens->seekTokenNum(T_STRING, TokenIterator::PREVIOUS)) {
                            $indexJob->setContraintSymbol($tokens->getPreviousTokenString());
                            $tokens->seekTokenNum(SqlToken::T_PRIMARY());
                        }

                        $indexJob->setName("PRIMARY");

                        if (!$tokens->seekTokenNum(SqlToken::T_KEY())) {
                            throw new MalformedSqlException("Missing T_KEY for PRIMARY KEY constraint in create-table statement!", $tokens);
                        }

                        # define index type (BTREE, HASH, ...)
                        if ($tokens->seekTokenNum(T_STRING)) {
                            $indexJob->setType(IndexType::factory($tokens->getCurrentTokenString()));
                        } else {
                            $indexJob->setType(IndexType::BTREE());
                        }

                        # columns in index
                        if ($tokens->seekTokenText('(')) {
                            do {
                                if (!$this->columnParser->canParseTokens($tokens)) {
                                    throw new MalformedSqlException("Invalid column in column-list for defining index!", $tokens);
                                }
                                $indexJob->addColumn($this->columnParser->convertSqlToJob($tokens));
                            } while ($tokens->seekTokenText(','));

                            if (!$tokens->seekTokenText(')')) {
                                throw new MalformedSqlException("Missing closing parenthesis at column-list for index!", $tokens);
                            }
                        }

                        $createTableJob->addIndex($indexJob);
                        break;

                    # KEY|INDEX [index_name] [index_type] (index_col_name,...)
                    case $tokens->seekTokenNum(SqlToken::T_INDEX()):
                    case $tokens->seekTokenNUm(SqlToken::T_KEY()):
                        /* @var $indexJob IndexPart */
                        $indexJob = new IndexPart();

                        if ($tokens->seekTokenNum(T_STRING)) {
                            $indexJob->setName($tokens->getCurrentTokenString());
                        } else {
                            $indexJob->setName(null); # first column name is used
                        }

                        # define index type (BTREE, HASH, ...)
                        if ($tokens->seekTokenNum(T_STRING)) {
                            $indexJob->setType(IndexType::factory($tokens->getCurrentTokenString()));
                        } else {
                            $indexJob->setType(IndexType::BTREE());
                        }

                        # columns in index
                        if ($tokens->seekTokenText('(')) {
                            do {
                                if (!$this->columnParser->canParseTokens($tokens)) {
                                    throw new MalformedSqlException("Invalid column in column-list for defining index!", $tokens);
                                }
                                $indexJob->addColumn($this->columnParser->convertSqlToJob($tokens));
                            } while ($tokens->seekTokenText(','));

                            if (!$tokens->seekTokenText(')')) {
                                throw new MalformedSqlException("Missing closing parenthesis at column-list for index!", $tokens);
                            }
                        }

                        $createTableJob->addIndex($indexJob);
                        break;

                    # [CONSTRAINT [symbol]] UNIQUE|FULLTEXT|SPATIAL [INDEX] [index_name] [index_type] (index_col_name,...)
                    case $tokens->seekTokenNum(SqlToken::T_UNIQUE(), TokenIterator::NEXT, [SqlToken::T_CONSTRAINT(), T_STRING]):
                    case $tokens->seekTokenNum(SqlToken::T_FULLTEXT(), TokenIterator::NEXT, [SqlToken::T_CONSTRAINT(), T_STRING]):
                    case $tokens->seekTokenNum(SqlToken::T_SPATIAL(), TokenIterator::NEXT, [SqlToken::T_CONSTRAINT(), T_STRING]):

                        /* @var $indexJob IndexPart */
                        $indexJob = new IndexPart();

                        switch($tokens->getCurrentTokenNumber()){
                            case SqlToken::T_UNIQUE():
                                $indexJob->setIsUnique(true);
                                break;

                            case SqlToken::T_FULLTEXT():
                                $indexJob->setIsFullText(true);
                                break;

                            case SqlToken::T_SPATIAL():
                                $indexJob->setIsSpatial(true);
                                break;
                        }

                        if ($tokens->isTokenNum(SqlToken::T_CONSTRAINT(), TokenIterator::PREVIOUS, [T_STRING])
                        && $tokens->seekTokenNum(T_STRING, TokenIterator::PREVIOUS)) {
                            $indexJob->setContraintSymbol($tokens->getPreviousTokenString());
                            $tokens->seekTokenNum(SqlToken::T_PRIMARY());
                        }

                        $tokens->seekTokenNum(SqlToken::T_KEY());
                        $tokens->seekTokenNum(SqlToken::T_INDEX());

                        if ($tokens->seekTokenNum(T_STRING)) {
                            $indexJob->setName($tokens->getCurrentTokenString());
                        } else {
                            $indexJob->setName(null); # first column name is used
                        }

                        # define index type (BTREE, HASH, ...)
                        if ($tokens->seekTokenNum(T_STRING)) {
                            $indexJob->setType(IndexType::factory($tokens->getCurrentTokenString()));
                        } else {
                            $indexJob->setType(IndexType::BTREE());
                        }

                        # columns in index
                        if ($tokens->seekTokenText('(')) {
                            do {
                                if (!$this->columnParser->canParseTokens($tokens)) {
                                    throw new MalformedSqlException("Invalid column in column-list for defining index!", $tokens);
                                }
                                $indexJob->addColumn($this->columnParser->convertSqlToJob($tokens));
                            } while ($tokens->seekTokenText(','));

                            if (!$tokens->seekTokenText(')')) {
                                throw new MalformedSqlException("Missing closing parenthesis at column-list for index!", $tokens);
                            }
                        }

                        $createTableJob->addIndex($indexJob);
                        break;

                    # [CONSTRAINT [$symbol]] FOREIGN KEY [$name] ($column[, $column, ...]) [$reference]
                    case $tokens->seekTokenNum(SqlToken::T_FOREIGN(), TokenIterator::NEXT, [T_STRING, SqlToken::T_CONSTRAINT()]):
                        /* @var $indexJob IndexPart */
                        $indexJob = new IndexPart();

                        if ($tokens->isTokenNum(SqlToken::T_CONSTRAINT(), TokenIterator::PREVIOUS, [T_STRING])
                        && $tokens->seekTokenNum(T_STRING, TokenIterator::PREVIOUS)) {
                            $indexJob->setContraintSymbol($tokens->getCurrentTokenString());
                            $tokens->seekTokenNum(SqlToken::T_FOREIGN());
                        }

                        if (!$tokens->seekTokenNum(SqlToken::T_KEY())) {
                            throw new MalformedSqlException("Missing T_KEY after T_FOREIGN in constraint-definition!", $tokens);
                        }

                        if ($tokens->seekTokenNum(T_STRING)) {
                            $indexJob->setName($tokens->getCurrentTokenString());
                        } else {
                            $indexJob->setName(null); # first column name is used
                        }

                        # columns in index
                        if ($tokens->seekTokenText('(')) {
                            do {
                                if (!$this->columnParser->canParseTokens($tokens)) {
                                    throw new MalformedSqlException("Invalid column in column-list for defining index!", $tokens);
                                }
                                $indexJob->addColumn($this->columnParser->convertSqlToJob($tokens));
                            } while ($tokens->seekTokenText(','));

                            if (!$tokens->seekTokenText(')')) {
                                throw new MalformedSqlException("Missing closing parenthesis at column-list for index!", $tokens);
                            }
                        }

                        if (!$tokens->seekTokenNum(SqlToken::T_REFERENCES())) {
                            throw new MalformedSqlException("Missing reference-definition in foreign-constraint-definition!", $tokens);
                        }

                        if (!$this->tableParser->canParseTokens($tokens)) {
                            throw new MalformedSqlException("Missing table-definition in foreign-constraint-definition!", $tokens);
                        }
                        $fkTable = $this->tableParser->convertSqlToJob($tokens);

                        # columns in index
                        if ($tokens->seekTokenText('(')) {
                            do {
                                if (!$this->columnParser->canParseTokens($tokens)) {
                                    throw new MalformedSqlException("Invalid column in column-list for defining index!", $tokens);
                                }
                                $fkColumn = $this->columnParser->convertSqlToJob($tokens);
                                $fkColumn = ColumnSpecifier::factory($fkTable.'.'.$fkColumn->getColumn());
                                $indexJob->addForeignKey($fkColumn);
                            } while ($tokens->seekTokenText(','));

                            if (!$tokens->seekTokenText(')')) {
                                throw new MalformedSqlException("Missing closing parenthesis at column-list for index!", $tokens);
                            }
                        }

                        if ($tokens->seekTokenNum(SqlToken::T_MATCH())) {
                            switch(true){
                                case $tokens->seekTokenNum(SqlToken::T_FULL()):
                                    $indexJob->setForeignKeyMatchType(MatchType::FULL());
                                    break;
                                case $tokens->seekTokenNum(SqlToken::T_PARTIAL()):
                                    $indexJob->setForeignKeyMatchType(MatchType::PARTIAL());
                                    break;
                                case $tokens->seekTokenNum(SqlToken::T_SIMPLE()):
                                    $indexJob->setForeignKeyMatchType(MatchType::SIMPLE());
                                    break;
                                default:
                                    throw new MalformedSqlException("Invalid match parameter for foreign key!", $tokens);
                            }
                        }

                        while ($tokens->seekTokenNum(SqlToken::T_ON())) {
                            switch(true){

                                case $tokens->seekTokenNum(SqlToken::T_DELETE()):
                                    switch(true){

                                        case $tokens->seekTokenNum(SqlToken::T_RESTRICT()):
                                            $option = ReferenceOption::RESTRICT();
                                            break;

                                        case $tokens->seekTokenNum(SqlToken::T_CASCADE()):
                                            $option = ReferenceOption::CASCADE();
                                            break;

                                        case $tokens->seekTokenNum(SqlToken::T_SET())
                                          && $tokens->seekTokenNum(SqlToken::T_NULL()):
                                            $option = ReferenceOption::SET_NULL();
                                            break;

                                        case $tokens->seekTokenNum(SqlToken::T_NO())
                                          && $tokens->seekTokenText("ACTION"):
                                            $option = ReferenceOption::NO_ACTION();
                                            break;

                                        default:
                                            throw new MalformedSqlException(
                                                "Invalid reference-option for foreign key ON DELETE option!",
                                                $tokens
                                            );
                                    }
                                    $indexJob->setForeignKeyOnDeleteReferenceOption($option);
                                    break;

                                case $tokens->seekTokenNum(SqlToken::T_UPDATE()):
                                    switch(true){

                                        case $tokens->seekTokenNum(SqlToken::T_RESTRICT()):
                                            $option = ReferenceOption::RESTRICT();
                                            break;

                                        case $tokens->seekTokenNum(SqlToken::T_CASCADE()):
                                            $option = ReferenceOption::CASCADE();
                                            break;

                                        case $tokens->seekTokenNum(SqlToken::T_SET())
                                          && $tokens->seekTokenNum(SqlToken::T_NULL()):
                                            $option = ReferenceOption::SET_NULL();
                                            break;

                                        case $tokens->seekTokenNum(SqlToken::T_NO())
                                          && $tokens->seekTokenText("ACTION"):
                                            $option = ReferenceOption::NO_ACTION();
                                            break;

                                        default:
                                            throw new MalformedSqlException(
                                                "Invalid reference-option for foreign key ON UPDATE option!",
                                                $tokens
                                            );
                                    }
                                    $indexJob->setForeignKeyOnUpdateReferenceOption($option);
                                    break;

                                default:
                                    throw new MalformedSqlException("Invalid ON event for foreign key (allowed are UPDATE and DELETE)!", $tokens);
                            }
                        }

                        $createTableJob->addIndex($indexJob);
                        break;

                    # CHECK (expression)
                    case $tokens->seekTokenNum(SqlToken::T_CHECK()):
                        if (!$this->conditionParser->canParseTokens($tokens)) {
                            throw new MalformedSqlException("Invalid CHECK condition statement!", $tokens);
                        }
                        $createTableJob->addCheck($this->conditionParser->convertSqlToJob($tokens));
                        break;

                    default:
                        throw new MalformedSqlException("Invalid definition in CREATE TABLE statement!", $tokens);
                }
            } while ($tokens->seekTokenText(','));
        }

        if ($checkEndParenthesis && !$tokens->seekTokenText(')')) {
            throw new MalformedSqlException("Missing closing parenthesis at end of table-definition!", $tokens);
        }

        ### TABLE OPTIONS

        while (true) {
            switch(true){

                case $tokens->seekTokenNum(SqlToken::T_ENGINE()):
                case $tokens->seekTokenNum(SqlToken::T_TYPE()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(T_STRING)) {
                        throw new MalformedSqlException("Missing T_STRING after T_ENGINE!", $tokens);
                    }
                    $createTableJob->setEngine(Engine::factory($tokens->getCurrentTokenString()));
                    break;

                case $tokens->seekTokenNum(SqlToken::T_AUTO_INCREMENT()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(T_NUM_STRING)) {
                        throw new MalformedSqlException("Missing number-string for T_AUTO_INCREMENT!", $tokens);
                    }
                    $createTableJob->setAutoIncrement((int)$tokens->getCurrentTokenString());
                    break;

                case $tokens->seekTokenNum(SqlToken::T_AVG_ROW_LENGTH()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(T_NUM_STRING)) {
                        throw new MalformedSqlException("Missing number-string for T_AVG_ROW_LENGTH!", $tokens);
                    }
                    $createTableJob->setAverageRowLength((int)$tokens->getCurrentTokenString());
                    break;

                case $tokens->seekTokenNum(SqlToken::T_CHARACTER(), TokenIterator::NEXT, [SqlToken::T_DEFAULT()]):
                    if (!$tokens->seekTokenNum(SqlToken::T_SET())) {
                        throw new MalformedSqlException("Missing SET after CHARACTER keyword!", $tokens);
                    }
                case $tokens->seekTokenNum(SqlToken::T_CHARSET(), TokenIterator::NEXT, [SqlToken::T_DEFAULT()]):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(T_CONSTANT_ENCAPSED_STRING) && !$tokens->seekTokenNum(T_STRING)) {
                        throw new MalformedSqlException("Missing string for CHARACTER SET!", $tokens);
                    }
                    $createTableJob->setCharacterSet($tokens->getCurrentTokenString());
                    break;

                case $tokens->seekTokenNum(SqlToken::T_COLLATE()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(T_CONSTANT_ENCAPSED_STRING) && !$tokens->seekTokenNum(T_STRING)) {
                        throw new MalformedSqlException("Missing string for COLLATE!", $tokens);
                    }
                    $createTableJob->setCollate($tokens->getCurrentTokenString());
                    break;

                case $tokens->seekTokenNum(SqlToken::T_CHECKSUM()):
                    $tokens->seekTokenText('=');
                    switch(true){
                        case $tokens->seekTokenText('0'):
                            $createTableJob->setUseChecksum(false);
                            break;
                        case $tokens->seekTokenText('1'):
                            $createTableJob->setUseChecksum(true);
                            break;
                        default:
                            throw new MalformedSqlException("Invalid value for CHECKSUM! (only 0 or 1 allowed!)", $tokens);
                    }
                    break;

                case $tokens->seekTokenNum(SqlToken::T_COMMENT()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(T_CONSTANT_ENCAPSED_STRING)) {
                        throw new MalformedSqlException("Missing encapsed string for comment!", $tokens);
                    }
                    $createTableJob->setComment($tokens->getCurrentTokenString());
                    break;

                case $tokens->seekTokenNum(SqlToken::T_CONNECTION()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(T_CONSTANT_ENCAPSED_STRING)) {
                        throw new MalformedSqlException("Missing encapsed string for connection-string!", $tokens);
                    }
                    $createTableJob->setConnectString($tokens->getCurrentTokenString());
                    break;

                case $tokens->seekTokenNum(SqlToken::T_MAX_ROWS()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(T_NUM_STRING)) {
                        throw new MalformedSqlException("Missing number-string for MAX_ROWS!", $tokens);
                    }
                    $createTableJob->setMaximumRows((int)$tokens->getCurrentTokenString());
                    break;

                case $tokens->seekTokenNum(SqlToken::T_MIN_ROWS()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(T_NUM_STRING)) {
                        throw new MalformedSqlException("Missing number-string for MIN_ROWS!", $tokens);
                    }
                    $createTableJob->setMinimumRows((int)$tokens->getCurrentTokenString());
                    break;

                case $tokens->seekTokenNum(SqlToken::T_PACK_KEYS()):
                    $tokens->seekTokenText('=');
                    switch(true){
                        case $tokens->seekTokenText('DEFAULT'):
                        case $tokens->seekTokenText('0'):
                            $createTableJob->setDelayKeyWrite(false);
                            break;
                        case $tokens->seekTokenText('1'):
                            $createTableJob->setDelayKeyWrite(true);
                            break;
                        default:
                            throw new MalformedSqlException("Invalid value for PACK_KEYS! (only DEFAULT, 0 or 1 allowed!)", $tokens);
                    }
                    break;

                case $tokens->seekTokenNum(SqlToken::T_PASSWORD()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(T_CONSTANT_ENCAPSED_STRING)) {
                        throw new MalformedSqlException("Missing encapsed string for password!", $tokens);
                    }
                    $createTableJob->setPassword($tokens->getCurrentTokenString());
                    break;

                case $tokens->seekTokenNum(SqlToken::T_DELAY_KEY_WRITE()):
                    $tokens->seekTokenText('=');
                    switch(true){
                        case $tokens->seekTokenText('0'):
                            $createTableJob->setDelayKeyWrite(false);
                            break;
                        case $tokens->seekTokenText('1'):
                            $createTableJob->setDelayKeyWrite(true);
                            break;
                        default:
                            throw new MalformedSqlException("Invalid value for DELAY_KEY_WRITE! (only 0 or 1 allowed!)", $tokens);
                    }
                    break;

                case $tokens->seekTokenNum(SqlToken::T_ROW_FORMAT()):
                    $tokens->seekTokenText('=');
                    $keyword = $tokens->getExclusiveTokenString();
                    $rowFormat = RowFormat::factory($keyword);
                    $tokens->seekIndex($tokens->getExclusiveTokenIndex());
                    $createTableJob->setRowFormat($rowFormat);
                    break;

                case $tokens->seekTokenNum(SqlToken::T_UNION()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenText('(')) {
                        throw new MalformedSqlException("Missing opening parenthesis for union-table-definition!", $tokens);
                    }
                    do {
                        if (!$this->tableParser->canParseTokens($tokens)) {
                            throw new MalformedSqlException("Invalid table in table-list for defining union tables!", $tokens);
                        }
                        $createTableJob->addUnionTable($this->tableParser->convertSqlToJob($tokens));
                    } while ($tokens->seekTokenText(','));

                    if (!$tokens->seekTokenText(')')) {
                        throw new MalformedSqlException("Missing closing parenthesis at union-table-list!", $tokens);
                    }
                    break;

                case $tokens->seekTokenNum(SqlToken::T_INSERT_METHOD()):
                    $tokens->seekTokenText('=');
                    switch(true){
                        case $tokens->seekTokenNum(SqlToken::T_NO()):
                            $createTableJob->setInsertMethod(InsertMethod::NO());
                            break;
                        case $tokens->seekTokenNum(SqlToken::T_FIRST()):
                            $createTableJob->setInsertMethod(InsertMethod::FIRST());
                            break;
                        case $tokens->seekTokenNum(SqlToken::T_LAST()):
                            $createTableJob->setInsertMethod(InsertMethod::LAST());
                            break;
                        default:
                            throw new MalformedSqlException("Invalid value given for insert-method (allowed are NO, FIRST and LAST)!");
                    }
                    break;

                case $tokens->seekTokenNum(SqlToken::T_DATA()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(SqlToken::T_DIRECTORY())) {
                        throw new MalformedSqlException("Missing T_DIRECTORY after T_DATA for data-directory!", $tokens);
                    }
                    if (!$tokens->seekTokenNum(T_CONSTANT_ENCAPSED_STRING)) {
                        throw new MalformedSqlException("Missing encapsed string for comment!", $tokens);
                    }
                    $createTableJob->setDataDirectory($tokens->getCurrentTokenString());
                    break;

                case $tokens->seekTokenNum(SqlToken::T_INDEX()):
                    $tokens->seekTokenText('=');
                    if (!$tokens->seekTokenNum(SqlToken::T_DIRECTORY())) {
                        throw new MalformedSqlException("Missing T_DIRECTORY after T_INDEX for index-directory!", $tokens);
                    }
                    if (!$tokens->seekTokenNum(T_CONSTANT_ENCAPSED_STRING)) {
                        throw new MalformedSqlException("Missing encapsed string for comment!", $tokens);
                    }
                    $createTableJob->setIndexDirectory($tokens->getCurrentTokenString());
                    break;

                default:
                    break 2;
            }

        }

        return $createTableJob;
    }