problem-solving icon indicating copy to clipboard operation
problem-solving copied to clipboard

Make grammars called from grammars more intuitive

Open alabamenhu opened this issue 3 years ago • 1 comments

There should be an easy way for one grammar to call another grammar.

Lately we've seen a number of people playing around a lot more with how one grammar can interact with another (for instance here and here.

As Raku adoption increases, we are no doubt likely to see many others attempting to do similar mixing and matching of grammars. Unfortunately, there are a number of different drawbacks with the different ways that this can be done today (including potential for namespace overlaps and seams in the match process), besides being maybe not the most intuitive thing.

Therefore, I'd propose that we support an easy-to-read and easy-to-access way for one grammar to integrate another grammar into itself.

(Note: I would not imagine that this is something that would even be looked at until 6.f)

alabamenhu avatar Feb 14 '22 23:02 alabamenhu

For reference, Rakudo internally handles the switch by way of a method called nibble. But that's an internal method not intended for use by regular coders. It has the advantage (over the technique I describe here), however, that the full parse tree is maintained since it hands over the cursor directly to the next language.

It would probably be most intuitive to users to be set up as a (pseudo)token, e.g., <foreign: Grammar, Actions>, but the naming would be a key issue. While I used foreign thinking about switching between different languages, a grammar might not necessarily be a language, and so a more general term would be better. Maybe external or other, or even just grammar. Anything chosen would have the (likely slim) possibility that a grammar in the wild already uses it.

Alternatively, a different syntax could be provided, but I'm not sure what that would be.

alabamenhu avatar Feb 14 '22 23:02 alabamenhu