Parsing Doc Strings

Learn how to parse doc strings using the Gherkin class.

We'll cover the following

Parsing doc strings

We will begin parsing some more complicated structures, starting with Gherkin’s doc strings. Let’s familiarize ourselves again with the doc string syntax:

Feature: Feature Name

  Scenario: Doc String Example One
    Given a blog post named "Random" with Markdown body
      """
      Some Title, Eh?
      ===============
      Here is the first paragraph of my blog post. Lorem ipsum dolor
      consectetur adipiscing elit.
      """

The strategy for parsing doc strings will be similar to our free-form descriptions. The basic method will be to scan each line and check to see if it starts with one of the two character sequences that indicate the start of a doc string: three double quotes or three backticks.

We will also need to remember which one of the two sequences we saw because we need to stop parsing our doc string when we see it again. Our implementation for parsing doc strings is as follows:

Get hands-on with 1200+ tech skills courses.