Lex and parse a string of code into statements.

@param string $code

@return array Statements
487995
private function parse($code)
    {
        try {
            return $this->parser->parse($code);
        } catch (\PhpParser\Error $e) {
            if (\strpos($e->getMessage(), 'unexpected EOF') === false) {
                throw $e;
            }

            // If we got an unexpected EOF, let's try it again with a semicolon.
            return $this->parser->parse($code . ';');
        }
    }
70187
protected function _analiseCode($code)
    {
        // name of the tag, opening, closure, autoclosure
        $tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)';
        if (!preg_match('/'.$tag.'/isU', $code, $match)) return null;
        $close     = ($match[1]=='/' ? true : false);
        $autoclose = preg_match('/\/>$/isU', $code);
        $name      = strtolower($match[2]);

        // required parameters (depends on the tag name)
        $param    = array();
        $param['style'] = '';
        if ($name=='img') {
            $param['alt'] = '';
            $param['src'] = '';
        }
        if ($name=='a') {
            $param['href'] = '';
        }

        // read the parameters : nom=valeur
        $prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)';
        preg_match_all('/'.$prop.'/is', $code, $match);
        for($k=0; $k<count($match[0]); $k++)
            $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);

        // read the parameters : nom="valeur"
        $prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]';
        preg_match_all('/'.$prop.'/is', $code, $match);
        for($k=0; $k<count($match[0]); $k++)
            $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);

        // read the parameters : nom='valeur'
        $prop = "([a-zA-Z0-9_]+)=[']([^']*)[']";
        preg_match_all('/'.$prop.'/is', $code, $match);
        for($k=0; $k<count($match[0]); $k++)
            $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);

        // compliance of each parameter
        $color  = "#000000";
        $border = null;
        foreach ($param as $key => $val) {
            $key = strtolower($key);
            switch($key)
            {
                case 'width':
                    unset($param[$key]);
                    $param['style'] .= 'width: '.$val.'px; ';
                    break;

                case 'align':
                    if ($name==='img') {
                        unset($param[$key]);
                        $param['style'] .= 'float: '.$val.'; ';
                    } elseif ($name!=='table') {
                        unset($param[$key]);
                        $param['style'] .= 'text-align: '.$val.'; ';
                    }
                    break;

                case 'valign':
                    unset($param[$key]);
                    $param['style'] .= 'vertical-align: '.$val.'; ';
                    break;

                case 'height':
                    unset($param[$key]);
                    $param['style'] .= 'height: '.$val.'px; ';
                    break;

                case 'bgcolor':
                    unset($param[$key]);
                    $param['style'] .= 'background: '.$val.'; ';
                    break;

                case 'bordercolor':
                    unset($param[$key]);
                    $color = $val;
                    break;

                case 'border':
                    unset($param[$key]);
                    if (preg_match('/^[0-9]+$/isU', $val)) $val = $val.'px';
                    $border = $val;
                    break;

                case 'cellpadding':
                case 'cellspacing':
                    if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px';
                    break;

                case 'colspan':
                case 'rowspan':
                    $val = preg_replace('/[^0-9]/isU', '', $val);
                    if (!$val) $val = 1;
                    $param[$key] = $val;
                    break;
            }
        }

        // compliance of the border
        if ($border!==null) {
            if ($border)    $border = 'border: solid '.$border.' '.$color;
            else            $border = 'border: none';

            $param['style'] .= $border.'; ';
            $param['border'] = $border;
        }

        // reading styles: decomposition and standardization
        $styles = explode(';', $param['style']);
        $param['style'] = array();
        foreach ($styles as $style) {
            $tmp = explode(':', $style);
            if (count($tmp)>1) {
                $cod = $tmp[0];
                unset($tmp[0]);
                $tmp = implode(':', $tmp);
                $param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp));
            }
        }

        // determining the level of table opening, with an added level
        if (in_array($name, array('ul', 'ol', 'table')) && !$close) {
            $this->_num++;
            $this->_level[count($this->_level)] = $this->_num;
        }

        // get the level of the table containing the element
        if (!isset($param['num'])) {
            $param['num'] = $this->_level[count($this->_level)-1];
        }

        // for closures table: remove a level
        if (in_array($name, array('ul', 'ol', 'table')) && $close) {
            unset($this->_level[count($this->_level)-1]);
        }

        // prepare the parameters
        if (isset($param['value']))  $param['value']  = $this->_prepareTxt($param['value']);
        if (isset($param['alt']))    $param['alt']    = $this->_prepareTxt($param['alt']);
        if (isset($param['title']))  $param['title']  = $this->_prepareTxt($param['title']);
        if (isset($param['class']))  $param['class']  = $this->_prepareTxt($param['class']);

        // return the new action to do
        return array('name' => $name, 'close' => $close ? 1 : 0, 'autoclose' => $autoclose, 'param' => $param);
    }
913051
public static function getLanguage($code = 'default')
    {
        if ($code == 'default') {
            $code = App::getLocale();
        }

        return self::addNames([$code])[$code];
    }
