Parse the template

@return string Parsed element
174464
public function generate()
	{
		if (TL_MODE === 'BE') {
			return parent::generate();
		}

		$parentKey = ($this->arrData['ptable'] ?: 'tl_article') . '__' . $this->arrData['pid'];
		if (isset($GLOBALS['TL_RS_COLUMNS'][$parentKey])) {
			if (!$GLOBALS['TL_RS_COLUMNS'][$parentKey]['active']) {
				trigger_error('Missing column stop element before column wrapper stop element ID ' . $this->id . '.', E_USER_WARNING);
			}
			unset($GLOBALS['TL_RS_COLUMNS'][$parentKey]);
		}
		else {
			trigger_error('Missing column wrapper start element before column wrapper stop element ID ' . $this->id . '.', E_USER_WARNING);
		}

		$htmlSuffix = '';

		if (!empty($GLOBALS['TL_RS_COLUMNS_STACK'][$parentKey])) {
			$GLOBALS['TL_RS_COLUMNS'][$parentKey] = array_pop($GLOBALS['TL_RS_COLUMNS_STACK'][$parentKey]);
			if ($GLOBALS['TL_RS_COLUMNS'][$parentKey]['active']) {
				$htmlSuffix .= '</div>';
			}
		}

		return parent::generate() . $htmlSuffix;
	}
