Parse a block of use declaration statements.
@return UseDeclarationBlockNode
547262
private function useBlock() {
    $node = new UseDeclarationBlockNode();
    $node->addChild($this->_use());
    while ($this->currentType === T_USE) {
      $this->matchHidden($node);
      $node->addChild($this->_use());
    }
    return $node;
  }
18656
function getDeclaration1() {
  const type = NodeType.DeclarationType;
  const token = tokens[pos];
  const line = token.ln;
  const column = token.col;
  const content = [];

  content.push(getProperty());
  if (checkS(pos)) content.push(getS());
  content.push(getPropertyDelim());
  if (checkS(pos)) content.push(getS());
  content.push(getValue());

  return newNode(type, content, line, column);
}
858478
protected function parse(): void
    {
        // add the root node
        $this->root = new HtmlNode('root');
        $activeNode = $this->root;
        while ( ! is_null($activeNode)) {
            $str = $this->content->copyUntil('<');
            if ($str == '') {
                $info = $this->parseTag();
                if ( ! $info['status']) {
                    // we are done here
                    $activeNode = null;
                    continue;
                }

                // check if it was a closing tag
                if ($info['closing']) {
                    $foundOpeningTag  = true;
                    $originalNode     = $activeNode;
                    while ($activeNode->getTag()->name() != $info['tag']) {
                        $activeNode = $activeNode->getParent();
                        if (is_null($activeNode)) {
                            // we could not find opening tag
                            $activeNode = $originalNode;
                            $foundOpeningTag = false;
                            break;
                        }
                    }
                    if ($foundOpeningTag) {
                        $activeNode = $activeNode->getParent();
                    }
                    continue;
                }

                if ( ! isset($info['node'])) {
                    continue;
                }

                /** @var AbstractNode $node */
                $node = $info['node'];
                $activeNode->addChild($node);

                // check if node is self closing
                if ( ! $node->getTag()->isSelfClosing()) {
                    $activeNode = $node;
                }
            } else if ($this->options->whitespaceTextNode ||
                trim($str) != ''
            ) {
                // we found text we care about
                $textNode = new TextNode($str, $this->options->removeDoubleSpace);
                $activeNode->addChild($textNode);
            }
        }
    }
691671
private function parse(){
        if(self::$parser === null){
            self::$parser   = (new ParserFactory())
                ->create(\PhpParser\ParserFactory::ONLY_PHP7);
        }

        $stmt   = self::$parser->parse(file_get_contents($this->path));

        if(!is_array($stmt)){
            throw new \LogicException;
        }

        $stmt   = array_filter($stmt, function($v){
            return $v instanceof \PhpParser\Node\Stmt\Namespace_;
        });

        if(empty($stmt)){
            throw new \LogicException;
        }

        $this->namespace    = implode("\\", $stmt[0]->name->parts);

        foreach($stmt[0]->stmts as $sub_stmt){
            if($sub_stmt instanceof \PhpParser\Node\Stmt\Use_
                || $sub_stmt instanceof \PhpParser\Node\Stmt\GroupUse
            ){
                $prefix = "";

                if($sub_stmt instanceof \PhpParser\Node\Stmt\GroupUse){
                    $prefix = $sub_stmt->prefix;
                }

                foreach($sub_stmt->uses as $use){
                    $name   = implode("\\", $use->name->parts);
                    $alias  = $use->alias;

                    if($prefix !== ""){
                        $name   = "{$prefix}\\{$name}";
                    }

                    $this->uses[$name]  = $alias;
                }
            }else if($sub_stmt instanceof \PhpParser\Node\Stmt\Class_){
                $this->class    = $sub_stmt->name;
            }
        }
    }
557846
protected function getBlockDefinitions() {
    $definitions = $this->blockManager->getSortedDefinitions();
    $block_definitions = [];
    foreach ($definitions as $plugin_id => $definition) {
      // Context aware plugins are not currently supported.
      // Core and component plugins can be context-aware
      // https://www.drupal.org/node/1938688
      // @see \Drupal\ctools\Plugin\Block\EntityView
      if (isset($definition['context'])) {
        continue;
      }

      $block_definitions[$plugin_id] = $definition;
    }
    return $block_definitions;
  }
