protected function parseFeature()
{
$token = $this->expectTokenType('Feature');
$title = trim($token['value']) ?: null;
$description = null;
$tags = $this->popTags();
$background = null;
$scenarios = array();
$keyword = $token['keyword'];
$language = $this->lexer->getLanguage();
$file = $this->file;
$line = $token['line'];
// Parse description, background, scenarios & outlines
while ('EOS' !== $this->predictTokenType()) {
$node = $this->parseExpression();
if (is_string($node)) {
$text = preg_replace('/^\\s{0,' . ($token['indent'] + 2) . '}|\\s*$/', '', $node);
$description .= (null !== $description ? "\n" : '') . $text;
continue;
}
if (!$background && $node instanceof BackgroundNode) {
$background = $node;
continue;
}
if ($node instanceof ScenarioInterface) {
$scenarios[] = $node;
continue;
}
if ($background instanceof BackgroundNode && $node instanceof BackgroundNode) {
throw new ParserException(sprintf('Each Feature could have only one Background, but found multiple on lines %d and %d%s', $background->getLine(), $node->getLine(), $this->file ? ' in file: ' . $this->file : ''));
}
if (!$node instanceof ScenarioNode) {
throw new ParserException(sprintf('Expected Scenario, Outline or Background, but got %s on line: %d%s', $node->getNodeType(), $node->getLine(), $this->file ? ' in file: ' . $this->file : ''));
}
}
return new FeatureNode(rtrim($title) ?: null, rtrim($description) ?: null, $tags, $background, $scenarios, $keyword, $language, $file, $line);
}