Parse the if, elseif or else branch starting at current index

Ends at the last }

@return array Branch's data ("structure", "head", "body", "tail")
18197
protected function parseBranch()
	{
		// Record the control structure
		$structure = $this->captureStructure();

		// Record the output expressions at the start of this branch
		$head = $this->captureOutput();
		$body = '';
		$tail = [];

		$braces = 0;
		do
		{
			$tail = $this->mergeOutput($tail, array_reverse($this->captureOutput()));
			if ($this->tokens[$this->i] === '}' && !$braces)
			{
				break;
			}

			$body .= $this->serializeOutput(array_reverse($tail));
			$tail  = [];

			if ($this->tokens[$this->i][0] === T_IF)
			{
				$child = $this->parseIfBlock();

				// If this is the start of current branch, what's been optimized away and moved
				// outside, before the child branch is the head of this one. Otherwise it's just
				// part of its body
				if ($body === '')
				{
					$head = $this->mergeOutput($head, $child['before']);
				}
				else
				{
					$body .= $this->serializeOutput($child['before']);
				}

				$body .= $child['source'];
				$tail  = $child['after'];
			}
			else
			{
				$body .= $this->serializeToken($this->tokens[$this->i]);

				if ($this->tokens[$this->i] === '{')
				{
					++$braces;
				}
				elseif ($this->tokens[$this->i] === '}')
				{
					--$braces;
				}
			}
		}
		while (++$this->i < $this->cnt);

		return [
			'structure' => $structure,
			'head'      => $head,
			'body'      => $body,
			'tail'      => $tail
		];
	}
1113141
public function parseBehatOutput()
    {
        $output = $this->phpci->getLastOutput();

        $parts = explode('---', $output);

        if (count($parts) <= 1) {
            return array(0, array());
        }

        $lines = explode(PHP_EOL, $parts[1]);

        $storeFailures = false;
        $data = array();

        foreach ($lines as $line) {
            $line = trim($line);
            if ($line == 'Failed scenarios:') {
                $storeFailures = true;
                continue;
            }

            if (strpos($line, ':') === false) {
                $storeFailures = false;
            }

            if ($storeFailures) {
                $lineParts = explode(':', $line);
                $data[] = array(
                    'file' => $lineParts[0],
                    'line' => $lineParts[1]
                );

                $this->build->reportError(
                    $this->phpci,
                    'behat',
                    'Behat scenario failed.',
                    BuildError::SEVERITY_HIGH,
                    $lineParts[0],
                    $lineParts[1]
                );
            }
        }

        $errorCount = count($data);

        return array($errorCount, $data);
    }
1240576
public function parse()
    {
        if (preg_match_all($this->pattern, $this->originalString, $matches, PREG_SET_ORDER)) {
            $this->parsed = [];
            foreach ($matches as $match) {
                $code = explode(';', static::$colorMaps[$match['color']]);
                $parsed = [];
                if ($match['prefix']) {
                    $parsed = array_merge($parsed, $this->parseLine($match['prefix']));
                }
                $parsed = array_merge($parsed, $this->parseLine($match['str'], $code[1]));
                if ($match['suffix']) {
                    $parsed = array_merge($parsed, $this->parseLine($match['suffix']));
                }
                /*
                $this->parsed = array_merge(
                    $this->parsed,
                    // $this->parseLine($match['prefix']),
                    $this->parseLine($match['str'], $code[1])
                    // $this->parseLine($match['suffix'])
                );
                */
               $this->parsed = array_merge($this->parsed, $parsed);
            }
        } else {
            $this->parsed = $this->parseLine($this->originalString, null);
        }

        return $this;
    }
511472
protected function parseSorting(){
		$order = array();
		foreach($this->stmt->getSorting() as $rule){
			list($field, $type) = $rule;
			$order[] = $this->tryDelimite($field) . ($type !== null ? ' ' . $type : '');
		}
		return "\nORDER BY " . implode(', ', $order);
	}