422089
private function innerIfInnerStatementList() {
    static $terminators = [T_ELSEIF, T_ELSE, T_ENDIF];
    $node = new StatementBlockNode();
    while ($this->currentType !== NULL && !in_array($this->currentType, $terminators)) {
      $this->matchHidden($node);
      $node->addChild($this->innerStatement());
    }
    return $node;
  }
1167668
private function traitDeclaration() {
    $node = new TraitNode();
    $this->matchDocComment($node);
    $this->mustMatch(T_TRAIT, $node);
    $name_node = new NameNode();
    $this->mustMatch(T_STRING, $name_node, NULL, TRUE);
    $node->addChild($name_node, 'name');
    if ($this->currentType === T_EXTENDS) {
      throw new ParserException(
        $this->filename,
        $this->iterator->getLineNumber(),
        $this->iterator->getColumnNumber(),
        'Traits can only be composed from other traits with the \'use\' keyword.'
      );
    }
    if ($this->currentType === T_IMPLEMENTS) {
      throw new ParserException(
        $this->filename,
        $this->iterator->getLineNumber(),
        $this->iterator->getColumnNumber(),
        'Traits can not implement interfaces.'
      );
    }
    $this->matchHidden($node);
    $statement_block = new StatementBlockNode();
    $this->mustMatch('{', $statement_block, NULL, FALSE, TRUE);
    while ($this->currentType !== NULL && $this->currentType !== '}') {
      $this->matchHidden($statement_block);
      $statement_block->addChild($this->classStatement(TRUE));
    }
    $this->mustMatch('}', $statement_block, NULL, TRUE, TRUE);
    $node->addChild($statement_block, 'statements');
    return $node;
  }
194178
private function innerStatementBlock() {
    $node = new StatementBlockNode();
    $this->mustMatch('{', $node, NULL, FALSE, TRUE);
    $this->innerStatementList($node, '}');
    $this->mustMatch('}', $node, NULL, TRUE, TRUE);
    return $node;
  }
1345267
private function _declare() {
    $node = new DeclareNode();
    $this->mustMatch(T_DECLARE, $node);
    $this->mustMatch('(', $node, 'openParen');
    $directives = new CommaListNode();
    $node->addChild($directives, 'directives');
    if (!$this->tryMatch(')', $node, 'closeParen', FALSE, TRUE)) {
      do {
        $declare_directive = new DeclareDirectiveNode();
        $this->tryMatch(T_STRING, $declare_directive, 'name');
        if ($this->tryMatch('=', $declare_directive)) {
          $declare_directive->addChild($this->staticScalar(), 'value');
        }
        $directives->addChild($declare_directive);
      } while ($this->tryMatch(',', $directives));
      $this->mustMatch(')', $node, 'closeParen', FALSE, TRUE);
    }
    if ($this->tryMatch(':', $node, NULL, FALSE, TRUE)) {
      $node->addChild($this->innerStatementListNode(T_ENDDECLARE), 'body');
      $this->mustMatch(T_ENDDECLARE, $node);
      $this->endStatement($node);
      return $node;
    }
    else {
      $node->addChild($this->statement(), 'body');
      return $node;
    }
  }
1109304
protected function parseDocument()
    {
        $start = $this->token->getStart();
        $definitions = [];

        do {
            if ($this->peek(Token::BRACE_L_TYPE)) {
                $definitions[] = $this->parseOperationDefinition();
            } else if ($this->peek(Token::NAME_TYPE)) {
                $value = $this->token->getValue();
                if ($value === 'query' || $value === 'mutation') {
                    $definitions[] = $this->parseOperationDefinition();
                } else if ($value === 'fragment') {
                    $definitions[] = $this->parseFragmentDefinition();
                } else {
                    throw $this->unexpected();
                }
            } else {
                throw $this->unexpected();
            }
        } while (!$this->skip(Token::EOF_TYPE));

        return new Document($definitions, $this->location($start));
    }
1049475
public function parse($docblock)
    {
        // parse @key value
        preg_match_all('#@([a-zA-Z]+)(.*)(\*/|\n)#', $docblock, $out, PREG_SET_ORDER);

        // compile data
        $annotations = [];
        foreach($out as $row) {
            $key = trim($row[1]);
            $annotations[$key] = $this->resolveValue($row[2]);
        }

        return $annotations;
    }
