Pegs recently got an "event parser" feature that allows you to exactly this kind of thing: [https://nim-lang.org/docs/pegs.html#eventParser.t%2Cuntyped%2Cuntyped](https://nim-lang.org/docs/pegs.html#eventParser.t%2Cuntyped%2Cuntyped)
With this you can build a case statement for the different matching grammar elements very easily.