Tokenize matematical expression.

@param type $code
@return array Collection of Token instances
@throws \InvalidArgumentException
490644
public function tokenize($code)
    {
        $code = trim((string) $code);
        if (empty($code)) {
            throw new \InvalidArgumentException('Cannot tokenize empty string.');
        }

        $this->code = $code;
        $this->tokens = array();

        $tokenArray = explode(' ', $this->code);

        if (!is_array($tokenArray) || empty($tokenArray)) {
            throw new \InvalidArgumentException(
                sprintf('Cannot tokenize string: %s, please use " "(empty space for delimeter betwwen tokens)', $this->code)
            );
        }

        foreach ($tokenArray as $t) {
            if (array_key_exists($t, static::$operatorsMap)) {
                $token = new Operator(
                        $t,
                        static::$operatorsMap[$t]['priority'],
                        static::$operatorsMap[$t]['associativity']
                );
            } elseif (is_numeric($t)) {
                $token = new Token((float) $t, Token::T_OPERAND);
            }elseif('(' === $t) {
                $token = new Token($t, Token::T_LEFT_BRACKET);
            }elseif(')' === $t) {
                $token = new Token($t, Token::T_RIGHT_BRACKET);
            }elseif('' === $t) {
                continue;
            }else {
                throw new \InvalidArgumentException(sprintf('Syntax error: unknown token "%s"', $t));
            }

            $this->tokens[] = $token;
        }

        return $this->tokens;
    }
732260
public function create($languageCode) {
    $mappings = $this->getMappings();

    if (!isset($mappings[$languageCode])) {
      throw new \InvalidArgumentException('The language code is not part of the supported list. Please see GoogleSupportedLanguages\LanguageFactory::getMappings() for reference.');
    }

    return new $mappings[$languageCode]();
  }
624610
public static function getTokensFromString($code) {
      try {
        $tokens = token_get_all($code, TOKEN_PARSE);
      } catch (\ParseError $e) {
        // with TOKEN_PARSE flag, the function throws on invalid code
        // let's just ignore the error and tokenize the code without the flag
        $tokens = token_get_all($code);
      }

      foreach ($tokens as $index => $tokenData) {

        if (!is_array($tokenData)) {
          $previousIndex = $index - 1;

          /** @var Token $previousToken */
          $previousToken = $tokens[$previousIndex];
          $line = $previousToken->getLine() + substr_count($previousToken->getValue(), "\n");
          $tokenData = [
            Token::INVALID_TYPE,
            $tokenData,
            $line,
          ];
        }

        $token = new Token($tokenData);
        $token->setIndex($index);
        $tokens[$index] = $token;

      }

      return $tokens;
    }
814911
protected function prepareMultiInsert($code)
    {
        $default      = Languages::where('is_default', 1)->first()->code;
        $translations = Translation::where('locale', $default)->get()->toArray();
        $translation  = new Translation();
        $guarded      = $translation->getGuarded();
        $langId       = Languages::where('code', $code)->first()->id;
        $inserts      = array_map(function($current) use($code, $langId, $guarded) {
            $current['locale']  = $code;
            $current['lang_id'] = $langId;
            return array_except($current, $guarded);
        }, $translations);

        return $inserts;
    }
802861
public function get($code = null): string
    {
        if (!$this->validate($code)) {
            throw new \InvalidArgumentException('Invalid code');
        }

        return isset(self::$codes[$code]) ? self::$codes[$code] : '';
    }
585766
protected function applyHandlersToCode($code) {
		foreach($this->codeCallbackHandlers as $callback) {
			call_user_func_array($callback, array(&$code));
		}
		return $code;
	}
138165
private static function parseRegion($code)
    {
        $lang = substr($code, 0, 2);
        $reg =  strtoupper(substr($code, 3, 2));
        $needle = "{$lang}-{$reg}";
        foreach (self::codes() as $code) {
            if ($code['code'] == $needle) {
                return [$reg, $code['description']];
            }
        }

        throw new UnknownLanguageCodeException(
            "The region code '{$code}'' is unknown."
        );
    }
