Skip to content

allow for dangling comma #11

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

Closed
wants to merge 3 commits into from
Closed

allow for dangling comma #11

wants to merge 3 commits into from

Conversation

chx
Copy link
Contributor

@chx chx commented Sep 10, 2013

Drupal developers are much to used to the PHP array syntax which allows a dangling comma:

array(
  'foo' => 'bar',
);

Doctrine doesn't allow for this and this causes a lot of grief. This PR fixes this. It seems {} arrays already support this.

@dawehner
Copy link

I do really like the change, as it is damn complicated to extend an array if it fails all the time as the previous line did not had a comma.

@stof
Copy link
Member

stof commented Sep 10, 2013

you should also allow them in arrays (for which your consistency argument would be even more accurate as PHP does not support it at the end of function call arguments)

@chx
Copy link
Contributor Author

chx commented Sep 10, 2013

Arrays already good, I tested them.

@bartfeenstra
Copy link
Contributor

Trailing commas in arrays are supported by \Doctrine\Common\Annotations\DocParser::Arrayx() and I manually confirmed that as well.

Also, anything that decreases the chances of WTFs is an improvement.

@EclipseGc
Copy link

Working with this daily in Drupal, and also dealing with overcoming this particular objections with Drupal devs very very regularly. I 100% support this.

@patrickd-
Copy link

Whenever I'm writing JSON and forget that one comma there - I'm wasting another minute of my lifetime to get rid of it.

Let's make writing Annotations less painful and get this in, please!

@guilhermeblanco
Copy link
Member

I think there's a better way to support this without entering on 2nd level of indentation.
Will look into it. =)

@chx
Copy link
Contributor Author

chx commented Sep 11, 2013

I am not sure what you mean -- I could look at the lookahead token retrieved instead of calling the helper but calling the helper seemed cleaner. If you'd clarify what you'd like me to do, I'd be glad to help more.

@guilhermeblanco
Copy link
Member

@chx the issue I see is that you're mixing grammar rules by checking a token that is not part of "Values", but its parent, "Annotation".
There may be other ways to achieve same solution by rewriting the grammar rule, for example and updating the code to match it. Quick and dirty example would be from Value {"," Value}* to {Value ","}* Value or even {Value ","}+. Each of these have its own problem, but none of these covers the unknown token ).
I'm considering a variance of {Value ","?}+, but this one would make this annotation valid:

/**
 * @Annotation(foo="bar" bar="woo", fur="buzz")
 */

That's why I'm telling that it may be a little bit different your patch.

@chx
Copy link
Contributor Author

chx commented Sep 11, 2013

I simply upgraded the grammar to be Values ::= Array | Value {"," Value}* ,? but that might be wrong. I am not quite sure, however, how to check we are finished if I can't look at the forthcoming parenthesis...

@guilhermeblanco
Copy link
Member

@chx that's why I told you there may be a better approach for the problem. I just can't think on this atm (deploying a subsystem to production at work)

@chx
Copy link
Contributor Author

chx commented Sep 11, 2013

I checked the aforementioned arrayx function and it actually does the exact same. Added in 3b9d2f8

@chx
Copy link
Contributor Author

chx commented Sep 14, 2013

I asked this on stackoverflow and fixed my grammar syntax.

@chx
Copy link
Contributor Author

chx commented Sep 14, 2013

Worked with Damien Tournoud on this; the grammar is LL(1) again. Tests passed.

@chx
Copy link
Contributor Author

chx commented Sep 14, 2013

Also note that the grammar is positively weird:

Values ::= "(" [Array | Value {"," Value}* [","] ] ")"
Value ::= PlainValue | FieldAssignment
PlainValue ::= integer | string | float | boolean | Array | Annotation

So this means that {}, "foo" is invalid but "foo", {} is valid (PlainValue can contain Array).

What about (in a followup) removing the special casing of Array from Values?

@EclipseGc
Copy link

Is there any feedback on this in terms of what's left to get it committed?

@socketwench
Copy link

Ran into this problem too. Kinda annoying. The syntax error that gets thrown in the least is uninformative, especially as commas are easily overlooked characters.

@cosmicdreams
Copy link

Does this issue need to be assigned to a specific person in order to be reviewed for acceptance?

@beberlei
Copy link
Member

@guilhermeblanco ping again

@guilhermeblanco
Copy link
Member

Fixed here: 463d926
I kept BC, but still rely on 1 misleading call of CLOSE_PARENTHESIS where it shouldn't... couldn't imagine a proper solution for now.

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

Successfully merging this pull request may close these issues.