186002
public function parse()
    {
        if (!is_file($this->file)) {
            throw new \Exception(sprintf(
                'Template "%s" file doesn\'t exist!', $this->file
            ));
        }

        $fp = fopen($this->file, 'r');

        $lineCount       = 0;
        $nextToken       = '';
        $block           = '';
        $currentValue    = '';
        $stringComposing = false;
        $skipMultilineComment = false;

        while (($line = fgets($fp)) !== false) {
            $lineCount++;

            if ($stringComposing) {
                if (substr(ltrim($line), 0, 3) === '>>>') {
                    $this->blocks[$block][$name] = trim($value);
                    //$block = '';
                    $value = '';
                    $stringComposing = false;
                } else {
                    // $line = trim($line);
//                     if (substr($value, -1) != '>' && ! empty($line)) {
//                         $line = " " . $line;
//                     }

                    //$value .= substr($value, -1) == '>' ? trim($line) : " " . trim($line);
                    $value .= $line;
                }

                continue;
            }

            $line = trim($line);

            if (substr($line, 0, 1) === '#' || $line === '' || substr($line, 0, 2) === '//') {
                continue; // skip single comments or empty lines
            } elseif (substr($line, 0, 2) === '/*') { // start multiline comment
                if (strpos($line, '*/') === false) {
                    $skipMultilineComment = true; // activate multiline comments skipping
                } else {
                    continue; // just skip this line, it has the form: /* ... */
                }
            } elseif (strpos($line, '*/') !== false) { // end multiline comment
                $skipMultilineComment = false;
                continue; // just skip the end multiline comment
            }

            if ($skipMultilineComment) {
                continue; //skip multiline comments segment
            }

            $kwPattern = '^@(?<keyword>\w+)';

            if (! preg_match('/'.$kwPattern.'.*/', $line, $matches)) {
                throw new \Exception(sprintf(
                    'Parse Error: Unknow keyword, lines must starts with a valid keyword, near: %s, on line %s',
                    $line, $lineCount
                ));
            }
            //var_dump($matches);
            $keyword = $matches['keyword'];

            switch ($keyword) {
                case Parser::T_DEF:
                    $pattern = '/'.$kwPattern.'\s+(?<type>[\w]+)\s+(?<name>[\w.]+)\s+(?<value>.+)/';

                    if (!preg_match($pattern, $line, $matches)) {
                        throw new \Exception(sprintf(
                            "Syntax Error: near: '%s', on line %s.\n" .
                            "Syntax should be: @def <type> <name> <value>",
                            $line, $lineCount
                        ));
                    }

                    $keyword = $matches['keyword'];
                    $type    = $matches['type'];
                    $name    = $matches['name'];
                    $value   = $matches['value'];

                    $tmp     = explode('.', $name);
                    $defName = $tmp[0];
                    $defProp = isset($tmp[1]) ? $tmp[1] : '';

                    switch ($type) {
                        case Parser::T_GLOBAL:
                        case Parser::T_ITERATOR:
                        case Parser::T_SETCONF:
                            if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
                                $value = trim($value, '"');
                            } elseif (substr($value, 0, 1) == "'" && substr($value, -1) == "'") {
                                $value = trim($value, "'");
                            }

                            if ($value === '\n' || $value === '\r\n') {
                                $value = "\n";
                            }

                            $value = self::castValue($value);

                            if (empty($defProp)) {
                                $this->defs[$type][$defName] = $value;
                            } else {
                                $this->defs[$type][$defName][$defProp] = $value;
                            }
                            break;
                        default:
                            throw new \Exception(sprintf(
                                'Parse Error: unknow definition type: "%s" on line %s.', $type, $lineCount
                            ));
                    }
                    break;
                case Parser::T_BLOCK:
                    $pattern = '/'.$kwPattern.'\s+(?<block>[\w]+)/';

                    if (!preg_match($pattern, $line, $matches)) {
                        throw new Exception(sprintf(
                            "Parse Error: Syntax error near: %s, on line %s.\n." .
                            "Syntax should be: @def <type> <name> <value>",
                            substr($line, 0, 20).'...', $lineCount
                        ));
                    }
                    //var_dump($matches);

                    $block = $matches['block'];

                    if (!empty($nextToken)) {
                        throw new \Exception(sprintf(
                            'Parse Error: expected: @"%s", given: @"%s"', $nextToken, Parser::T_BLOCK
                        ));
                    }

                    $nextToken = Parser::T_END;
                    break;
                case Parser::T_END:
                    if (empty($nextToken)) {
                        throw new \Exception(sprintf(
                            'Parse Error: close keyword: @"%s" given, but any block was started.', Parser::T_BLOCK
                        ));
                    }

                    if ($nextToken !== Parser::T_END) {
                        throw new \Exception(sprintf(
                            'Parse Error: expected: @"%s", given: @"%s"', $nextToken, Parser::T_END
                        ));
                    }

                    $nextToken = '';
                    break;
                case Parser::T_VAR:
                    $pattern = '/'.$kwPattern.'\s+(?<name>[\w]+)\s+(?<value>.+)/';

                    if (!preg_match($pattern, $line, $matches)) {
                        throw new Exception(sprintf(
                            "Parse Error: Syntax error near: %s, on line %s.\n." .
                            "Syntax should be: @var <name> <value>\n or \n" .
                            "@var <name> <<<\nsome large string\nmultiline...\n>>>\n\n",
                            substr($line, 0, 20).'...', $lineCount
                        ));
                    }
                    //print_r($matches);
                    $keyword = $matches['keyword'];
                    $name    = $matches['name'];
                    $value   = $matches['value'];

                    if (substr($value, 0, 3) === '<<<' && $value !== '<<<') {
                        throw new \Exception(sprintf(
                            "Syntax Error: multiline string must starts on new line after open braces <<<\n" .
                            "near: '%s', on line %s", $line, $lineCount
                        ));
                    }

                    if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') {
                        $value = trim($value, '"');
                    } elseif (substr($value, 0, 1) == "'" && substr($value, -1) == "'") {
                        $value = trim($value, "'");
                    }

                    if ($value !== '<<<') {
                        $this->blocks[$block][$name] = self::castValue($value);
                    } else {
                        $value = '';
                        $stringComposing = true;
                    }
                    break;
                default:
                    throw new \Exception(sprintf(
                        'Parse Error: Unknown definition type: %s, on line %s', $type, $lineCount
                    ));
            }

        }

        if ($stringComposing) {
            throw new \Exception(sprintf(
                "Parse Error: Multiline string closing braces are missing '>>>',\nfor @block: '%s', @var: '%s' " .
                "until end of file.", $block, $name
            ));
        }
    }
123965
public function parse()
    {
        if ($this->query !== null) {
            return $this->query;
        }
        $query = preg_replace_callback('~{(.*?)}~', array($this, 'tableClb'), $this->pattern);
        $pattern = '~\?([a-z\?-]+)?(:([a-z0-9_-]*))?;?~i';
        $callback = array($this, 'placeholderClb');
        $query = preg_replace_callback($pattern, $callback, $query);
        if ((!$this->named) && (count($this->data) > $this->counter)) {
            if (($this->counter > 0) || (isset($this->data[0]))) {
                throw new DataMuch(count($this->data), $this->counter);
            }
        }
        $this->query = $query;
        return $this->query;
    }