500171
public function setCode(callable $code) {
        if (!is_callable($code)) {
            throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.');
        }

        if (PHP_VERSION_ID >= 50400 && $code instanceof \Closure) {
            $r = new \ReflectionFunction($code);
            if (null === $r->getClosureThis()) {
                $code = \Closure::bind($code, $this);
            }
        }

        $this->code = $code;

        return $this;
    }
646943
public function setCode($code)
    {
        $allowedValues = $this->getCodeAllowableValues();
        if (!in_array($code, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'code', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['code'] = $code;

        return $this;
    }
433118
public function process($tokenList) {
        $unparsed = $tokenList['INTO'];
        foreach ($unparsed as $k => $token) {
            if ($this->isWhitespaceToken($token) || $this->isCommaToken($token)) {
                unset($unparsed[$k]);
            }
        }
        $tokenList['INTO'] = array_values($unparsed);
        return $tokenList;
    }
1251206
public function get_label($code)
    {
        if (!array_key_exists($code, $this->labels)) {
            throw new InvalidArgumentException(sprintf('Code %s is not defined', $code));
        }

        return isset($this->labels[$code]) && '' !== $this->labels[$code] ? $this->labels[$code] : $this->name;
    }
1107458
public static function fromCode($code)
    {
        $calculateCodeHashRefl = new \ReflectionMethod(BaseTokens::class, 'calculateCodeHash');
        $calculateCodeHashRefl->setAccessible(true);
        $hasCacheRefl = new \ReflectionMethod(BaseTokens::class, 'hasCache');
        $hasCacheRefl->setAccessible(true);
        $getCacheRefl = new \ReflectionMethod(BaseTokens::class, 'getCache');
        $getCacheRefl->setAccessible(true);

        $codeHash = $calculateCodeHashRefl->invoke(null, $code);

        if ($hasCacheRefl->invoke(null, $codeHash)) {
            /** @var Tokens $tokens */
            $tokens = $getCacheRefl->invoke(null, $codeHash);

            // generate the code to recalculate the hash
            $tokens->generateCode();

            if ($codeHash === $tokens->getCodeHash()) {
                $tokens->clearEmptyTokens();
                $tokens->clearChanged();

                return $tokens;
            }
        }

        $tokens = new static();
        $tokens->setCode($code);
        $tokens->clearChanged();

        return $tokens;
    }
545103
public static function filterStatusCode(int $code): int
    {
        $filteredCode = \filter_var($code, \FILTER_VALIDATE_INT, ['options' => [
            'min_range' => self::MINIMUM,
            'max_range' => self::MAXIMUM,
        ]]);

        if ($filteredCode === false) {
            throw new InvalidArgumentException(\sprintf(
                'The submitted code "%s" must be a positive integer between %s and %s.',
                $code,
                self::MINIMUM,
                self::MAXIMUM
            ));
        }

        return $code;
    }
881167
public function buildBlock($code)
    {
        $lines = $this->parser->splitIntoLines($code);
        $result = [];

        foreach (array_filter($lines) as $line)
        {
            $result[] = $this->printer->toString(
                eval ("return {$line};")
            );
        }

        return sprintf(
            "```php\n%s```\n```\n%s\n```\n",
            implode("\n", $lines),
            implode("\n", $result)
        );
    }
846776
public function verify($token, $code)
    {
        $code = strtoupper($code);
        
        if (!$code || !DataHelper::verify_code($code)) {
            return ErrorInfo::error('请输入图形码');
        }
        
        return $this->getTokenInstance()->verify($token, ['code' => $code]);
    }
472311
public static function getExpressByCode($code){
        if($code){
            $expresses = self::expresses();
            $express = array_filter($expresses,function ($express) use($code){
                return $express['code'] == $code;
            });
            if($express){
                return current($express);
            }
            return null;
        }
        return null;
    }
180631
private function getZoneMemberByCode($code)
    {
        $zoneMember = $this->zoneMemberRepository->findOneBy(['code' => $code]);
        Assert::notNull(
            $zoneMember,
            sprintf('Zone member with code %s does not exist.', $code)
        );

        return $zoneMember;
    }