Parses comment tokens

@param TokenStream $stream TokenStream object
@param string      $type   Type of Node
760111
protected function parseComment(TokenStream $stream, $type)
    {
        while ($stream->skipType(array(Lexer::TOKEN_EOL, Lexer::TOKEN_WTSP))->is(Lexer::TOKEN_CMNT)) {
            $this->nodes[] = new Node($type, $stream->current()->getValue());
            $stream->next();
        }
    }
974465
public function parse($stream)
    {
        $tokeniser = new StreamTokeniser($this->csvFormat, $stream);
        $parser = new Parser();
        return $this->parseIterator(
            $parser->parse($tokeniser->getTokens())
        );
    }
672816
private function parseFragmentTypeAlias(Stream $stream)
    {
        $alias = $stream->expects(Token::TYPE_SYMBOL, '#')->getValue();

        while ($stream->current()->equals(Token::TYPE_SYMBOL, '[')) {
            $stream->expects(Token::TYPE_SYMBOL, '[');
            $stream->expects(Token::TYPE_SYMBOL, ']');

            $alias = sprintf('%s[]', $alias);
        }

        return $alias;
    }
1305587
protected function parseMethod(ClassBuilder $classBuilder, NodeStream $stream)
    {
        $builder = new MethodBuilder();
        $comments = array();
        $methodNodes = array(
            TokenParser::NODE_PUBLIC_METHOD => 'public',
            TokenParser::NODE_PROTECTED_METHOD => 'protected',
            TokenParser::NODE_PRIVATE_METHOD => 'private'
        );

        $node = $stream->expect(array_keys($methodNodes));
        $builder->setName($node->getValue());
        $builder->setVisibility($methodNodes[$node->getType()]);

        while ($stream->is(TokenParser::NODE_ARGUMENT)) {
            $argument = array();
            $argument[] = $stream->current()->getValue();
            $stream->next();
            if ($stream->is(TokenParser::NODE_ARGUMENT_TYPE)) {
                $argument[] = $stream->current()->getValue();
                $stream->next();
            } else {
                $argument[] = 'mixed';
            }
            $builder->addArgument($argument);
        }

        if ($stream->is(TokenParser::NODE_RETURN_TYPE)) {
            $builder->setType($stream->current()->getValue());
            $stream->next();
        }

        while ($stream->is(TokenParser::NODE_METHOD_COMMENT)) {
            $comments[] = $stream->current()->getValue();
            $stream->next();
        }

        if (count($comments) > 0) {
            $builder->setComments($comments);
        }

        $classBuilder->addMethod($builder);
    }
1027595
protected function validateAttributeOperator(TokenStream $stream, $attr): void
    {
        if (!$stream->test(Token::OPERATOR_TYPE, '=')) {
            throw new SyntaxError(sprintf('The attribute "%s" must be followed by "=" operator', $attr), $stream->getCurrent()->getLine(), $stream->getSourceContext());
        }
    }
852845
protected function parseEncounteredToken(\Twig_Token $token, \Twig_TokenStream $stream)
    {
        switch ($token->getValue()) {
            case 'lang':
                $this->attributes['lang'] = $this->parseLangOption($token, $stream);
                break;

            case 'format':
                $this->attributes['format'] = $this->parseFormatOption($token, $stream);
                break;

            case 'start':
                $this->attributes['start'] = $this->parseStartOption($token, $stream);
                break;

            case 'mark':
                $this->attributes['mark'] = $this->parseMarkOption($token, $stream);
                break;

            case 'linenos':
                $this->attributes['linenos'] = $this->parseLinenosOption($token, $stream);
                break;

            case 'class':
                $this->attributes['class'] = $this->parseClassOption($token, $stream);
                break;

            case 'title':
                $this->attributes['title'] = $this->parseTitleOption($token, $stream);
                break;

            case 'link':
                $this->attributes['linkUrl'] = $this->parseLinkOption($token, $stream);
                break;

            case 'link_text':
                $this->attributes['linkText'] = $this->parseLinkTextOption($token, $stream);
                break;
        }
    }
1043532
protected function setStream($type, StreamInterface $stream)
    {
        $this->streams[$type] = $stream;

        $callback = array($this, 'on'.ucfirst($type).'Message');

        $stream->addListener(
            StreamInterface::MESSAGE,
            $this->createEventListenerForStream($callback)
        );

        return $this;
    }
809493
protected function expectTokenType($type)
    {
        $types = (array) $type;
        if (in_array($this->predictTokenType(), $types)) {
            return $this->lexer->getAdvancedToken();
        }

        $token = $this->lexer->predictToken();

        throw new ParserException(sprintf(
            'Expected %s token, but got %s on line: %d%s',
            implode(' or ', $types),
            $this->predictTokenType(),
            $token['line'],
            $this->file ? ' in file: ' . $this->file : ''
        ));
    }
1355937
public function readBinaryStream($stream)
    {
        if (($str = stream_get_contents($stream)) === false || empty($str)) {
            throw new PListException("Error reading stream!");
        }

        $this->parseBinary($str);
    }