635266
public function getElement()
	{
		$element = $this->_element;

		if (empty($element))
		{
			$r = new ReflectionClass($this);
			if ($r->inNamespace())
			{
				$bits = explode('\\', __NAMESPACE__);

				// Should match either:
				//   Plugins\Folder\Element
				//   Components\Folder\Plugins\Element
				$element = strtolower($bits[2]);

				if (strtolower($bits[0]) == 'components')
				{
					$element = strtolower($bits[3]);
				}
			}
			else
			{
				throw new Exception('Cannot get or parse view class name.', 500);
			}
		}

		return $element;
	}
1231752
public function parse()
    {
        if (isset($this->view)) return;

        if ($this->viewParser instanceof StyleAwareInterface
            and $this->styleParser) {

            $style = $this->styleParser->parse($this->stylePath);

            if ($style) $this->viewParser->setStyle($style);
        }

        $view = $this->viewParser->parse($this->viewPath);

        if ($view instanceof ControllerAwareInterface) {
            $view->setController($this->controller);
        }

        $this->view = $view;
    }
455537
private function _parse()
    {
        $this->contentXml = str_replace(array_keys($this->vars), array_values($this->vars), $this->contentXml);
        $this->stylesXml  = str_replace(array_keys($this->vars), array_values($this->vars), $this->stylesXml);
    }
342920
private function render() {
        $parsed_data = Parser::parse($this->input_path);

        if ($parsed_data['frontmatter'] !== false && !$this->should_ignore()) {
            return Template::render($parsed_data['content'], $parsed_data['frontmatter']);
        }

        return $parsed_data['content'];
    }
278211
public function template() {

		if ( is_null( $this->template ) ) {
			$this->template = $this->locate();
		}

		return $this->template;
	}
651888
def _parse(self):
        
        # Is this a shorthand template?
        if self._element.tag == 'template':
            return self._parse_template(self._element)

        # Is this a shorthand redirect?
        if self._element.tag == 'redirect':
            return self._parse_redirect(self._element)

        for child in self._element:
            method_name = '_parse_' + child.tag

            if hasattr(self, method_name):
                parse = getattr(self, method_name)
                parse(child)
1340084
private function parse()
    {
        if (isset($this->template, $this->frontMatter)) {
            return $this;
        }

        $source = $this->readSourceFile();

        $parts = preg_split('/[\n]*[-]{3}[\n]/', $source, 2);
        if (count($parts) === 2) {
            $this->frontMatter = Yaml::parse($parts[0]);
            $this->template = trim($parts[1]);
        } else {
            $this->frontMatter = array();
            $this->template = trim($source);
        }

        return $this;
    }
694439
public function templateOptionsStructure()
    {
        if ($this->areTemplateOptionsFinalized === false) {
            $this->areTemplateOptionsFinalized = true;
            $this->prepareTemplateOptions();
        }

        $key  = 'template_options';
        $prop = $this->property($key);
        $val  = $this->propertyValue($key);
        $obj  = $prop->structureVal($val, $this->templateOptionsMetadata());

        return $obj;
    }
726959
public function parse()
    {
        $count = (int) $this->data;
        if ($count < 0) {
            return null;
        }

        $elements = [];
        for ($i=0; $i < $count; $i++) {
            $elements[$i] = call_user_func($this->receiver);
        }
        return $elements;
    }