937568
public function parse()
    {
        /**
         * Last transaction.
         *
         * @var TransactionStatement
         */
        $lastTransaction = null;

        /**
         * Last parsed statement.
         *
         * @var Statement
         */
        $lastStatement = null;

        /**
         * Union's type or false for no union.
         *
         * @var bool|string
         */
        $unionType = false;

        /**
         * The index of the last token from the last statement.
         *
         * @var int
         */
        $prevLastIdx = -1;

        /**
         * The list of tokens.
         *
         * @var TokensList
         */
        $list = &$this->list;

        for (; $list->idx < $list->count; ++$list->idx) {
            /**
             * Token parsed at this moment.
             *
             * @var Token
             */
            $token = $list->tokens[$list->idx];

            // `DELIMITER` is not an actual statement and it requires
            // special handling.
            if (($token->type === Token::TYPE_NONE)
                && (strtoupper($token->token) === 'DELIMITER')
            ) {
                // Skipping to the end of this statement.
                $list->getNextOfType(Token::TYPE_DELIMITER);
                $prevLastIdx = $list->idx;
                continue;
            }

            // Counting the brackets around statements.
            if ($token->value === '(') {
                ++$this->brackets;
                continue;
            }

            // Statements can start with keywords only.
            // Comments, whitespaces, etc. are ignored.
            if ($token->type !== Token::TYPE_KEYWORD) {
                if (($token->type !== Token::TYPE_COMMENT)
                    && ($token->type !== Token::TYPE_WHITESPACE)
                    && ($token->type !== Token::TYPE_OPERATOR) // `(` and `)`
                    && ($token->type !== Token::TYPE_DELIMITER)
                ) {
                    $this->error(
                        'Unexpected beginning of statement.',
                        $token
                    );
                }
                continue;
            }

            if (($token->keyword === 'UNION') ||
                    ($token->keyword === 'UNION ALL') ||
                    ($token->keyword === 'UNION DISTINCT') ||
                    ($token->keyword === 'EXCEPT') ||
                    ($token->keyword === 'INTERSECT')
            ) {
                $unionType = $token->keyword;
                continue;
            }

            // Checking if it is a known statement that can be parsed.
            if (empty(static::$STATEMENT_PARSERS[$token->keyword])) {
                if (! isset(static::$STATEMENT_PARSERS[$token->keyword])) {
                    // A statement is considered recognized if the parser
                    // is aware that it is a statement, but it does not have
                    // a parser for it yet.
                    $this->error(
                        'Unrecognized statement type.',
                        $token
                    );
                }
                // Skipping to the end of this statement.
                $list->getNextOfType(Token::TYPE_DELIMITER);
                $prevLastIdx = $list->idx;
                continue;
            }

            /**
             * The name of the class that is used for parsing.
             *
             * @var string
             */
            $class = static::$STATEMENT_PARSERS[$token->keyword];

            /**
             * Processed statement.
             *
             * @var Statement
             */
            $statement = new $class($this, $this->list);

            // The first token that is a part of this token is the next token
            // unprocessed by the previous statement.
            // There might be brackets around statements and this shouldn't
            // affect the parser
            $statement->first = $prevLastIdx + 1;

            // Storing the index of the last token parsed and updating the old
            // index.
            $statement->last = $list->idx;
            $prevLastIdx = $list->idx;

            // Handles unions.
            if (! empty($unionType)
                && ($lastStatement instanceof SelectStatement)
                && ($statement instanceof SelectStatement)
            ) {
                /*
                 * This SELECT statement.
                 *
                 * @var SelectStatement $statement
                 */

                /*
                 * Last SELECT statement.
                 *
                 * @var SelectStatement $lastStatement
                 */
                $lastStatement->union[] = [
                    $unionType,
                    $statement,
                ];

                // if there are no no delimiting brackets, the `ORDER` and
                // `LIMIT` keywords actually belong to the first statement.
                $lastStatement->order = $statement->order;
                $lastStatement->limit = $statement->limit;
                $statement->order = [];
                $statement->limit = null;

                // The statement actually ends where the last statement in
                // union ends.
                $lastStatement->last = $statement->last;

                $unionType = false;

                // Validate clause order
                $statement->validateClauseOrder($this, $list);
                continue;
            }

            // Handles transactions.
            if ($statement instanceof TransactionStatement) {
                /*
                 * @var TransactionStatement
                 */
                if ($statement->type === TransactionStatement::TYPE_BEGIN) {
                    $lastTransaction = $statement;
                    $this->statements[] = $statement;
                } elseif ($statement->type === TransactionStatement::TYPE_END) {
                    if ($lastTransaction === null) {
                        // Even though an error occurred, the query is being
                        // saved.
                        $this->statements[] = $statement;
                        $this->error(
                            'No transaction was previously started.',
                            $token
                        );
                    } else {
                        $lastTransaction->end = $statement;
                    }
                    $lastTransaction = null;
                }

                // Validate clause order
                $statement->validateClauseOrder($this, $list);
                continue;
            }

            // Validate clause order
            $statement->validateClauseOrder($this, $list);

            // Finally, storing the statement.
            if ($lastTransaction !== null) {
                $lastTransaction->statements[] = $statement;
            } else {
                $this->statements[] = $statement;
            }
            $lastStatement = $statement;
        }
    }
