diff --git a/src/Behat/Gherkin/Parser.php b/src/Behat/Gherkin/Parser.php index 66b0e596..c290a9f2 100644 --- a/src/Behat/Gherkin/Parser.php +++ b/src/Behat/Gherkin/Parser.php @@ -11,6 +11,7 @@ namespace Behat\Gherkin; use Behat\Gherkin\Exception\LexerException; +use Behat\Gherkin\Exception\NodeException; use Behat\Gherkin\Exception\ParserException; use Behat\Gherkin\Node\BackgroundNode; use Behat\Gherkin\Node\ExampleTableNode; @@ -549,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); + } } /** @@ -565,7 +568,13 @@ protected function parseExamples() */ protected function parseTable() { - return new TableNode($this->parseTableRows()); + $table = $this->parseTableRows(); + + try { + return new TableNode($table); + } catch(NodeException $e) { + $this->rethrowNodeException($e); + } } /** @@ -733,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 + ); + } } diff --git a/tests/Behat/Gherkin/Cucumber/CompatibilityTest.php b/tests/Behat/Gherkin/Cucumber/CompatibilityTest.php index bd7d74fb..76d7a0c7 100644 --- a/tests/Behat/Gherkin/Cucumber/CompatibilityTest.php +++ b/tests/Behat/Gherkin/Cucumber/CompatibilityTest.php @@ -43,7 +43,6 @@ class CompatibilityTest extends TestCase ]; private $parsedButShouldNotBe = [ - 'inconsistent_cell_count.feature' => 'Inconsistent cells count throws low level exception not ParserException', 'invalid_language.feature' => 'Invalid language is silently ignored', 'whitespace_in_tags.feature' => 'Whitespace in tags is tolerated', ];