Less writing with local projections

I like the idea of compact grammar even more after discovering two dead productions in Skila grammar — nothing lethal, I was simply annoyed that because of the former verbosity some unnecessary rules slipped in. Like having rule “(...)*” and later wrapping it with this-or-nothing proxy.

Thus the addition of local projections — they help reducing the number of productions even more:

params_ -> (COMMA- p:param ~ {p.ToUpperCase()})*
           { new Parameters(currCoords(),p) };

The tile character and attached code tells NLT to apply given projection while building a list — in main action “p” means entire list, while in local projection the same “p” means just single (current) element.

Local projection is not limited to running type. One could change it as well:

params_ -> (COMMA- 
            p:param ~ <RichStr>{ new RichStr(p)})*
           { new Parameters(currCoords(),p) };

In this case we added info (within angle brackets) about the result type — otherwise it would be assumed it is still a “string”.

This last feature resulted in syntax change of altogether groups — from “<...>” to “[...]&”.

Tagged ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: