]> Cypherpunks repositories - gostls13.git/commitdiff
spec: fix composite literal syntax to match prose
authorRobert Griesemer <gri@golang.org>
Fri, 11 Sep 2015 23:20:23 +0000 (16:20 -0700)
committerRobert Griesemer <gri@golang.org>
Sat, 12 Sep 2015 00:45:55 +0000 (00:45 +0000)
Fixes #12578.

Change-Id: I257d70a67609463e24936bc1739285da154be2fe
Reviewed-on: https://go-review.googlesource.com/14531
Reviewed-by: Rob Pike <r@golang.org>
doc/go_spec.html

index 22f9701a750a70c6307f367bb94deaf84b974fac..7de0c7b716ab3cf5a01232a13cd38b227065b3ac 100644 (file)
@@ -1,6 +1,6 @@
 <!--{
        "Title": "The Go Programming Language Specification",
-       "Subtitle": "Version of August 5, 2015",
+       "Subtitle": "Version of September 11, 2015",
        "Path": "/ref/spec"
 }-->
 
@@ -2210,9 +2210,8 @@ math.Sin  // denotes the Sin function in package math
 <p>
 Composite literals construct values for structs, arrays, slices, and maps
 and create a new value each time they are evaluated.
-They consist of the type of the value
-followed by a brace-bound list of composite elements. An element may be
-a single expression or a key-value pair.
+They consist of the type of the value followed by a brace-bound list of elements.
+Each element may optionally be preceded by a corresponding key.
 </p>
 
 <pre class="ebnf">
@@ -2220,18 +2219,18 @@ CompositeLit  = LiteralType LiteralValue .
 LiteralType   = StructType | ArrayType | "[" "..." "]" ElementType |
                 SliceType | MapType | TypeName .
 LiteralValue  = "{" [ ElementList [ "," ] ] "}" .
-ElementList   = Element { "," Element } .
-Element       = [ Key ":" ] Value .
+ElementList   = KeyedElement { "," KeyedElement } .
+KeyedElement  = [ Key ":" ] Element .
 Key           = FieldName | Expression | LiteralValue .
 FieldName     = identifier .
-Value         = Expression | LiteralValue .
+Element       = Expression | LiteralValue .
 </pre>
 
 <p>
 The LiteralType must be a struct, array, slice, or map type
 (the grammar enforces this constraint except when the type is given
 as a TypeName).
-The types of the expressions must be <a href="#Assignability">assignable</a>
+The types of the elements and keys must be <a href="#Assignability">assignable</a>
 to the respective field, element, and key types of the LiteralType;
 there is no additional conversion.
 The key is interpreted as a field name for struct literals,