Parsers are a key tool we use to convert program code or a data description into a form computers understand. We can build them using many different methods and approaches. We shall take a closer look at the method of building parsers using combinators. This approach originates from functional programming, where small and simple functions are combined to form complex ones. We want to find out if this way of writing code is easier and more transparent than the ``classic'' approach. We will implement a JSON parser based on the principle of combining. Initially, we will implement it fully functionally in the OCaml programming language and then in the Rust programming language, which is not fully functional. We will compare the Rust implementation with the classic approach using generators and finally a modern software library. We want to know if writing parsers is easier this way. It turns out that that this is true. However, we also discover that such an approach is not optimal for performance.
|