![]() ![]() To illustrate working with parser combinators, we'll work on transforming a string representation of a Dutch phone number into a canonical representation. Writing them is error-prone, they're challenging to maintain, and their format doesn't lend itself well to documentation/explanation. In contrast, regular expressions are often a poor choice for non-trivial parsing. You're less likely to make mistakes, and the parsers are a lot easier to maintain due to better readability. In effect, parser combinators enable the writing of complex parsers from simpler ones. So what are parser combinators? Well, as their name implies, they are parsers that can be combined - to make bigger, better parsers. Let's get into it! Parser Combinators: The What, How, and Why In other words, when talking about transforming text into structured data, we essentially mean parsing. In this two-part article, we'll explore how they work.īefore moving on, let's define what 'parsing' is:Ī parser is a software component that takes input data (frequently text) and builds a data structure. Most often, we'll reach for regular expressions to accomplish this task, but sometimes there's a better solution to the problem: parser combinators. The need to manipulate strings comes up quite often, whether it's to validate user-provided values or transform text into structured data that can be used programmatically.
0 Comments
Leave a Reply. |