503083
protected function conclude(): ?string
    {
        $types = array_values($this->types);

        // Reset
        $this->types = [];
        $this->value = null;

        if (count($types) < 2) {
            return reset($types) ?: null;
        }

        if (
            count($types) === 2 &&
            (is_a($types[0], \Traversable::class, true) xor is_a($types[1], \Traversable::class, true))
        ) {
            $args = is_a($types[0], \Traversable::class, true) ? $types : array_reverse($types);
            return vsprintf('%s|%s[]', $args);
        }

        return null;
    }
301087
final protected function parseRow(): void
    {
        // only parse the next row if only one in buffer
        if (\count($this->bufferedRow) > 1) {
            return;
        }
        if (feof($this->file)) {
            $this->currentRow = null;

            return;
        }

        $this->currentRowEnded = false;
        // read file until row is ended
        while (!$this->currentRowEnded && !feof($this->file)) {
            $data = fread($this->file, 1024);
            xml_parse($this->parser, $data);
        }
    }
425659
protected function parseAlt() {
    if (is_object($this->file)) {
      if (isset($this->file->alt)) {
        return $this->file->alt;
      }
    }

    if (is_array($this->file)) {
      if (isset($this->file['alt'])) {
        return $this->file['alt'];
      }
    }

    return '';
  }
660936
protected function parseAll()
    {
        if (!empty($this->parameter)) {
            return $this->parameter;
        }

        $this->parseParameter();
        $this->parseSource();
        $this->parseFilter();
    }
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);
        }
    }
159148
public function _endif()
    {
        if (!$this->conditionalProxy) {
            throw new PropelException('_endif() must be called after _if()');
        }

        $this->conditionalProxy = $this->conditionalProxy->getParentProxy();

        if ($this->conditionalProxy) {
            return $this->conditionalProxy->getCriteriaOrProxy();
        }

        // reached last level
        return $this;
    }
1090920
public function parse() : array
    {
        $buffer = $this->routing_rule;
        
        $section_list_set = [];
        $current_list = [];
        do
        {
            $pos = strpos(substr($buffer,1),'/');
            $section = $pos !== false ? substr($buffer, 1, $pos) : substr($buffer, 1);
            $buffer = $pos !== false ? substr($buffer, $pos + 1) : '';
            
            $length = strlen($section);
            if ($length === 0){
                $current_list[] = new class implements EmptyRoutingPathInterface {};
                if (!empty($buffer)){
                    throw new RoutingRuleParseException($this->routing_rule, "Empty routing section is allowed only for last element");
                }
                break;
            }
            $first = $section[0];
            $last = $section[$length - 1];
            if ($first === '[' && $last === ']'){
                // push current list
                $section_list_set[] = $current_list + ['()'];
                // add optional part to current list
                $inside = substr($section, 1, $length - 2);
                if ($inside[0] === ':') {
                    $current_list[] = self::parseVariablePattern($inside);
                }
                else {
                    $current_list[] = $inside;
                }
            }
            else if ($first === ':') {
                $current_list[] = self::parseVariablePattern($section);
            }
            else {
                $current_list[] = $section;
            }
        }
        while(!empty($buffer));
        
        $section_list_set[] = $current_list;
        return $section_list_set;
    }
