<!--{
"Title": "The Go Programming Language Specification",
- "Subtitle": "Language version go1.24 (Nov 20, 2024)",
+ "Subtitle": "Language version go1.24 (Dec 12, 2024)",
"Path": "/ref/spec"
}-->
</p>
<pre class="ebnf">
-Type = TypeName [ TypeArgs ] | TypeLit | "(" Type ")" .
-TypeName = identifier | QualifiedIdent .
-TypeArgs = "[" TypeList [ "," ] "]" .
-TypeList = Type { "," Type } .
-TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType |
- SliceType | MapType | ChannelType .
+Type = TypeName [ TypeArgs ] | TypeLit | "(" Type ")" .
+TypeName = identifier | QualifiedIdent .
+TypeArgs = "[" TypeList [ "," ] "]" .
+TypeList = Type { "," Type } .
+TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType |
+ SliceType | MapType | ChannelType .
</pre>
<p>
</p>
<pre class="ebnf">
-FunctionType = "func" Signature .
-Signature = Parameters [ Result ] .
-Result = Parameters | Type .
-Parameters = "(" [ ParameterList [ "," ] ] ")" .
-ParameterList = ParameterDecl { "," ParameterDecl } .
-ParameterDecl = [ IdentifierList ] [ "..." ] Type .
+FunctionType = "func" Signature .
+Signature = Parameters [ Result ] .
+Result = Parameters | Type .
+Parameters = "(" [ ParameterList [ "," ] ] ")" .
+ParameterList = ParameterDecl { "," ParameterDecl } .
+ParameterDecl = [ IdentifierList ] [ "..." ] Type .
</pre>
<p>
</p>
<pre class="ebnf">
-MapType = "map" "[" KeyType "]" ElementType .
-KeyType = Type .
+MapType = "map" "[" KeyType "]" ElementType .
+KeyType = Type .
</pre>
<p>
</p>
<pre class="ebnf">
-Block = "{" StatementList "}" .
+Block = "{" StatementList "}" .
StatementList = { Statement ";" } .
</pre>
</p>
<pre class="ebnf">
-Declaration = ConstDecl | TypeDecl | VarDecl .
-TopLevelDecl = Declaration | FunctionDecl | MethodDecl .
+Declaration = ConstDecl | TypeDecl | VarDecl .
+TopLevelDecl = Declaration | FunctionDecl | MethodDecl .
</pre>
<p>
</p>
<pre class="ebnf">
-TypeParameters = "[" TypeParamList [ "," ] "]" .
-TypeParamList = TypeParamDecl { "," TypeParamDecl } .
-TypeParamDecl = IdentifierList TypeConstraint .
+TypeParameters = "[" TypeParamList [ "," ] "]" .
+TypeParamList = TypeParamDecl { "," TypeParamDecl } .
+TypeParamDecl = IdentifierList TypeConstraint .
</pre>
<p>
</p>
<pre class="ebnf">
-VarDecl = "var" ( VarSpec | "(" { VarSpec ";" } ")" ) .
-VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) .
+VarDecl = "var" ( VarSpec | "(" { VarSpec ";" } ")" ) .
+VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) .
</pre>
<pre>
</p>
<pre class="ebnf">
-CompositeLit = LiteralType LiteralValue .
-LiteralType = StructType | ArrayType | "[" "..." "]" ElementType |
- SliceType | MapType | TypeName [ TypeArgs ] .
-LiteralValue = "{" [ ElementList [ "," ] ] "}" .
-ElementList = KeyedElement { "," KeyedElement } .
-KeyedElement = [ Key ":" ] Element .
-Key = FieldName | Expression | LiteralValue .
-FieldName = identifier .
-Element = Expression | LiteralValue .
+CompositeLit = LiteralType LiteralValue .
+LiteralType = StructType | ArrayType | "[" "..." "]" ElementType |
+ SliceType | MapType | TypeName [ TypeArgs ] .
+LiteralValue = "{" [ ElementList [ "," ] ] "}" .
+ElementList = KeyedElement { "," KeyedElement } .
+KeyedElement = [ Key ":" ] Element .
+Key = FieldName | Expression | LiteralValue .
+FieldName = identifier .
+Element = Expression | LiteralValue .
</pre>
<p>
</p>
<pre class="ebnf">
-PrimaryExpr =
- Operand |
- Conversion |
- MethodExpr |
- PrimaryExpr Selector |
- PrimaryExpr Index |
- PrimaryExpr Slice |
- PrimaryExpr TypeAssertion |
- PrimaryExpr Arguments .
+PrimaryExpr = Operand |
+ Conversion |
+ MethodExpr |
+ PrimaryExpr Selector |
+ PrimaryExpr Index |
+ PrimaryExpr Slice |
+ PrimaryExpr TypeAssertion |
+ PrimaryExpr Arguments .
-Selector = "." identifier .
-Index = "[" Expression [ "," ] "]" .
-Slice = "[" [ Expression ] ":" [ Expression ] "]" |
- "[" [ Expression ] ":" Expression ":" Expression "]" .
-TypeAssertion = "." "(" Type ")" .
-Arguments = "(" [ ( ExpressionList | Type [ "," ExpressionList ] ) [ "..." ] [ "," ] ] ")" .
+Selector = "." identifier .
+Index = "[" Expression [ "," ] "]" .
+Slice = "[" [ Expression ] ":" [ Expression ] "]" |
+ "[" [ Expression ] ":" Expression ":" Expression "]" .
+TypeAssertion = "." "(" Type ")" .
+Arguments = "(" [ ( ExpressionList | Type [ "," ExpressionList ] ) [ "..." ] [ "," ] ] ")" .
</pre>
</p>
<pre class="ebnf">
-MethodExpr = ReceiverType "." MethodName .
-ReceiverType = Type .
+MethodExpr = ReceiverType "." MethodName .
+ReceiverType = Type .
</pre>
<p>
</p>
<pre class="ebnf">
-Statement =
- Declaration | LabeledStmt | SimpleStmt |
- GoStmt | ReturnStmt | BreakStmt | ContinueStmt | GotoStmt |
- FallthroughStmt | Block | IfStmt | SwitchStmt | SelectStmt | ForStmt |
- DeferStmt .
+Statement = Declaration | LabeledStmt | SimpleStmt |
+ GoStmt | ReturnStmt | BreakStmt | ContinueStmt | GotoStmt |
+ FallthroughStmt | Block | IfStmt | SwitchStmt | SelectStmt | ForStmt |
+ DeferStmt .
SimpleStmt = EmptyStmt | ExpressionStmt | SendStmt | IncDecStmt | Assignment | ShortVarDecl .
</pre>
<pre class="ebnf">
Assignment = ExpressionList assign_op ExpressionList .
-assign_op = [ add_op | mul_op ] "=" .
+assign_op = [ add_op | mul_op ] "=" .
</pre>
<p>
</p>
<pre class="ebnf">
-ForStmt = "for" [ Condition | ForClause | RangeClause ] Block .
+ForStmt = "for" [ Condition | ForClause | RangeClause ] Block .
Condition = Expression .
</pre>
<pre class="ebnf">
ForClause = [ InitStmt ] ";" [ Condition ] ";" [ PostStmt ] .
-InitStmt = SimpleStmt .
-PostStmt = SimpleStmt .
+InitStmt = SimpleStmt .
+PostStmt = SimpleStmt .
</pre>
<pre>
</p>
<pre class="ebnf">
-SourceFile = PackageClause ";" { ImportDecl ";" } { TopLevelDecl ";" } .
+SourceFile = PackageClause ";" { ImportDecl ";" } { TopLevelDecl ";" } .
</pre>
<h3 id="Package_clause">Package clause</h3>
</p>
<pre class="ebnf">
-PackageClause = "package" PackageName .
-PackageName = identifier .
+PackageClause = "package" PackageName .
+PackageName = identifier .
</pre>
<p>
</p>
<pre class="ebnf">
-ImportDecl = "import" ( ImportSpec | "(" { ImportSpec ";" } ")" ) .
-ImportSpec = [ "." | PackageName ] ImportPath .
-ImportPath = string_lit .
+ImportDecl = "import" ( ImportSpec | "(" { ImportSpec ";" } ")" ) .
+ImportSpec = [ "." | PackageName ] ImportPath .
+ImportPath = string_lit .
</pre>
<p>