smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.26k stars 712 forks source link

use a trailing comma in arrays #1013

Open SlowFox71 opened 6 months ago

SlowFox71 commented 6 months ago

While I am at it, things like:

{$a=[
  'foo',
  'bar',
  'baz',
]}

are not possible at the moment (because of the trailing comma). PHP supports this syntax for quite a while, so IMO Smarty should do it as well. IMO (but as I said, I am not really good with parsers), a small change should to the trick:

arrayelements(res)   ::=  arrayelements(a1) COMMA arrayelement(a).  {
    res = a1.','.a;
}
arrayelements(res)   ::=  arrayelement(a1) COMMA arrayelements(a).  {
    res = a1.','.a;
}
wisskid commented 6 months ago

Great suggestion, I'll see if we can support this soon.