diff --git a/src/Behat/Gherkin/Parser.php b/src/Behat/Gherkin/Parser.php index 101f324f..c290a9f2 100644 --- a/src/Behat/Gherkin/Parser.php +++ b/src/Behat/Gherkin/Parser.php @@ -550,13 +550,15 @@ protected function parseStep() */ protected function parseExamples() { - $token = $this->expectTokenType('Examples'); - - $keyword = $token['keyword']; - + $keyword = ($this->expectTokenType('Examples'))['keyword']; $tags = empty($this->tags) ? array() : $this->popTags(); + $table = $this->parseTableRows(); - return new ExampleTableNode($this->parseTableRows(), $keyword, $tags); + try { + return new ExampleTableNode($table, $keyword, $tags); + } catch(NodeException $e) { + $this->rethrowNodeException($e); + } } /** @@ -571,11 +573,7 @@ protected function parseTable() try { return new TableNode($table); } catch(NodeException $e) { - throw new ParserException( - $e->getMessage() . ($this->file ? ' in file '.$this->file : ''), - 0, - $e - ); + $this->rethrowNodeException($e); } } @@ -744,4 +742,13 @@ private function normalizeStepNodeKeywordType(StepNode $node, array $steps = arr } return $node; } + + private function rethrowNodeException(NodeException $e): void + { + throw new ParserException( + $e->getMessage() . ($this->file ? ' in file ' . $this->file : ''), + 0, + $e + ); + } }