392446
protected function parse()
    {
        $sectionName = static::GLOBAL_SECTION;
        $values = [];

        try {
            while ($line = fgets($this->handle)) {
                $this->linenumber++;
                $line = trim($line);
                if (empty($line) || substr($line, 0, 1) === ';') {
                    continue;
                }

                if ($this->isSectionHeader($line)) {
                    if ($sectionName === static::GLOBAL_SECTION) {
                        $this->config = $values;
                    } else {
                        $tokens = explode($this->delimiter, $sectionName);
                        $this->config = array_merge_recursive($this->config,
                                                              $this->subdivide($tokens, $values));

                        unset($tokens);
                    }

                    $sectionName = $this->getSectionHeader($line);
                    $values = [];
                    continue;
                }

                list($key, $value) = array_pad(preg_split(static::SPLIT_PATTERN, trim($line), 2), 2, '');

                if ($this->isArrayKey($key)) {
                    if (is_null($array_key = $this->parseArrayKey($key))) {
                        $key = trim(trim($key), '[]');

                        $values[$key][] = $this->parseValue($value);
                    } else {
                        $key = trim(substr($key, 0, strpos($key, '[')));
                        if (!isset($values[$key])) {
                            $values[$key] = [];
                        }

                        $values[$key][$array_key] = $this->parseValue($value);
                    }
                } else {
                    $values[trim($key)] = $this->parseValue($value);
                }
            }
        } catch (\Exception $ex) {
            throw new \RuntimeException("{$ex->getMessage()} Line: {$this->linenumber}.");
        } finally {
            $this->close();
        }

        if ($sectionName === static::GLOBAL_SECTION) {
            $this->config = $values;
        } else {
            $section = $this->subdivide(explode($this->delimiter, $sectionName), $values);
            $this->config = array_merge($this->config, $section);
        }
    }
1211493
public function parse() {
    $value = $this->getRawValue();
    $matches = [];
    if (is_array($value)) {
      return $value;
    }

    if (preg_match(self::NESTED_CONFIGURATION_REGEX, $value, $matches) === 1) {
      return $this->parseNestedValue($value, $matches);
    } else {
      return $this->parser->parseIntelligent($value);
    }
  }
1099555
public function parse()
    {
        if (is_object($this->xml)) {
            $this->attributes = Helper::getAttributesAsArray($this->getXml());
        }

        switch ($this->type) {
            case 'datetime':
                $this->content = new DateTime($this->xml_value);
                break;
            case 'time':
                $this->content = new DateTime;
                if (true===$this->getSetting('isHours')) {
                    $this->content->setTime($this->xml_value, 0);
                } elseif (true===$this->getSetting('isMinutes')) {
                    $this->content->setTime(0, $this->xml_value);
                } elseif (true===$this->getSetting('isSeconds')) {
                    $this->content->setTime(0, 0, $this->xml_value);
                }
                break;
            case 'text':
                $this->content = strip_tags($this->xml_value);
                break;
            case 'lang':
                $this->content = Locale::getDisplayLanguage($this->xml_value);
                break;
            case 'int': case 'integer':
                $this->content = (int) $this->xml_value;
                break;
            case 'bool': case 'boolean':
                $this->content = (bool) $this->xml_value;
                break;
            case 'list':
                $this->content = array();
                $type = isset($this->settings['listitem_type']) ? $this->settings['listitem_type'] : 'string';
                foreach ($this->xml_value as $_value) {
                    $this->content[] = new Item($type, $_value, $this->name, $this->settings);
                }
                break;
            default:
                $this->content = $this->xml_value;
                break;
        }
    }
873954
private function parse()
    {
        $this->parameters   = [];
        $this->pathSegments = [];
        $parsedUrl          = parse_url($this->returnValue);
        foreach ($parsedUrl as $key => $value) {
            if ($key == 'query') {
                parse_str($value, $this->parameters);
            } elseif ($key == 'path') {
                $this->pathSegments = ($value) ? explode('/', ltrim($value, '/')) : [];
            } else {
                $this->{$key} = $value;
            }
        }
        return $this;
    }
