Behat\Gherkin\Parser::parseBackground PHP Method

parseBackground() protected method

Parses background token & returns it's node.
protected parseBackground ( ) : Behat\Gherkin\Node\BackgroundNode
return Behat\Gherkin\Node\BackgroundNode
    protected function parseBackground()
    {
        $token = $this->expectTokenType('Background');
        $title = trim($token['value']);
        $keyword = $token['keyword'];
        $line = $token['line'];
        if (count($this->popTags())) {
            throw new ParserException(sprintf('Background can not be tagged, but it is on line: %d%s', $line, $this->file ? ' in file: ' . $this->file : ''));
        }
        // Parse description and steps
        $steps = array();
        $allowedTokenTypes = array('Step', 'Newline', 'Text', 'Comment');
        while (in_array($this->predictTokenType(), $allowedTokenTypes)) {
            $node = $this->parseExpression();
            if ($node instanceof StepNode) {
                $steps[] = $this->normalizeStepNodeKeywordType($node, $steps);
                continue;
            }
            if (!count($steps) && is_string($node)) {
                $text = preg_replace('/^\\s{0,' . ($token['indent'] + 2) . '}|\\s*$/', '', $node);
                $title .= "\n" . $text;
                continue;
            }
            if ("\n" === $node) {
                continue;
            }
            if (is_string($node)) {
                throw new ParserException(sprintf('Expected Step, but got text: "%s"%s', $node, $this->file ? ' in file: ' . $this->file : ''));
            }
            if (!$node instanceof StepNode) {
                throw new ParserException(sprintf('Expected Step, but got %s on line: %d%s', $node->getNodeType(), $node->getLine(), $this->file ? ' in file: ' . $this->file : ''));
            }
        }
        return new BackgroundNode(rtrim($title) ?: null, $steps, $keyword, $line);
    }