p4-spec icon indicating copy to clipboard operation
p4-spec copied to clipboard

Use Madoko INCLUDE directive for grammar excerpts within the spec

Open jfingerh opened this issue 3 years ago • 4 comments

jfingerh avatar Dec 10 '22 04:12 jfingerh

Note: This PR intentionally only uses the Madoko INCLUDE directive for 4 or 5 of the grammar excerpts in the specification. Many more could be similarly done like this, but this PR was created quickly merely as an example of what could be done throughout the specification, so that spec maintainers can see what the resulting Madoko file would look like.

jfingerh avatar Dec 10 '22 04:12 jfingerh

We have to be careful, often we don't show the full production

mihaibudiu avatar Dec 10 '22 04:12 mihaibudiu

Is there a strong reason not to show the full production, in some cases? Is it primarily for focusing on a few of the production rules being presented in that section of the spec?

jfingerh avatar Dec 10 '22 15:12 jfingerh

That's right

mihaibudiu avatar Dec 10 '22 16:12 mihaibudiu

After 3 commits on this PR, I have replaced all occurrences of grammar rule definitions in the file P4-16-spec.mdk with Madoko INCLUDE directives, but ONLY for the ones where the definition in the file grammar.mdk was functionally identical to the one that resulted from replacing it with the INCLUDE statement. Usually this was also textually identical, but in a few cases the order of some of the alternatives was different, but I left them in the order they were in the grammar.mdk file, because with recent changes made there, those orders match the order of corresponding grammar rules in p4c, for easier text-based comparison between p4c and grammar.mdk.

There are only about 10 or so grammar rules left as they were in P4-16-spec.mdk. Those are either the ones that were partial rules, or were in some other way not functionally identical with the ones in grammar.mdk. Those we could consider whether they should become identical between them, but not in this PR.

jfingerh avatar Dec 10 '22 18:12 jfingerh

I reviewed one more time the grammar rules in P4-16-spec.mdk that had NOT yet been replaced with Madoko INCLUDE directives, and found 3 more that were equivalent between the two, and thus also replaced them with INCLUDE directives.

There remain only 3 non-terminal definitions in P4-16-spec.mdk that are not identical to the corresponding definition in grammar.mdk, and also do not appear to be excerpts. I will file a separate issue on the spec to record those, in case someone wants to think about how to address them.

In the mean time, since this PR makes no functional changes to the spec, only in how the Madoko source looks in producing it, I will go ahead and merge this in with Mihai's one approval.

jfingerh avatar Dec 12 '22 22:12 jfingerh