dlang-community / Pegged

A Parsing Expression Grammar (PEG) module, using the D programming language.
534 stars 66 forks source link

Syntax wrappers #313

Open AntonC9018 opened 1 year ago

AntonC9018 commented 1 year ago

Digging through the syntax tree in search of certain nodes is not maintainable - the code becomes cryptic even for simple grammars. Is there a way to generate convenient type-safe wrappers for any syntactic construct? They can be done as wrappers over raw nodes.

For example: Usage with wrappers (manually written out) And the grammar + wrappers themselves:

The same code without said wrappers, with digging through the syntax tree done manually, inline

The way I did it is not necessarily optimal, but I think it's pretty plausible. From experience working with Roslyn, it's a real good thing.

AntonC9018 commented 1 year ago

Perhaps better switches for the options could be beneficial. Stuff kind of like SumType, but with tags.