leonerd / tree-sitter-perl-LEGACY

a perl parser for javascript
MIT License
4 stars 0 forks source link

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

Open leonerd opened 2 years ago

leonerd commented 2 years ago

(copied from https://github.com/ganezdragon/tree-sitter-perl/issues/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 commented 2 years ago

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

leonerd commented 2 years ago

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 commented 2 years ago

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