protected function parseScenario()
{
$token = $this->expectTokenType('Scenario');
$title = trim($token['value']);
$tags = $this->popTags();
$keyword = $token['keyword'];
$line = $token['line'];
// Parse description and steps
$steps = array();
while (in_array($this->predictTokenType(), array('Step', 'Newline', 'Text', 'Comment'))) {
$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 ScenarioNode(rtrim($title) ?: null, $tags, $steps, $keyword, $line);
}