pest icon indicating copy to clipboard operation
pest copied to clipboard

Sharing rules between grammars?

Open waywardmonkeys opened this issue 6 years ago • 3 comments

I have a few grammars for related formats / languages that share some common rules. Is there a way to readily share rules between separate grammar files?

It wouldn't make sense to just have a single big grammar file.

In nom, I would be able to define new combinators that I'd use for things like basic types and such.

waywardmonkeys avatar Feb 19 '18 10:02 waywardmonkeys

Good point. There should be an import command in .pest files. This could be added in 1.1. Let me know if you want to tackle it.

dragostis avatar Feb 19 '18 11:02 dragostis

Could you provide a couple of getting started pointers and I will see if I can tackle it?

waywardmonkeys avatar Feb 19 '18 11:02 waywardmonkeys

Of course. The necessary grammar should be added to meta. Probably something like use generic.pest would do well.

Then this should be somehow integrated into the parser and validator in the meta crate. I'm not completely sure what the best approach would be in this case. My current hunch is to do the actual importing in parser::convert_rules, where one could call parse and validate recursively, but this might not work and a change in architecture may be needed.

dragostis avatar Feb 19 '18 12:02 dragostis