Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to control trailing tokens when doing layer unpacking #21

Closed
msjyoo opened this issue Feb 6, 2016 · 7 comments
Closed

Allow to control trailing tokens when doing layer unpacking #21

msjyoo opened this issue Feb 6, 2016 · 7 comments

Comments

@msjyoo
Copy link

msjyoo commented Feb 6, 2016

In a macro expansion such as

function (·vars ··· { ·var , }) { return ·expr; }

It is impossible to specify the correct amount of commas (to my knowledge of YAY functionality) - the last match will always add a trailing comma which is invalid syntax.

On function calls this can be alleviated by using array destructuring ...[var, var, var, ] but function definitions do not have this workaround.

@marcioAlmada
Copy link
Owner

This one is listed on the roadmap issue #3. Basically we need an expander called ·ls (stands for list) that could be used this way ·ls(·vars, ',', YAY_NO_TRAILING). That would allow you to decide if a trailing separator (in your case a comma) should be added or not.

Or maybe we need syntax support on the current unpacking syntax to indicate how to make delimiters behave.

@marcioAlmada
Copy link
Owner

Expanders are declared here, btw https://github.com/marcioAlmada/yay/blob/master/src/expanders.php.

They are just functions that receive a TokenStream and return another TokenStream.

Tests for expanders are here: https://github.com/marcioAlmada/yay/tree/master/tests/phpt/expanders

@msjyoo
Copy link
Author

msjyoo commented Feb 6, 2016

@marcioAlmada What do you think about an IRC channel on freenode? Would you mind if I implemented some of the easy picks?

@marcioAlmada
Copy link
Owner

I'm currently in transit ✈️ so there won't be time to create a real time support channel withing the next 3 days. But feel free to get some easy picks. I'll try to reply ASAP.

@msjyoo
Copy link
Author

msjyoo commented Feb 6, 2016

Ah okay. Safe travels!

@marcioAlmada
Copy link
Owner

·implode(·vars, ',') is probably more self explanatory.

@marcioAlmada marcioAlmada changed the title Impossible to expand a list of matches into the argument of a function (trailing comma) Allow to control trailing tokens when doung layer unpacking Feb 8, 2016
marcioAlmada added a commit that referenced this issue Feb 8, 2016
@marcioAlmada
Copy link
Owner

Turns out adding first class trailing token control to the already existing unpacking syntax ··· look way more expressive. See the tests at 397fb05.

@marcioAlmada marcioAlmada changed the title Allow to control trailing tokens when doung layer unpacking Allow to control trailing tokens when doing layer unpacking Feb 8, 2016
marcioAlmada added a commit that referenced this issue Feb 8, 2016
@marcioAlmada marcioAlmada mentioned this issue Feb 9, 2016
40 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants