A Gherkin Lexer
Explore how to build a Gherkin lexer in Laravel by managing text indentation to structure and simplify parsing. Understand how breaking a Gherkin document into lines with relative indentation helps streamline parser implementation, making it easier to handle scenarios and features accurately.
We'll cover the following...
A lexer is an interesting topic when parsing text because it can often be confused with the parser itself. If we look at the Gherkin example in the code snippet below, we can see that there are a lot of individual characters and words, and it might be difficult to even figure out where we should start parsing this:
Operating directly on individual characters or entire words can be complicated from a parser’s perspective. It would be much more helpful if we could work on a higher-level structure instead. This is where a lexer comes in.
Because Gherkin is an ...