Get the latest tech news
How Janet's PEG module works
An in depth explanation of pegs and how they work.
Although the code is written in Janet, It can be translated directly to most programming languages as we make no special use of any data structures besides arrays and hashtables. This grammar will match "apple pie", "banana split", and "coconut cluster", but not "orange soda", "watermelon taffy", or "lemon snap". Janet's peg implementation does something very similar to this, although the syntax tree is first compiled to a bytecode form and validate for better speed.
Or read this on Hacker News