dlang-community / Pegged

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

`pure` and `@safe` grammars/rules? #303

Open Dechcaudron opened 3 years ago

Dechcaudron commented 3 years ago

Hi,

First of all thanks for the great library and for the good work that is still put into maintaining it. I would like to request an improvement, if possible.

Is there any chance grammar and rule functions can be made pure @safe? Conceptually I do not see any reason why they should not be, but there may be internal limitations I am not aware of.

Thanks in advance, Héctor

veelo commented 3 years ago

Hi Héctor,

I don't see a problem there either. @cbleser has done a lot of @safe work in #302, but I cannot merge that as it is failing tests. I am very much in favour of separating the @safe work out of that PR, as well as other refactorings, to keep things easy to review and not have progress stall because of unrelated problems. I am fine with combining @safe and pure in the same PR, though.

Even though it should be fairly straightforward, I am not sure when I would be able to add this myself. Feel free to have a go at it, I'll be happy to answer any questions regarding building Pegged. Beware that a number of files are generated, so make your edits at the right spot :-)

Cheers, Bastiaan.

Dechcaudron commented 3 years ago

Hi Bastiaan,

apologies for taking so long to reply. I'm currently working against the clock to meet some deadlines, so I will have to make due by calling unsafe-impure functions in debug conditional statements. I hope to be able to fix that in pegged once I finish what I have in my hands.

I would naïvely think the grammar template mixin is a good place to begin?

Regards, Héctor

veelo commented 3 years ago

I would naïvely think the grammar template mixin is a good place to begin?

I would naïvely think so too :-) Reuse from #302 where practical, and be sure to not change files that are generated (change the generator).