www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5953] New: Too many trailing commas are accepted

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5953

           Summary: Too many trailing commas are accepted
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



Accepting an extra trailing comma is acceptable, but this looks excessive (this
compiles and runs with no errors, DMD 2.053 beta):


void main() {
    auto a = [,,,,,,,,,,,,,,,,,,,,,,,,,,,,,];
    assert(a.length == 0);
}


As in Python I suggest to accept only one extra trailing comma:

 a = [1]
 a = [1,]
 a = [1,,]
File "<stdin>", line 1 a = [1,,] ^ SyntaxError: invalid syntax -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 07 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5953


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm gmail.com



Please don't use Python to say a D syntax is invalid. Use the D spec or TDPL.

--------

In the D spec an array literal follows the rule:

ArrayLiteral:
    '[' ArgumentList ']'

ArgumentList:
    AssignExpression
        AssignExpression ','
    AssignExpression ',' ArgumentList

and an AssignExpression cannot be empty, so '[1,,]' should be rejected.

(BTW this rule doesn't handle '[]' at all.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 07 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5953





 Please don't use Python to say a D syntax is invalid. Use the D spec or TDPL.
I feel free to show what's the design of other languages, if they are a good example.
 and an AssignExpression cannot be empty, so '[1,,]' should be rejected.
OK. So it's not a design problem, just an implementation issue. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 08 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5953






 Please don't use Python to say a D syntax is invalid. Use the D spec or TDPL.
I feel free to show what's the design of other languages, if they are a good example.
Yes, but with the 'accept-invalid' tag I think that you want to say [,,,,,,,,,,,,,,,,,,] is invalid because it is invalid in Python. Sorry for misinterpreting.
 
 and an AssignExpression cannot be empty, so '[1,,]' should be rejected.
OK. So it's not a design problem, just an implementation issue.
-- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 08 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5953


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



00:36:53 PDT ---
https://github.com/D-Programming-Language/dmd/commit/ba4da917ed6b79fc896a21cec91a0de1a04128cb

https://github.com/D-Programming-Language/dmd/commit/fc0bbd3afba6e5f878fecc8a029f437b1df51e41

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 31 2011