On 09/09/2012 02:49 PM, Ben Davis wrote:
Hi,I'm trying to define an API in D where an object can be instantiated and then set up inline. I have various methods that return 'this' so that they can be used inline in this way. For example: dialogue=new GuiDialogue([ (new GuiLabel(titleText)).setLayoutHint(GuiLayoutHint.TOP), fileNameInput.setLayoutHint(GuiLayoutHint.TOP), currentDirectoryLabel.setLayoutHint(GuiLayoutHint.TOP), confirmButton, new GuiButton("Cancel",delegate {dialogue=null;}), ]); D's syntax currently requires me to put the new A() part in brackets. So instead of new A().b() I have to write (new A()).b() If I don't do that, then the error is "found . when expecting ," - which sounds as if it's already decided it's finished reading the expression, so there isn't a problem with ambiguity. (I suppose if the brackets are optional, then "new A.b()" would be ambiguous, but this is no different from the 'else' binding problem.) So - is this something that could be relaxed? Thanks, Ben :)
I think so. Probably it is just a bug. (the spec does not indicate that it is illegal iirc.) Maybe you can even fix it yourself, the parser should be quite hackable.