654564
protected function parseClass(ClassBuilder $builder, NodeStream $stream)
    {
        $node = $stream->expect(TokenParser::NODE_CLASS);
        $docblock = array();
        $builder->setClass($node->getValue());
        if ($stream->is(TokenParser::NODE_EXTENDS)) {
            $builder->setExtends($stream->current()->getValue());
            $stream->next();
        }
        while ($stream->is(TokenParser::NODE_IMPLEMENTS)) {
            $builder->addInterface($stream->current()->getValue());
            $stream->next();
        }
        while ($stream->is(TokenParser::NODE_CLASS_COMMENT)) {
            $docblock[] = $stream->current()->getValue();
            $stream->next();
        }

        if (count($docblock) > 0) {
            $builder->setDocblock($docblock);
        }

        $this->status = self::STAT_BODY;
    }
1368494
protected function getNextExpectedBoolValueFromStream(
        \Twig_TokenStream $stream,
        $optionName
    ) {
        $stream->next();
        $stream->expect(\Twig_Token::PUNCTUATION_TYPE);
        $expr = $this->parser->getExpressionParser()->parseExpression();

        if (!($expr instanceof \Twig_Node_Expression_Constant) || !is_bool($expr->getAttribute('value'))) {
            throw new SyntaxException(
                sprintf(
                    'The %s option must be boolean true or false (i.e. %s:false).',
                    $optionName,
                    $optionName
                ),
                $stream->getCurrent()->getLine(),
                $this->getStreamFilename($stream)
            );
        }

        return $expr->getAttribute('value');
    }
746794
private function parseArgumentList(Stream $stream)
    {
        $arguments = [];

        do {
            $argument = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();

            $stream->expects(Token::TYPE_SYMBOL, ':');

            if ($stream->current()->equals(Token::TYPE_SYMBOL, '#')) {
                $type = $this->parseFragmentTypeAlias($stream);
            } else {
                $type = $this->parseTypeAlias($stream);
            }

            $argument = [
                'argument' => $argument,
                'type' => $type,
            ];

            if ($stream->current()->equals(Token::TYPE_SYMBOL, '=')) {
                $stream->expects(Token::TYPE_SYMBOL, '=');

                $argument['default'] = $this->parseValue($stream);
            }

            $arguments[] = $argument;
        } while ($stream->current()->equals(Token::TYPE_SYMBOL, ',') && $stream->expects(Token::TYPE_SYMBOL, ','));

        return $arguments;
    }
918132
public function parse(TokenStream $stream)
    {
        while (!$stream->is(Lexer::TOKEN_EOF)) {
            if ($stream->is(Lexer::TOKEN_WTSP)) {
                $stream->next();
                continue;
            }

            switch ($this->status) {
                case self::STAT_NONE:
                    $this->parseClassDefinition($stream);
                    break;
                case self::STAT_CLASS_DEFINED;
                    $this->parseBody($stream);
                    break;
                default:
                    $stream->next();
                    break;
            }
        }
        $this->nodes[] = new Node(self::NODE_EON, null);

        return new NodeStream($this->nodes);
    }
207583
public function parse( Twig_Token $token ) {

		$nodes  = array();
		$parser = $this->parser;
		$stream = $parser->getStream();

		$stream->expect( Twig_Token::BLOCK_END_TYPE );
		$nodes['callback'] = $parser->subparse( array( $this, 'decide_comments_end' ), true );
		$stream->expect( Twig_Token::BLOCK_END_TYPE );

		return new Comments_Node( $nodes, array(), $token->getLine(), $this->getTag() );
	}
1023994
def _parse(self):
        
        try:
            # parse token stream into abstract syntax tree (AST)
            self._ast = self._rule_container()

        except ParseError:
            raise

        except Exception as exc:
            raise ParseError(u'Unexpected error: {0}'.format(unicode(exc)))
402953
public function parseText() : void
    {
        if (!count($this->stream->getTokens())) {
            return;
        }

        if ($this->accept(Token::T_TEXT)) {
            $this->insert(new TextNode($this->getCurrentToken()->getValue()));
            $this->advance();
        }
    }
270509
private function parseClass(Parser $parser, Stream $stream, $parentTemplate)
    {
        $oldClassNode = $parser->getCurrentClassNode();
        $fileNode     = $parser->getCurrentFileNode();

        /** @var $classNode ClassNode */
        $classNode = $fileNode->addClass(
            $fileNode->getNextEmbeddedTemplateName()
        );
        $classNode->setParentTemplate($parentTemplate);
        $parser->setCurrentClassNode($classNode);

        $classNode->addChild(
            $parser->parseBlock($stream, 'endembed'),
            ClassNode::MAIN_TEMPLATE_BLOCK
        );
        $stream->expect(Token::TAG_END);
        $parser->setCurrentClassNode($oldClassNode);

        return $classNode->getClassName();
    }