Search⌘ K
AI Features

Parsing Gherkin Tables

Explore how to parse complex Gherkin data tables by extracting and processing table rows and cells. Learn step-by-step methods using Laravel and PHP, including regular expressions and escape sequence handling, to effectively convert table data into structured objects for web applications.

We'll cover the following...

Parsing Gherkin data tables

We will now work to parse Gherkin data tables, which will be the most substantial structure we’ve parsed. It’s, in some ways, the most difficult to parse out of all of the different Gherkin elements. A Gherkin data table looks similar to a Markdown table, and each line starts and ends with a vertical pipe character, with each column also separated by a pipe character:

C++
Feature: Feature Name
Scenario Outline: eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |

Like with doc strings and free-form descriptions, we will want to gather all of the lines that should be part of our data table. For data tables, this will be all lines that begin with the | symbol. Once we have the individual ...