benjamin-hodgson/Pidgin

[Question] Syntax - Inside-out vs outside-in

Closed this issue · 2 comments

mgkr commented

This is purely "academical" (ie. I'm curious and like to play around)

The syntax of the below is what I would call inside-out: (matches ("Identifier") )

      Identifier
        .Between(Quotes)
        .Between(OpenParen, CloseParen);

Would there be any way of achieving an outside-in syntax instead: (the following won't work obviously - just as an easy example)

        .Between(OpenParen, CloseParen);
        .Between(Quotes)
        Identifier

The outside-in syntax lends itself better to how my brain works I guess - So would be nice to be able to work like that instead :-)
I wouldn't even mind if it involved a bit of (syntax or computational) overhead to achieve.

I’m afraid I don’t see myself ever adding something like this. I don’t have any bright ideas on how to implement syntax like that, and it’s quite at odds with how the library works today, to the point of being a different library.

It’s an interesting idea though! And you’re more than welcome to write your own library, I’d be interested to read about it.

mgkr commented

Completely fair.
I couldn't quite see how to achieve it either - Hence my post :-)