133776
protected function check_syntax($code){

        $errors = array();

        ob_start();

        $check = function_exists('eval') ? eval('?>'.'<?php if(0): ?>'.$code.'<?php endif; ?><?php ') : true;

        if ($check === false) {
            $output = ob_get_clean();
            $output = strip_tags($output);

            if (preg_match_all("/on line (\d+)/m", $output, $matches)) {

                foreach($matches[1] as $m){
                    $errors[] = "Parse error on line: ".$m;
                }

            } else {
                $errors[] = 'syntax error';
            }

        } else {
            ob_end_clean();
        }

        return count($errors) ? $errors:false;
    }
876669
protected function decodeHash( $code )
	{
		$php	= gzinflate( base64_decode( $code ) );
		$php	= substr( $php, strlen( $this->incodePrefix) , -strlen( $this->incodeSuffix ) );
		return 	$php;
	}
14770
public static function stripComments($code)
    {
        $output = '';
        $commentTokens = array(T_COMMENT, T_DOC_COMMENT);
        foreach (token_get_all($code) as $token) {
            if (is_array($token)) {
                if (in_array($token[0], $commentTokens)) {
                    continue;
                }
                $token = $token[1];
            }
            $output .= $token;
        }

        return $output;
    }
495253
protected function getErrorTypeByCode($code) {
		if(!static::$errorsConstantsValues) {
			foreach(static::$errorsConstantsNames as $constantName) {
				if(defined($constantName)) {
					static::$errorsConstantsValues[constant($constantName)] = $constantName;
				}
			}
		}
		if(isset(static::$errorsConstantsValues[$code])) {
			return static::$errorsConstantsValues[$code];
		}
		return (string)$code;
	}
1226396
public static function codeToCollection(string $code) {
		$tokens = token_get_all($code);
		//prr($tokens,1,1);
		$tokenCollection = [];
		foreach($tokens as $token) {
			$entity = new TokenEntity();
			if(is_array($token)) {
				$entity->type = $token[0];
				$entity->value = $token[1];
				$entity->line = $token[2];
			} else {
				$entity->type = 0;
				$entity->value = $token;
				//$entity->line = $token[2];
			}
			$tokenCollection[] = $entity;
		}
		return $tokenCollection;
	}
550290
public function getLanguageByCode($code)
    {
        $returnValue = null;


        $langClass = new core_kernel_classes_Class(static::CLASS_URI_LANGUAGES);
	    $langs = $langClass->searchInstances(array(
            OntologyRdf::RDF_VALUE => $code
	    ), array(
	    	'like' => false
	    ));
	    if (count($langs) == 1) {
	    	$returnValue = current($langs);
	    } else {
	    	common_Logger::w('Could not find language with code '.$code);
	    }


        return $returnValue;
    }
407284
protected function getCode($code)
    {
        if (is_array($code)) {
            return $this->getCodeArray($code);
        }

        return $this->get($code);
    }
1098480
public function get($code): array
    {
        $options = ['json' => ['code' => $code]];

        /** @var JsonStream $stream */
        $stream = $this->client
            ->get(UserApi::generateUrl('user/organizations.json'), $options)
            ->getBody();

        return $stream->jsonSerialize()['organizationTitles'];
    }
120909
public function create(string $code): array
    {
        $stmt = $this->parser->parse($code);
        return $this->traverser->traverse($stmt);
    }
1114030
public static function getErrText($code)
    {
        if (isset(self::$errCode[$code])) {
            return self::$errCode[$code];
        }
        return false;
    }
1183505
public function getClassReflections($code)
    {
        $result = [];
        foreach ($this->getClassNames($code) as $className) {
            $result[$className] = new \ReflectionClass($className);
        }
        return $result;
    }
53240
public static function guess(string $code) : string
    {
        switch (strtolower(trim($code))) {
            case SportMapperInterface::RUNNING:
            case 'run':
                return SportMapperInterface::RUNNING;
            case SportMapperInterface::CYCLING_SPORT:
            case 'cycling':
                return SportMapperInterface::CYCLING_SPORT;
            case SportMapperInterface::CYCLING_TRANSPORT:
                return SportMapperInterface::CYCLING_TRANSPORT;
            case SportMapperInterface::SWIMMING:
                return SportMapperInterface::SWIMMING;
            default:
                return SportMapperInterface::OTHER;
        }
    }
316479
public function tokenize($code)
    {
        $this->tokens = array();
        $lines        = preg_split('/\r?\n/', $code);
        $number       = 0;

        foreach ($lines as $number => $fragment) {
            $this->processLine($number + 1, $fragment);
            $this->tokens[] = new Token(self::TOKEN_EOL, null, $number + 1);
        }
        $this->tokens[] = new Token(self::TOKEN_EOF, null, $number + 1);

        return new TokenStream($this->tokens);
    }
173554
public static function getHierarchyParents($code)
    {
        $parents = [''];

        $node_length = strlen($code);
        $current_length = 0;

        foreach (static::getHierarchyLengths() as $length) {
            if ($current_length + $length === $node_length) {
                return $parents;
            } elseif ($current_length + $length > $node_length) {
                return false;
            } else {
                $current_length += $length;
                $parents[] = substr($code, 0, $current_length);
            }
        }

        return false;
    }