Building a simple query parser using PEG in Go
In another post, Simple Query Parser we had built a simple query parser using Participle - a parser builder for go lang. Parsing expression grammar (PEG) is a type of grammar. The advantage of PEG is that it doesn’t tolerate ambiguous grammar definitions and so is better in error reporting. The go language port of PEG is pigeon The popular Javascript port of PEG is pegjs. A good introduction to PEG grammar can be found in the pegjs documentation and also here.
Let's build a search query parser in Go
Mini languages are great. Makes it easy to express what you want in a concise manner. Sometimes a complex UI can be replaced with a mini-language. Some time back, google used to support a simple language in the search queries. For example: “some phrase” +required -not_required . Alas! they stopped it and Google search is less cool ever since. I would count regular expressions also as a mini-language. Imagine we are building an online store that allows searching for products using a simple but structured query language.