This month we have an online workshop thanks to Mathias Verraes, who will be showing us how we can build some pretty cool stuff in PHP.
Build Your Own Parser
Let’s write some parsers! We could do it by writing a lot of imperative code that manipulates strings using a ton of ifs and switches, but it turns out there’s a better way.
Parser combinators let you describe your parsers in plain PHP, by composing them from smaller parsers. The underlying library then takes care of actually running the parser, building the output data structures, and reporting errors in the input.
Because it’s basically a high level PHP DSL for writing parsers, the code you end up with is very readable, and very easy to evolve later. This makes parser combinators a great choice for doing anything from simple input validation, to reading weird old legacy file formats, to building a complete programming language from scratch.
If you want to code along, make sure your have an editor, PHP 7.4, and Composer.
Mathias Verraes runs a boutique consultancy that advises organisations on designing and modelling software for complex environments, including architecture, analysis, testing, and refactoring “unmaintainable” systems. He has worked with clients in Finance, Government, Supply Chain, Mobility, Energy, E-Commerce, and more. He teaches Domain-Driven Design courses and curates the DDD Europe conference. When he’s at home in Kortrijk, Belgium, he helps his two sons build crazy Lego contraptions.