450513
void parseBlock( FormattableContainer currentRule ) {
        Operation expr = null;
        String name = null;
        Expression guard = null;
        StringBuilder builder = cachesBuilder;
        boolean wasWhite = false;
        for( ;; ) {
            char ch = reader.read();
            switch( ch ) {
                case '{':
                    String selector;
                    if( name == null ) {
                        selector = trim( builder );
                    } else {
                        selector = name;
                        name = null;
                        throwUnrecognizedInputIfAny( builder, ch );
                    }
                    if( selector.endsWith( "@" ) ) { // selector with variable name like abc@{foo}abc
                        builder.append( selector );
                        builder.append( ch );
                        break;
                    }
                    if( selector.contains( ":extend(" ) ) {
                        selector = LessExtend.addLessExtendsTo( currentRule, reader, selector );
                    }
                    Rule rule = rule( currentRule, selector, expr, guard );
                    currentRule.add( rule );
                    expr = null;
                    guard = null;
                    String[] selectors = rule.getSelectors();
                    for( String sel : selectors ) {
                        currentRule.getMixins().add( sel.trim(), rule );
                    }
                    return;
                case '/':
                    if( !comment( isWhitespace( builder ) ? currentRule : null ) ) {
                        builder.append( ch );
                    }
                    wasWhite = false;
                    break;
                case '\"':
                case '\'':
                    readQuote( ch, builder );
                    wasWhite = false;
                    break;
                case '(':
                    String cmd;
                    if( name == null ) {
                        int idx = builder.lastIndexOf( " when" );
                        if( idx < 0 || (idx + 5 != builder.length() && builder.indexOf( " when " ) < 0) ) {
                            if( isSelector( builder ) || !reader.nextIsMixinParam( true ) ) {
                                builder.append( ch );
                                break;
                            }
                        }
                        name = trim( builder );
                        if( idx < 0 ) {
                            expr = parseParameterList();
                            break;
                        } else {
                            cmd = name.substring( idx + 1 );
                            name = name.substring( 0, idx );
                        }
                    } else {
                        cmd = trim( builder );
                    }
                    char operator;
                    boolean isNot = false;
                    switch( cmd ) {
                        case "when not":
                            isNot = true;
                            //$FALL-THROUGH$
                        case "when":
                            operator = 0;
                            break;
                        case "and not":
                            isNot = true;
                            //$FALL-THROUGH$
                        case "and":
                            operator = '&';
                            break;
                        case ",not":
                        case ", not":
                            isNot = true;
                            //$FALL-THROUGH$
                        case ",":
                            operator = '|';
                            break;
                        default:
                            throw createException( "Unrecognized input: '" + cmd + "'" );
                    }
                    Expression right = parseExpression( (char)0 );
                    ch = read();
                    if( ch != ')' ) {
                        throw createException( "Unrecognized input: '" + ch + "'" );
                    }
                    if( isNot ) {
                        right = new Operation( reader, right, '!' );
                    }
                    guard = ( operator == 0 ) ? right : concat( guard, operator, right );
                    break;
                default:
                    boolean isWhite = Character.isWhitespace( ch );
                    if( isWhite ) {
                        if( builder.length() == 0 ) {
                            break;
                        }
                        if( wasWhite ) {
                            break;
                        } else {
                            builder.append( ' ' );
                            wasWhite = true;
                        }
                    } else {
                        builder.append( ch );
                        wasWhite = false;
                    }
            }
        }
    }
63894
protected function parseCodeBlock()
    {
        $stream = $this->parser->getStream();

        while (!$stream->getCurrent()->test(\Twig_Token::BLOCK_END_TYPE)) {
            $this->parseEncounteredToken($stream->getCurrent(), $stream);
        }

        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
        $this->body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
        $stream->expect(\Twig_Token::BLOCK_END_TYPE);
    }
