Compile expression list.

@return string
975680
protected function compileExpressions()
    {
        if (count($this->expressions) === 0) {
            throw new BadMethodCallException('Can\'t compile an empty expression');
        }
        if (count($this->expressions) === 1) {
            return reset($this->expressions);
        }

        $parts = [];

        foreach ($this->expressions as $expr) {
            $expr = '(?:' . $expr . ')';

            $parts[] = $expr;
        }

        return '(?:' . implode('|', $parts) . ')';
    }
114864
protected function compileLoopStack($expression)
    {
        foreach ($this->getLoopStack() as $token) {
            $out = $this->{'compile'.$token}($expression);

            if (strlen($out) !== 0) {
                $expression = $out;
            }
        }

        return $expression;
    }
950537
protected function compileExtends($expression)
    {
        $regex = "/\#extends\s*\(((?:\n|\s|\t)*(?:.+?)(?:\n|\s|\t)*)\)/sm";

        if (preg_match($regex, $expression, $match)) {
            $this->footer[] = "<?php echo \$__tintin->getStackManager()->includeFile({$match[1]}, ['__tintin' => \$__tintin]); ?>";

            return ' ';
        }

        return $expression;
    }
972470
protected function compileInclude($expr)
    {
        $expr = explode(',', $this->stripParentheses($expr), 2);
        $vars = isset($expr[1]) ? trim($expr[1]) : '';
        if (empty($vars)) {
            return "<?php echo \$this->make({$expr[0]}, get_defined_vars()); ?>";
        }
        else {
            $result = "<?php echo \$this->make({$expr[0]}, array_merge(get_defined_vars(), {$vars})); ?>";
            return $result;
        }
    }
913972
protected function compileForelse($expression)
    {
        $empty = '$__empty_'.++$this->forElseCounter;

        preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);

        $iteratee = trim($matches[1]);

        $iteration = trim($matches[2]);

        $initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);";

        $iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();';

        return "<?php {$empty} = true; {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} {$empty} = false; ?>";
    }
1216729
private function compile()
    {
        $ff5c = "\x{ff5c}";
        if( PHP_VERSION_ID >= 70000){
            $ff5c = "\u{ff5c}";
        }
        $this->re = new Re($this->__opts__);

        // Define dynamic patterns
        $tlds = array_slice($this->__tlds__, 0);

        $this->onCompile();

        if (!$this->__tlds_replaced__) {
            $tlds[] = $this->tlds_2ch_src_re;
        }
        $tlds[] = $this->re->src_xn;

        $this->re->src_tlds = join('|', $tlds);

        $untpl = function(&$tpl){ return preg_replace('/%TLDS%/u', $this->re->src_tlds, $tpl); };

        $this->re->email_fuzzy      = '/' . $untpl($this->re->tpl_email_fuzzy) . '/ui';
        $this->re->link_fuzzy       = '/' . $untpl($this->re->tpl_link_fuzzy) . '/ui';
        $this->re->link_no_ip_fuzzy = '/' . $untpl($this->re->tpl_link_no_ip_fuzzy) . '/ui';
        $this->re->host_fuzzy_test  = '/' . $untpl($this->re->tpl_host_fuzzy_test) . '/ui';

        //
        // Compile each schema
        //

        $aliases = [];
        $this->__compiled__ = []; // Reset compiled data

        $schemaError = function (&$name, &$val) {
            throw new \Exception('(LinkifyIt) Invalid schema "' . $name . '": '. gettype ($val));
        };

        foreach($this->__schemas__ as $name => &$val) {
            if ($val === null) { continue; }

            $compiled = new \stdClass();
            $compiled->validate = null;
            $compiled->link = null;

            $this->__compiled__[$name] = $compiled;

            if (is_object($val)) {
                if( !isset($val->validate)){
                    $schemaError($name, $val);
                } else if (is_string($val->validate)) {
                    $compiled->validate = $this->createValidator($val->validate);
                } else if (is_callable($val->validate)) {
                    $compiled->validate = $val->validate;
                } else {
                    $schemaError($name, $val);
                }

                if (!isset($val->normalize)) {
                    $compiled->normalize = $this->createNormalizer();
                } else if (is_callable($val->normalize)) {
                    $compiled->normalize = $val->normalize;
                } else {
                    $schemaError($name, $val);
                }

                continue;
            }

            if (is_string($val)) {
                $aliases[] = $name;
                continue;
            }

            $schemaError($name, $val);
        }

        //
        // Compile postponed aliases
        //
        foreach($aliases as &$alias){
            if (isset($this->__schemas__[$alias]) && !isset($this->__compiled__[$this->__schemas__[$alias]])) {
                // Silently fail on missed schemas to avoid errons on disable.
                // $schemaError(alias, self.__schemas__[alias]);
                continue;
            }

            $this->__compiled__[$alias]->validate =
                $this->__compiled__[$this->__schemas__[$alias]]->validate;
            $this->__compiled__[$alias]->normalize =
                $this->__compiled__[$this->__schemas__[$alias]]->normalize;
        }

        //
        // Fake record for guessed links
        //
        $fake = new \stdClass();
        $fake->validate = null;
        $fake->normalize = $this->createNormalizer();
        $this->__compiled__[''] = $fake;

        /**
         * Merge objects
         * @param $str
         * @return mixed
         */
        $escapeRE = function($str) {
            return preg_replace("/([\.\?\*\+\^\$\[\]\\\(\)\{\}\|\-\/\^])/u", '\\\\${1}', $str);
        };

        //
        // Build schema condition
        //
        $slist = join('|',
            array_map($escapeRE,
                array_filter(
                    array_keys($this->__compiled__),
                    function ($name) {
                        // Filter disabled & fake schemas
                        return strlen ($name) > 0 && isset($this->__compiled__[$name]);
                    }
                )
            )
        );
//        var slist = Object.keys(self.__compiled__)
//            .filter(function (name) {
//                // Filter disabled & fake schemas
//                return name.length > 0 && self.__compiled__[name];
//            })
//            .map(escapeRE)
//            .join('|');

        // (?!_) cause 1.5x slowdown
        $this->re->schema_test   = "/(^|(?!_)(?:[><{$ff5c}]|" . $this->re->src_ZPCc . '))(' . $slist . ')/ui';
        $this->re->schema_search = "/(^|(?!_)(?:[><{$ff5c}]|" . $this->re->src_ZPCc . '))(' . $slist . ')/ui';


        $this->re->pretest       =
            '/((^|(?!_)(?:[><]|' . $this->re->src_ZPCc . '))(' . $slist . '))|' .
            '((^|(?!_)(?:[><]|' . $this->re->src_ZPCc . '))(' . $slist . '))|' .
            '@/ui';

        //
        // Cleanup
        //

        $this->resetScanCache();
    }