403378
protected function _parse()
    {
        $origCss = '';
        $length = 0;
        foreach (@file($this->_absoluteCssPath) as $line) {
            $origCss .= $line;
            $length += strlen($line);
            $this->_lines[] = $length;
        }
        $css = $origCss;
        $peek = 0;
        $block = null;

        // Consume all CSS data (blockwise)
        while ($peek < $length) {

            // Consume whitespace
            if (preg_match("%^(\s+)%isSu", $css, $whitespace)) {
                $block .= $whitespace[0];
                $peek += strlen($whitespace[0]);

                // Consume Block comment
            } else {
                if (!strncmp('/*', $css, 2)) {
                    $commentEnd = strpos($css, '*/', 2);

                    // If no comment end is found: Error
                    if ($commentEnd === false) {
                        throw new \Tollwerk\Squeezr\Exception(sprintf(\Tollwerk\Squeezr\Exception::UNBALANCED_BLOCK_COMMENT_STR,
                            $this->_peekToLine($peek)), \Tollwerk\Squeezr\Exception::UNBALANCED_BLOCK_COMMENT);
                    }

                    $commentLength = $commentEnd + 2;
                    $block .= substr($css, 0, $commentLength);
                    $peek += $commentLength;

                    // Consume @-rule
                } elseif (!strncmp('@', $css, 1)) {

                    // Determine the rule identifier
                    if (!preg_match("%^\@([\w\-]+)%", $css, $atRule)) {
                        throw new \Tollwerk\Squeezr\Exception(sprintf(\Tollwerk\Squeezr\Exception::INVALID_AT_RULE_IDENTIFIER_STR,
                            $this->_peekToLine($peek)), \Tollwerk\Squeezr\Exception::INVALID_AT_RULE_IDENTIFIER);
                    }

                    // Consume @-rule by identifier
                    switch ($atRule[1]) {

                        // @media rule
                        case 'media':
                            $declarationBlockStart = 0;
                            $declarationBlock = $this->_consumeDeclarationBlock($css, $peek, strlen($atRule[1]) + 1,
                                $declarationBlockStart);
                            $peek += strlen($declarationBlock);
                            $breakpoints = $this->_breakpoints(substr($css, 6, $declarationBlockStart - 6));

                            // If the @media query is squeezable
                            if (is_array($breakpoints)) {

                                // If there's already block data to be registered
                                if (strlen($block)) {
                                    $this->_registerBlock($block);
                                }

                                $this->_registerBlock($declarationBlock, $breakpoints);

                                // Else: Not a squeezable @media query, register as regular block
                            } else {
                                $block .= $declarationBlock;
                            }

                            break;

                        // @import rule: May contain media query, should be implemented
                        case 'import':

                            // Find the next line break or semicolon
                            if (preg_match("%[\r\n\;]%", $css, $delimiter, PREG_OFFSET_CAPTURE, strlen($atRule[1]))) {
                                $declarationBlock = substr($css, 0, $delimiter[0][1] + 1);

                                // Else: this must be the end of the data
                            } else {
                                $declarationBlock = $css;
                            }

                            $peek += strlen($declarationBlock);

                            // Examine the import rule
                            $import = trim(substr($declarationBlock, 7), ' ;');
                            foreach (self::$_importPatterns as $start => $pattern) {
                                if (!strncmp($start, $import, strlen($start)) && preg_match($pattern, $import,
                                        $importMediaQuery)
                                ) {
                                    $breakpoints = $this->_breakpoints($importMediaQuery[4]);

                                    // If the @import rule has a squeezable media query part
                                    if (is_array($breakpoints)) {

                                        // If there's already block data to be registered
                                        if (strlen($block)) {
                                            $this->_registerBlock($block);
                                        }

                                        $this->_registerBlock($declarationBlock, $breakpoints);
                                        break 2;
                                    }
                                }
                            }

                            $block .= $declarationBlock;
                            break;

                        // Single line @-rules (except @import)
                        case 'charset';
                        case 'namespace':

                            // Find the next line break or semicolon
                            if (preg_match("%[\r\n\;]%", $css, $delimiter, PREG_OFFSET_CAPTURE, strlen($atRule[1]))) {
                                $block .=
                                $declarationBlock = substr($css, 0, $delimiter[0][1] + 1);
                                $peek += strlen($declarationBlock);

                                // Else: this must be the end of the data
                            } else {
                                $block .= $css;
                                $peek += strlen($css);
                            }

                            break;

                        // Block @-rules (e.g. *-keyframes)
                        case 'page':
                        case 'font-face':
                        default:
                            $block .=
                            $declarationBlock = $this->_consumeDeclarationBlock($css, $peek, strlen($atRule[1]) + 1);
                            $peek += strlen($declarationBlock);
                            break;
                    }

                    // Consume declaration blocks
                } else {
                    $block .=
                    $declarationBlock = $this->_consumeDeclarationBlock($css, $peek);
                    $peek += strlen($declarationBlock);
                }
            }

            $css = substr($origCss, $peek);
        }

        // Register the last block (if any)
        if (strlen($block)) {
            $this->_registerBlock($block);
        }
    }