1352183
private function parseRule()
    {
        $newToken = $this->tokens[$this->index];
        $set = false;
        if ($this->index > 0) {
            $prevToken = &$this->tokens[$this->index-1];
            $prevTokenType = &$prevToken[0];
            $prevTokenText = &$prevToken[1];
            $concat = false;

            $map = array(
                'DOT' => 'CLASS_SELECTOR',
                'HASH' => 'ID_SELECTOR',
                'COLON' => 'PSEUDO_SELECTOR',
                'DOUBLE_COLON' => 'PSEUDO_SELECTOR'
            );
            if (isset($map[$prevTokenType])) {
                // mark the prev token for deletion and concat into one.
                $newToken[0] = $map[$prevTokenType];
                $prevTokenType = self::$deleteToken;
                $newToken[1] = $prevTokenText . $newToken[1];
                $set = true;
            }
        }
        if (!$set) {
            // must be an element
            $newToken[0] = 'ELEMENT_SELECTOR';
        }
        $this->tokens[$this->index] = $newToken;
    }
40927
public function parse()
    {
        $where = [];

        foreach ($this->where as $key => $val) {
            if ($val instanceof Expression) {
                $where[] = [$key, 'exp', $val];
            } elseif (is_null($val)) {
                $where[] = [$key, 'NULL', ''];
            } elseif (is_array($val)) {
                $where[] = $this->parseItem($key, $val);
            } else {
                $where[] = [$key, '=', $val];
            }
        }

        return $this->enclose ? [$where] : $where;
    }
944489
protected function parseIncludes()
	{
		$includes = ['this' => [], 'forward' => []];

		foreach($this->model->getIncludes() as $include => $criteria)
		{
			if(is_numeric($include))
			{
				$include  = $criteria;
				$criteria = null;
			}

			if(($position = strpos($include, '.')) === false)
			{
				$includes['this'][$include] = $criteria;
			}
			else
			{
				if($criteria === null)
				{
					$includes['forward'][substr($include, 0, $position)][] = substr($include, $position + 1);
				}
				else
				{
					$includes['forward'][substr($include, 0, $position)][substr($include, $position + 1)] = $criteria;
				}
			}
		}

		return $includes;
	}
779085
public function parse() : array
    {
        $fileLines = $this->getFileLines();

        $data = [];

        $currentSection  = '';
        $currentDivision = '';

        for ($line = 0, $count = count($fileLines); $line < $count; ++$line) {
            $currentLine       = ($fileLines[$line]);
            $currentLineLength = mb_strlen($currentLine);

            if (0 === $currentLineLength) {
                continue;
            }

            if (';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;' === mb_substr($currentLine, 0, 40)) {
                $currentDivision = trim(mb_substr($currentLine, 41));

                continue;
            }

            // We only skip comments that *start* with semicolon
            if (';' === $currentLine[0]) {
                continue;
            }

            if ('[' === $currentLine[0]) {
                $currentSection = mb_substr($currentLine, 1, ($currentLineLength - 2));

                continue;
            }

            $bits = explode('=', $currentLine);

            if (2 < count($bits)) {
                throw new \RuntimeException("Too many equals in line: {$currentLine}, in Division: {$currentDivision}");
            }

            if (2 > count($bits)) {
                $bits[1] = '';
            }

            $data[$currentSection][$bits[0]]   = $bits[1];
            $data[$currentSection]['Division'] = $currentDivision;
        }

        if ($this->shouldSort()) {
            $data = $this->sortArrayAndChildArrays($data);
        }

        $this->data = $data;

        return $data;
    }
264848
protected function parse()
    {
        if ($this->hasElement()) {
            return $this->getElement();
        }

        $stack = [];
        foreach ($this->stack as $offset => $where) {
            $stack[$offset] = $where->parse();
        }

        return sprintf('(%s)', join(sprintf(' %s ', $this->operator), $stack));
    }