1006968
public function compile()
    {
        $route = $this->getRoute();

        //
        $optionals = $this->extractOptionalParameters($uri = $route->uri());

        $path = preg_replace('/\{(\w+?)\?\}/', '{$1}', $uri);

        $domain = $route->domain() ?: '';

        return with(
            new SymfonyRoute($path, $optionals, $route->patterns(), array(), $domain)

        )->compile();
    }
828631
protected function compileIfStack($expression)
    {
        foreach (['UnLess', 'If', 'ElseIf', 'ElseIfAlias', 'Else', 'EndIf'] as $token) {
            $out = $this->{'compile'.$token}($expression);

            if (strlen($out) !== 0) {
                $expression = $out;
            }
        }

        return $expression;
    }
264482
public function compileParameters(): array
    {
        $return = [
            'query' => [],
            'resource_id' => $this->resourceId,
        ];

        if ($this->filterBy) {
            $return['query']['filter_by'] = $this->filterBy;
        }

        if ($this->sortBy) {
            $return['query']['sort_by'] = $this->sortBy;
        }

        if ($this->fieldList) {
            $return['query']['field_list'] = $this->fieldList;
        }

        if ($this->parameters) {
            foreach ($this->parameters as $name => $value) {
                $return['query'][$name] = $value;
            }
        }

        return $return;
    }
308894
public function getExpression()
    {
        $expression = array(
            $this->minute,
            $this->hour,
            $this->dayOfMonth,
            $this->month,
            $this->dayOfWeek
        );

        return implode(' ', $expression);
    }
425913
private function compileFilterExpression()
    {
        $filters = [];

        foreach ($this->filters as $filter => $options) {
            $opt = [];

            if (is_array($options)) {

                foreach ($options as $option => $value) {
                    $opt[] = sprintf('%s=%s', $option, $value);
                }
            }
            $filters[] = sprintf('%s;%s', $filter, implode(';', $opt));
        }
        if (!empty($filters)) {
             return sprintf('filter:%s', implode(':', $filters));
        }

        return null;
    }
