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

for and foreach should be exact aliases of each other #1

Open
leonerd opened this issue Feb 24, 2022 · 3 comments
Open

for and foreach should be exact aliases of each other #1

leonerd opened this issue Feb 24, 2022 · 3 comments
Assignees
Labels
OHMAGERD What on earth?

Comments

@leonerd
Copy link
Owner

leonerd commented Feb 24, 2022

(copied from ganezdragon#13)

This grammar makes several distinctions between for and foreach. The real perl parser considers them as exact synonyms of each other. Any and all syntax forms that are accepted by one are accepted by the other. Yes; even C-style for loops:

$ perl -E 'foreach(my $i = 0; $i < 3; $i++) { say $i }'
0
1
2
@rabbiveesh rabbiveesh self-assigned this Feb 24, 2022
@rabbiveesh
Copy link
Collaborator

This should be trivial to implement, so I'll handle it

@rabbiveesh rabbiveesh added the OHMAGERD What on earth? label Feb 24, 2022
@leonerd
Copy link
Owner Author

leonerd commented Feb 24, 2022

I imagine the solution would involve creating a new private $_for that simply matches either "for" or "foreach" then rewrite the rest of the rules in terms of that.

@rabbiveesh
Copy link
Collaborator

Does for need special casing syntax-wise b/c of the lexical assignment part? Otherwise I would imagine we should group all control-flow blocks in the same syntax group

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OHMAGERD What on earth?
Projects
None yet
Development

No branches or pull requests

2 participants