249370
public function parseCoverAnnotationDocBlock($docBlock)
    {
        $annotations = array('covers' => array(), 'uses' => array());
        $docBlock = substr($docBlock, 3, -2);
        if (preg_match_all('/@(?P<name>[A-Za-z_-]+)(?:[ \t]+(?P<value>.*?))?[ \t]*\r?$/m', $docBlock, $matches)) {
            $numMatches = count($matches[0]);
            for ($i = 0; $i < $numMatches; ++$i) {
                $annotations[$matches['name'][$i]][] = $matches['value'][$i];
            }
        }
        array_walk_recursive(
            $annotations,
            function(&$element) {
                if (substr($element, 0, 1) === '\\') {
                    $element = substr($element, 1);
                }
            }
        );
        return $annotations;
    }
1067637
protected function parseBlocks()
    {
        $this->blocks = array();
        $currentBlock = '';
        // Do we need insideSingleLineBlock? It doesn't seem to be used anywhere
        // Original Ruby version of KSS had it but I'm not seeing a purpose to it
        $insideSingleLineBlock = false;
        $insideMultiLineBlock = false;

        foreach ($this->file as $line) {
            $isSingleLineComment = self::isSingleLineComment($line);
            $isStartMultiLineComment = self::isStartMultiLineComment($line);
            $isEndMultiLineComment = self::isEndMultiLineComment($line);

            if ($isSingleLineComment) {
                $parsed = self::parseSingleLineComment($line);

                if ($insideSingleLineBlock) {
                    $currentBlock .= "\n";
                } else {
                    $insideSingleLineBlock = true;
                }

                $currentBlock .= $parsed;
            }

            if ($isStartMultiLineComment || $insideMultiLineBlock) {
                $parsed = self::parseMultiLineComment($line);

                if ($insideMultiLineBlock) {
                    $currentBlock .= "\n";
                } else {
                    $insideMultiLineBlock = true;
                }

                $currentBlock .= $parsed;
            }

            if ($isEndMultiLineComment) {
                $insideMultiLineBlock = false;
            }

            // If we're not in a comment then end the current block and go to
            // the next one
            if (!$isSingleLineComment && !$insideMultiLineBlock) {
                if (!empty($currentBlock)) {
                    $this->blocks[] = $this->normalize($currentBlock);
                    $insideSingleLineBlock = false;
                    $currentBlock = '';
                }
            }
        }

        $this->parsed = true;
        return $this->blocks;
    }
719942
function() {
    var tok = this.expect('block');

    var node = 'indent' == this.peek().type
      ? this.block()
      : this.emptyBlock(tok.line);
    node.type = 'NamedBlock';
    node.name = tok.val.trim();
    node.mode = tok.mode;
    node.line = tok.line;

    return node;
  }
183122
protected function parseCode()
    {
        $brace_level      = 0;
        $parsed_code      = '';
        $parsing_complete = false;

        // Parse the code looking for the end of the function
        /** @var $token \FunctionParser\Token */
        foreach ($this->tokenizer as $token)
        {
            /***********************************************************************************************************
             * AFTER PARSING
             *
             * After the parsing is complete, we need to make sure there are no other T_FUNCTION tokens found, which
             * would indicate a possible ambiguity in the function code we retrieved. This should only happen in
             * situations where the code is minified or poorly formatted.
             */
            if ($parsing_complete)
            {
                if ($token->is(T_FUNCTION))
                {
                    throw new \RuntimeException('Cannot parse the function; multiple, non-nested functions were defined'
                        . ' in the code block containing the desired function.');
                }
                else
                {
                    continue;
                }
            }

            /***********************************************************************************************************
             * WHILE PARSING
             *
             * Scan through the tokens (while keeping track of braces) and reconstruct the code from the parsed tokens.
             */

            // Keep track of opening and closing braces
            if ($token->isOpeningBrace())
            {
                $brace_level++;
            }
            elseif ($token->isClosingBrace())
            {
                $brace_level--;

                // Once we reach the function's closing brace, mark as complete
                if ($brace_level === 0)
                {
                    $parsing_complete = true;
                }
            }

            // Reconstruct the code token by token
            $parsed_code .= $token->code;
        }

        /*
         * If all tokens have been looked at and the closing brace was not found, then there is a
         * problem with the code defining the Closure. This should probably never happen, but just
         * in case...
         */
        if (!$parsing_complete)
        {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException('Cannot parse the function because the code appeared to be invalid.');
            // @codeCoverageIgnoreEnd
        }

        return $parsed_code;
    }