facebookarchive / hack-langspec

The official Hack Language specification.
http://hacklang.org
Other
172 stars 48 forks source link

list intrinsic grammar is too permissive #87

Closed ericlippert closed 7 years ago

ericlippert commented 7 years ago

The grammar says

  list-intrinsic:
     list  (  list-expression-list-opt  )
  list-expression-list:
    expression
    ,
    list-expression-list  ,  expression-opt

And then goes on to say

Only the right-most list-or-variable can be omitted.

This is a weird way to characterize that the grammar permits a trailing comma. I don't think of

list($x, $y,)

as having omitted a variable after the comma, but rather, having added an unnecessary comma. Characterizing this as an "omission" implies that something ought to be there.

I would remove the sentence entirely and enforce the rule in the grammar:

  list-intrinsic:
     list  (  expression-list-opt  )
  expression-list:
    expressions ,-opt
  expressions:
    expression
    expressions  ,  expression

Now there is no need for the supporting text, and the only things that can be "omitted" are (1) the entire list, or (2) the trailing comma.

ericlippert commented 7 years ago

Whoops, I already entered this one as #82.