1058552
protected function createSliceFunction()
    {
        return new ExpressionFunction(
            'slice',
            function ($array, $start, $length = null, $preserveKeys = false) {
                return sprintf('array_slice(%s, %s, %s, %s)', $array, $start, $length, $preserveKeys);
            },
            function ($arguments, $array, $start, $length = null, $preserveKeys = false) {
                return array_slice($array, $start, $length, $preserveKeys);
            }
        );
    }
454404
protected function compile()
	{		
		// Get the pattern model collection
		$colPattern = \PatternModel::findVisibleByPid($this->objElement->id);

		if ($colPattern === null)
		{
			return;
		}
		
		// Get correct content element id (included content element) see #37
		$intPid = ($this->origId) ? $this->origId : $this->id;
		
		// Get the data
		$colData = \DataModel::findByPid($intPid);

		if ($colData !== null)
		{
			foreach ($colData as $objData)
			{
				$arrData[$objData->pattern] = $objData;
			}							
		}

		// Prepare values for every pattern
		foreach($colPattern as $objPattern)
		{
			if (!Pattern::hasOutput($objPattern->type))
			{
				continue;
			}
			
			$strClass = Pattern::findClass($objPattern->type);
				
			if (!class_exists($strClass))
			{
				System::log('Pattern element class "'.$strClass.'" (pattern element "'.$objPattern->type.'") does not exist', __METHOD__, TL_ERROR);
			}
			else
			{
				$objPatternClass = new $strClass($objPattern);
				$objPatternClass->pid = $intPid;
				$objPatternClass->Template = $this->Template;
				$objPatternClass->data = $arrData[$objPattern->alias];
		
				$objPatternClass->compile();
			}
		}
	}
1319670
public function getCompiled()
    {
        if ($this->compiled === null) {
            $regexp = "/^";

            // Method(s)
            $methodIdx = 0;
            foreach($this->methods as $method) {
                $regexp .= "(?:" . strtoupper($method) . ")";
                if (($methodIdx + 1) < count($this->methods)) {
                    $regexp .= "|";
                }
                $methodIdx++;
            }

            // Separator
            $regexp .= "~";

            // Url
            $regexp .= str_replace('/', '\/', $this->match);

            $regexp .= "$/";

            $this->compiled = $regexp;
        }
        return $this->compiled;
    }
351491
public function list(): string
    {
        if (!$this->types) {
            return '';
        }

        $meta = [];

        foreach ($this->types as $type) {
            if (0 === \stripos($type, 'avatar__')) {
                if ($this->post->author()->supported() &&
                    ($avatar = $this->post->thumbnail($type))
                ) {
                    $meta[] = $avatar;
                }
            } elseif (0 === \stripos($type, 'updated_ago')) {
                $meta[] = $this->updatedAgo(\preg_replace(
                    '/^updated\_ago(\_\_)?/i',
                    '',
                    $type
                ));
            } elseif (0 === \stripos($type, 'published_ago')) {
                $meta[] = $this->publishedAgo(\preg_replace(
                    '/^published\_ago(\_\_)?/i',
                    '',
                    $type
                ));
            } elseif (\is_callable([$this, ($call = "render_{$type}")])
                && ($return = $this->$call())
            ) {
                $meta[] = $return;
            } elseif ($filter = \apply_filters(
                $type,
                '',
                $this->post->get()->ID,
                $this->separator
            )) {
                $meta[] = $filter;
            } elseif ($post_meta = $this->post->meta($type, true)) {
                $meta[] = $post_meta;
            } elseif ($terms = $this->termList($type)) {
                $meta[] = $terms;
            }
        }

        if (!$meta) {
            return '';
        }

        return $this->before.\join(
            ' <span class="meta-sep">'.$this->separator.'</span> ',
            $meta
        ).$this->after;
    }
91364
protected function buildValuesClause() {
		if (!empty($this->expression))
			return $this->expression;
		
		if (empty($this->value)) {
			$values = [];
			
			for ($i = 0, $n = count($this->valueList); $i < $n; $i++)
				$values[] = '%{' . $i . '}';
			
			return implode(',', $values);
		}
		

		$values = [];
		
		foreach ($this->columnList as $column) {
			$name = $this->parseColumn($column);
			$values[] = '#{' . $name . '}';
		}

		return implode(',', $values);
	}
1090830
protected function compileForeach($expr)
    {
        preg_match('/\( *(.*) +as *([^\)]*)/is', $expr, $matches);
        $iteratee = trim($matches[1]);
        $iteration = trim($matches[2]);

        return "<?php foreach({$iteratee} as {$iteration}): ?>";
    }