Skip to content

Commit

Permalink
Support trailing commas in function call/declaration
Browse files Browse the repository at this point in the history
With love to @ptarjan
  • Loading branch information
sgolemon committed Sep 28, 2016
1 parent 2438fa8 commit dc6af0a
Show file tree
Hide file tree
Showing 4 changed files with 404 additions and 379 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -30,6 +30,7 @@ Phack extends [PHP-Parser](https://www.github.com/nikic/PHP-Parser) by amending
| [Shapes](https://docs.hhvm.com/hack/shapes) | TBD | |
| [Collections](https://docs.hhvm.com/hack/collections) | TBD | Static initialization is... complicated... |
| [Async](https://docs.hhvm.com/hack/async) | Unlikely | PHP's Engine just doesn't support this concept well |
| Trailing Commas | Alpha | Allow trailing comma in arg/param lists |

## How do I use it?

Expand Down
9 changes: 9 additions & 0 deletions grammar/hack-extras.y
Expand Up @@ -70,6 +70,7 @@ hack_parameter_type_list:

hack_parameter_list:
hack_non_empty_parameter_list { $$ = $1; }
| hack_non_empty_parameter_list ',' { $$ = $1; }
| /* empty */ { $$ = array(); }
;

Expand All @@ -92,6 +93,14 @@ hack_optional_visibility_modifier:
| T_PRIVATE { $$ = Stmt\Class_::MODIFIER_PRIVATE; }
;

parameter_list:
non_empty_parameter_list ',' { $$ = $1; }
;

argument_list:
'(' non_empty_argument_list ',' ')' { $$ = $2; }
;

type:
'?' type { $$ = PhackNode\SoftNullableType[$2, false, true]; }
| '@' type { $$ = PhackNode\SoftNullableType[$2, true, false]; }
Expand Down

1 comment on commit dc6af0a

@ptarjan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

Please sign in to comment.