Commit f7ac3136 authored by Robert Griesemer's avatar Robert Griesemer

- mark actual EBNF with pre-formatted class "ebnf" instead of "grammar"

- make real productions for Unicode char classes so that they can be parsed
- use `` for tokens that contain "'s or \'s so that they can be parsed
- added a missing '.'

This version of the spec passes through ebnflint (forthcoming) without errors.

R=r,rsc
DELTA=74  (3 added, 1 deleted, 70 changed)
OCL=31464
CL=31466
parent 8a9e395f
...@@ -69,12 +69,11 @@ operators, in increasing precedence: ...@@ -69,12 +69,11 @@ operators, in increasing precedence:
<p> <p>
Lower-case production names are used to identify lexical tokens. Lower-case production names are used to identify lexical tokens.
Non-terminals are in CamelCase. Lexical symbols are enclosed in Non-terminals are in CamelCase. Lexical symbols are enclosed in
double quotes <code>""</code> (the double quote symbol is written as double <code>""</code> or back quotes <code>``</code>.
<code>'"'</code>).
</p> </p>
<p> <p>
The form <code>"a ... b"</code> represents the set of characters from The form <code>a ... b</code> represents the set of characters from
<code>a</code> through <code>b</code> as alternatives. <code>a</code> through <code>b</code> as alternatives.
</p> </p>
...@@ -99,12 +98,12 @@ are different characters. ...@@ -99,12 +98,12 @@ are different characters.
<p> <p>
The following terms are used to denote specific Unicode character classes: The following terms are used to denote specific Unicode character classes:
</p> </p>
<ul> <pre class="ebnf">
<li>unicode_char an arbitrary Unicode code point</li> unicode_char = /* an arbitrary Unicode code point */ .
<li>unicode_letter a Unicode code point classified as "Letter"</li> unicode_letter = /* a Unicode code point classified as "Letter" */ .
<li>capital_letter a Unicode code point classified as "Letter, uppercase"</li> capital_letter = /* a Unicode code point classified as "Letter, uppercase" */ .
<li>unicode_digit a Unicode code point classified as "Digit"</li> unicode_digit = /* a Unicode code point classified as "Digit" */ .
</ul> </pre>
(The Unicode Standard, Section 4.5 General Category - Normative.) (The Unicode Standard, Section 4.5 General Category - Normative.)
...@@ -112,8 +111,8 @@ The following terms are used to denote specific Unicode character classes: ...@@ -112,8 +111,8 @@ The following terms are used to denote specific Unicode character classes:
<p> <p>
The underscore character <code>_</code> (U+005F) is considered a letter. The underscore character <code>_</code> (U+005F) is considered a letter.
</> </p>
<pre class="grammar"> <pre class="ebnf">
letter = unicode_letter | "_" . letter = unicode_letter | "_" .
decimal_digit = "0" ... "9" . decimal_digit = "0" ... "9" .
octal_digit = "0" ... "7" . octal_digit = "0" ... "7" .
...@@ -152,7 +151,7 @@ Identifiers name program entities such as variables and types. ...@@ -152,7 +151,7 @@ Identifiers name program entities such as variables and types.
An identifier is a sequence of one or more letters and digits. An identifier is a sequence of one or more letters and digits.
The first character in an identifier must be a letter. The first character in an identifier must be a letter.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
identifier = letter { letter | unicode_digit } . identifier = letter { letter | unicode_digit } .
</pre> </pre>
<pre> <pre>
...@@ -199,7 +198,7 @@ sets a non-decimal base: <code>0</code> for octal, <code>0x</code> or ...@@ -199,7 +198,7 @@ sets a non-decimal base: <code>0</code> for octal, <code>0x</code> or
<code>0X</code> for hexadecimal. In hexadecimal literals, letters <code>0X</code> for hexadecimal. In hexadecimal literals, letters
<code>a-f</code> and <code>A-F</code> represent values 10 through 15. <code>a-f</code> and <code>A-F</code> represent values 10 through 15.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
int_lit = decimal_lit | octal_lit | hex_lit . int_lit = decimal_lit | octal_lit | hex_lit .
decimal_lit = ( "1" ... "9" ) { decimal_digit } . decimal_lit = ( "1" ... "9" ) { decimal_digit } .
octal_lit = "0" { octal_digit } . octal_lit = "0" { octal_digit } .
...@@ -223,7 +222,7 @@ followed by an optionally signed decimal exponent. One of the ...@@ -223,7 +222,7 @@ followed by an optionally signed decimal exponent. One of the
integer part or the fractional part may be elided; one of the decimal integer part or the fractional part may be elided; one of the decimal
point or the exponent may be elided. point or the exponent may be elided.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
float_lit = decimals "." [ decimals ] [ exponent ] | float_lit = decimals "." [ decimals ] [ exponent ] |
decimals exponent | decimals exponent |
"." decimals [ exponent ] . "." decimals [ exponent ] .
...@@ -312,16 +311,16 @@ After a backslash, certain single-character escapes represent special values: ...@@ -312,16 +311,16 @@ After a backslash, certain single-character escapes represent special values:
<p> <p>
All other sequences are illegal inside character literals. All other sequences are illegal inside character literals.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
char_lit = "'" ( unicode_value | byte_value ) "'" . char_lit = "'" ( unicode_value | byte_value ) "'" .
unicode_value = unicode_char | little_u_value | big_u_value | escaped_char . unicode_value = unicode_char | little_u_value | big_u_value | escaped_char .
byte_value = octal_byte_value | hex_byte_value . byte_value = octal_byte_value | hex_byte_value .
octal_byte_value = "\" octal_digit octal_digit octal_digit . octal_byte_value = `\` octal_digit octal_digit octal_digit .
hex_byte_value = "\" "x" hex_digit hex_digit . hex_byte_value = `\` "x" hex_digit hex_digit .
little_u_value = "\" "u" hex_digit hex_digit hex_digit hex_digit . little_u_value = `\` "u" hex_digit hex_digit hex_digit hex_digit .
big_u_value = "\" "U" hex_digit hex_digit hex_digit hex_digit big_u_value = `\` "U" hex_digit hex_digit hex_digit hex_digit
hex_digit hex_digit hex_digit hex_digit . hex_digit hex_digit hex_digit hex_digit .
escaped_char = "\" ( "a" | "b" | "f" | "n" | "r" | "t" | "v" | "\" | "'" | """ ) . escaped_char = `\` ( "a" | "b" | "f" | "n" | "r" | "t" | "v" | `\` | "'" | `"` ) .
</pre> </pre>
<pre> <pre>
'a' 'a'
...@@ -379,7 +378,7 @@ U+00FF. ...@@ -379,7 +378,7 @@ U+00FF.
A sequence of string literals is concatenated to form a single string. A sequence of string literals is concatenated to form a single string.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
StringLit = string_lit { string_lit } . StringLit = string_lit { string_lit } .
string_lit = raw_string_lit | interpreted_string_lit . string_lit = raw_string_lit | interpreted_string_lit .
raw_string_lit = "`" { unicode_char } "`" . raw_string_lit = "`" { unicode_char } "`" .
...@@ -430,7 +429,7 @@ type. A type may be specified by a (possibly qualified) <i>type name</i> ...@@ -430,7 +429,7 @@ type. A type may be specified by a (possibly qualified) <i>type name</i>
which composes a new type from previously declared types. which composes a new type from previously declared types.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
Type = TypeName | TypeLit | "(" Type ")" . Type = TypeName | TypeLit | "(" Type ")" .
TypeName = QualifiedIdent. TypeName = QualifiedIdent.
TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType | TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType |
...@@ -568,7 +567,7 @@ type, called the element type, which must be complete ...@@ -568,7 +567,7 @@ type, called the element type, which must be complete
negative. negative.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
ArrayType = "[" ArrayLength "]" ElementType . ArrayType = "[" ArrayLength "]" ElementType .
ArrayLength = Expression . ArrayLength = Expression .
ElementType = CompleteType . ElementType = CompleteType .
...@@ -598,7 +597,7 @@ type denotes the set of all slices of arrays of its element type. ...@@ -598,7 +597,7 @@ type denotes the set of all slices of arrays of its element type.
A slice value may be <code>nil</code>. A slice value may be <code>nil</code>.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
SliceType = "[" "]" ElementType . SliceType = "[" "]" ElementType .
</pre> </pre>
...@@ -674,7 +673,7 @@ an identifier and type for each field. Within a struct, field identifiers ...@@ -674,7 +673,7 @@ an identifier and type for each field. Within a struct, field identifiers
must be unique and field types must be complete (§Types). must be unique and field types must be complete (§Types).
</p> </p>
<pre class="grammar"> <pre class="ebnf">
StructType = "struct" "{" [ FieldDeclList ] "}" . StructType = "struct" "{" [ FieldDeclList ] "}" .
FieldDeclList = FieldDecl { ";" FieldDecl } [ ";" ] . FieldDeclList = FieldDecl { ";" FieldDecl } [ ";" ] .
FieldDecl = (IdentifierList CompleteType | [ "*" ] TypeName) [ Tag ] . FieldDecl = (IdentifierList CompleteType | [ "*" ] TypeName) [ Tag ] .
...@@ -775,7 +774,7 @@ type, called the <i>base type</i> of the pointer. ...@@ -775,7 +774,7 @@ type, called the <i>base type</i> of the pointer.
A pointer value may be <code>nil</code>. A pointer value may be <code>nil</code>.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
PointerType = "*" BaseType . PointerType = "*" BaseType .
BaseType = Type . BaseType = Type .
</pre> </pre>
...@@ -793,7 +792,7 @@ and result types. ...@@ -793,7 +792,7 @@ and result types.
A function value may be <code>nil</code>. A function value may be <code>nil</code>.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
FunctionType = "func" Signature . FunctionType = "func" Signature .
Signature = Parameters [ Result ] . Signature = Parameters [ Result ] .
Result = Parameters | CompleteType . Result = Parameters | CompleteType .
...@@ -842,7 +841,7 @@ that is any superset of the interface. Such a type is said to ...@@ -842,7 +841,7 @@ that is any superset of the interface. Such a type is said to
<i>implement the interface</i>. An interface value may be <code>nil</code>. <i>implement the interface</i>. An interface value may be <code>nil</code>.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
InterfaceType = "interface" "{" [ MethodSpecList ] "}" . InterfaceType = "interface" "{" [ MethodSpecList ] "}" .
MethodSpecList = MethodSpec { ";" MethodSpec } [ ";" ] . MethodSpecList = MethodSpec { ";" MethodSpec } [ ";" ] .
MethodSpec = IdentifierList Signature | InterfaceTypeName . MethodSpec = IdentifierList Signature | InterfaceTypeName .
...@@ -943,7 +942,7 @@ A map value may be <code>nil</code>. ...@@ -943,7 +942,7 @@ A map value may be <code>nil</code>.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
MapType = "map" "[" KeyType "]" ValueType . MapType = "map" "[" KeyType "]" ValueType .
KeyType = CompleteType . KeyType = CompleteType .
ValueType = CompleteType . ValueType = CompleteType .
...@@ -1000,7 +999,7 @@ specified element type. The element type must be complete (§Types). ...@@ -1000,7 +999,7 @@ specified element type. The element type must be complete (§Types).
A value of channel type may be <code>nil</code>. A value of channel type may be <code>nil</code>.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
ChannelType = Channel | SendChannel | RecvChannel . ChannelType = Channel | SendChannel | RecvChannel .
Channel = "chan" ValueType . Channel = "chan" ValueType .
SendChannel = "chan" "&lt;-" ValueType . SendChannel = "chan" "&lt;-" ValueType .
...@@ -1242,7 +1241,7 @@ a variable or function and specifies properties such as its type. ...@@ -1242,7 +1241,7 @@ a variable or function and specifies properties such as its type.
Every identifier in a program must be declared. Every identifier in a program must be declared.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
Declaration = ConstDecl | TypeDecl | VarDecl | FunctionDecl | MethodDecl . Declaration = ConstDecl | TypeDecl | VarDecl | FunctionDecl | MethodDecl .
</pre> </pre>
...@@ -1349,7 +1348,7 @@ the left is bound to value of the n<sup>th</sup> expression on the ...@@ -1349,7 +1348,7 @@ the left is bound to value of the n<sup>th</sup> expression on the
right. right.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
ConstDecl = "const" ( ConstSpec | "(" [ ConstSpecList ] ")" ) . ConstDecl = "const" ( ConstSpec | "(" [ ConstSpecList ] ")" ) .
ConstSpecList = ConstSpec { ";" ConstSpec } [ ";" ] . ConstSpecList = ConstSpec { ";" ConstSpec } [ ";" ] .
ConstSpec = IdentifierList [ [ CompleteType ] "=" ExpressionList ] . ConstSpec = IdentifierList [ [ CompleteType ] "=" ExpressionList ] .
...@@ -1465,7 +1464,7 @@ A type declaration binds an identifier, the <i>type name</i>, ...@@ -1465,7 +1464,7 @@ A type declaration binds an identifier, the <i>type name</i>,
to a new type. <font color=red>TODO: what exactly is a "new type"?</font> to a new type. <font color=red>TODO: what exactly is a "new type"?</font>
</p> </p>
<pre class="grammar"> <pre class="ebnf">
TypeDecl = "type" ( TypeSpec | "(" [ TypeSpecList ] ")" ) . TypeDecl = "type" ( TypeSpec | "(" [ TypeSpecList ] ")" ) .
TypeSpecList = TypeSpec { ";" TypeSpec } [ ";" ] . TypeSpecList = TypeSpec { ";" TypeSpec } [ ";" ] .
TypeSpec = identifier ( Type | "struct" | "interface" ) . TypeSpec = identifier ( Type | "struct" | "interface" ) .
...@@ -1498,7 +1497,7 @@ A variable declaration creates a variable, binds an identifier to it and ...@@ -1498,7 +1497,7 @@ A variable declaration creates a variable, binds an identifier to it and
gives it a type and optionally an initial value. gives it a type and optionally an initial value.
The type must be complete (§Types). The type must be complete (§Types).
</p> </p>
<pre class="grammar"> <pre class="ebnf">
VarDecl = "var" ( VarSpec | "(" [ VarSpecList ] ")" ) . VarDecl = "var" ( VarSpec | "(" [ VarSpecList ] ")" ) .
VarSpecList = VarSpec { ";" VarSpec } [ ";" ] . VarSpecList = VarSpec { ";" VarSpec } [ ";" ] .
VarSpec = IdentifierList ( CompleteType [ "=" ExpressionList ] | "=" ExpressionList ) . VarSpec = IdentifierList ( CompleteType [ "=" ExpressionList ] | "=" ExpressionList ) .
...@@ -1546,7 +1545,7 @@ var f = 3.1415 // f has type float ...@@ -1546,7 +1545,7 @@ var f = 3.1415 // f has type float
A <i>short variable declaration</i> uses the syntax A <i>short variable declaration</i> uses the syntax
<pre class="grammar"> <pre class="ebnf">
SimpleVarDecl = IdentifierList ":=" ExpressionList . SimpleVarDecl = IdentifierList ":=" ExpressionList .
</pre> </pre>
...@@ -1603,7 +1602,7 @@ they can be used to declare local temporary variables (§Statements). ...@@ -1603,7 +1602,7 @@ they can be used to declare local temporary variables (§Statements).
A function declaration binds an identifier to a function (§Function types). A function declaration binds an identifier to a function (§Function types).
</p> </p>
<pre class="grammar"> <pre class="ebnf">
FunctionDecl = "func" identifier Signature [ Block ] . FunctionDecl = "func" identifier Signature [ Block ] .
</pre> </pre>
...@@ -1627,7 +1626,7 @@ Implementation restriction: Functions can only be declared at the package level. ...@@ -1627,7 +1626,7 @@ Implementation restriction: Functions can only be declared at the package level.
A method declaration binds an identifier to a method, A method declaration binds an identifier to a method,
which is a function with a <i>receiver</i>. which is a function with a <i>receiver</i>.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
MethodDecl = "func" Receiver identifier Signature [ Block ] . MethodDecl = "func" Receiver identifier Signature [ Block ] .
Receiver = "(" [ identifier ] [ "*" ] TypeName ")" . Receiver = "(" [ identifier ] [ "*" ] TypeName ")" .
</pre> </pre>
...@@ -1742,7 +1741,7 @@ and a type. ...@@ -1742,7 +1741,7 @@ and a type.
Operands denote the elementary values in an expression. Operands denote the elementary values in an expression.
<pre class="grammar"> <pre class="ebnf">
Operand = Literal | QualifiedIdent | "(" Expression ")" . Operand = Literal | QualifiedIdent | "(" Expression ")" .
Literal = BasicLit | CompositeLit | FunctionLit . Literal = BasicLit | CompositeLit | FunctionLit .
BasicLit = int_lit | float_lit | char_lit | StringLit . BasicLit = int_lit | float_lit | char_lit | StringLit .
...@@ -1766,7 +1765,7 @@ Constants have values that are known at compile time. ...@@ -1766,7 +1765,7 @@ Constants have values that are known at compile time.
A qualified identifier is an identifier qualified by a package name prefix. A qualified identifier is an identifier qualified by a package name prefix.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
QualifiedIdent = [ ( LocalPackageName | PackageName ) "." ] identifier . QualifiedIdent = [ ( LocalPackageName | PackageName ) "." ] identifier .
LocalPackageName = identifier . LocalPackageName = identifier .
PackageName = identifier . PackageName = identifier .
...@@ -1802,7 +1801,7 @@ followed by a brace-bound list of composite elements. An element may be ...@@ -1802,7 +1801,7 @@ followed by a brace-bound list of composite elements. An element may be
a single expression or a key-value pair. a single expression or a key-value pair.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
CompositeLit = LiteralType "{" [ ElementList ] "}" . CompositeLit = LiteralType "{" [ ElementList ] "}" .
LiteralType = StructType | ArrayType | "[" "..." "]" ElementType | LiteralType = StructType | ArrayType | "[" "..." "]" ElementType |
SliceType | MapType | TypeName . SliceType | MapType | TypeName .
...@@ -1965,7 +1964,7 @@ A function literal represents an anonymous function. ...@@ -1965,7 +1964,7 @@ A function literal represents an anonymous function.
It consists of a specification of the function type and a function body. It consists of a specification of the function type and a function body.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
FunctionLit = FunctionType Block . FunctionLit = FunctionType Block .
Block = "{" StatementList "}" . Block = "{" StatementList "}" .
</pre> </pre>
...@@ -1993,7 +1992,7 @@ as they are accessible. ...@@ -1993,7 +1992,7 @@ as they are accessible.
<h3>Primary expressions</h3> <h3>Primary expressions</h3>
<pre class="grammar"> <pre class="ebnf">
PrimaryExpr = PrimaryExpr =
Operand | Operand |
PrimaryExpr Selector | PrimaryExpr Selector |
...@@ -2414,7 +2413,7 @@ parameter is passed unchanged as an actual <code>...</code> parameter. ...@@ -2414,7 +2413,7 @@ parameter is passed unchanged as an actual <code>...</code> parameter.
Operators combine operands into expressions. Operators combine operands into expressions.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
Expression = UnaryExpr | Expression binary_op UnaryExpr . Expression = UnaryExpr | Expression binary_op UnaryExpr .
UnaryExpr = PrimaryExpr | unary_op UnaryExpr . UnaryExpr = PrimaryExpr | unary_op UnaryExpr .
...@@ -3003,7 +3002,7 @@ of <code>y</code> is not specified. ...@@ -3003,7 +3002,7 @@ of <code>y</code> is not specified.
Statements control execution. Statements control execution.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
Statement = Statement =
Declaration | EmptyStmt | LabeledStmt | Declaration | EmptyStmt | LabeledStmt |
SimpleStmt | GoStmt | ReturnStmt | BreakStmt | ContinueStmt | GotoStmt | SimpleStmt | GoStmt | ReturnStmt | BreakStmt | ContinueStmt | GotoStmt |
...@@ -3013,7 +3012,7 @@ Statement = ...@@ -3013,7 +3012,7 @@ Statement =
SimpleStmt = ExpressionStmt | IncDecStmt | Assignment | SimpleVarDecl . SimpleStmt = ExpressionStmt | IncDecStmt | Assignment | SimpleVarDecl .
StatementList = Statement { Separator Statement } . StatementList = Statement { Separator Statement } .
Separator = [ ";" ] Separator = [ ";" ] .
</pre> </pre>
<p> <p>
...@@ -3033,7 +3032,7 @@ which may be omitted only if the previous statement: ...@@ -3033,7 +3032,7 @@ which may be omitted only if the previous statement:
The empty statement does nothing. The empty statement does nothing.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
EmptyStmt = . EmptyStmt = .
</pre> </pre>
...@@ -3050,7 +3049,7 @@ A labeled statement may be the target of a <code>goto</code>, ...@@ -3050,7 +3049,7 @@ A labeled statement may be the target of a <code>goto</code>,
<code>break</code> or <code>continue</code> statement. <code>break</code> or <code>continue</code> statement.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
LabeledStmt = Label ":" Statement . LabeledStmt = Label ":" Statement .
Label = identifier . Label = identifier .
</pre> </pre>
...@@ -3068,7 +3067,7 @@ can appear in statement context. ...@@ -3068,7 +3067,7 @@ can appear in statement context.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
ExpressionStmt = Expression . ExpressionStmt = Expression .
</pre> </pre>
...@@ -3086,7 +3085,7 @@ by the ideal numeric value 1. As with an assignment, the operand ...@@ -3086,7 +3085,7 @@ by the ideal numeric value 1. As with an assignment, the operand
must be a variable, pointer indirection, field selector or index expression. must be a variable, pointer indirection, field selector or index expression.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
IncDecStmt = Expression ( "++" | "--" ) . IncDecStmt = Expression ( "++" | "--" ) .
</pre> </pre>
...@@ -3103,7 +3102,7 @@ x-- x -= 1 ...@@ -3103,7 +3102,7 @@ x-- x -= 1
<h3>Assignments</h3> <h3>Assignments</h3>
<pre class="grammar"> <pre class="ebnf">
Assignment = ExpressionList assign_op ExpressionList . Assignment = ExpressionList assign_op ExpressionList .
assign_op = [ add_op | mul_op ] "=" . assign_op = [ add_op | mul_op ] "=" .
...@@ -3182,7 +3181,7 @@ present, the "else" branch is executed. A missing condition ...@@ -3182,7 +3181,7 @@ present, the "else" branch is executed. A missing condition
is equivalent to <code>true</code>. is equivalent to <code>true</code>.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
IfStmt = "if" [ [ SimpleStmt ] ";" ] [ Expression ] Block [ "else" Statement ] . IfStmt = "if" [ [ SimpleStmt ] ";" ] [ Expression ] Block [ "else" Statement ] .
</pre> </pre>
...@@ -3219,7 +3218,7 @@ inside the "switch" to determine which branch ...@@ -3219,7 +3218,7 @@ inside the "switch" to determine which branch
to execute. to execute.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
SwitchStmt = ExprSwitchStmt | TypeSwitchStmt . SwitchStmt = ExprSwitchStmt | TypeSwitchStmt .
</pre> </pre>
...@@ -3249,7 +3248,7 @@ A missing expression is equivalent to ...@@ -3249,7 +3248,7 @@ A missing expression is equivalent to
the expression <code>true</code>. the expression <code>true</code>.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
ExprSwitchStmt = "switch" [ [ SimpleStmt ] ";" ] [ Expression ] "{" { ExprCaseClause } "}" . ExprSwitchStmt = "switch" [ [ SimpleStmt ] ";" ] [ Expression ] "{" { ExprCaseClause } "}" .
ExprCaseClause = ExprSwitchCase ":" [ StatementList ] . ExprCaseClause = ExprSwitchCase ":" [ StatementList ] .
ExprSwitchCase = "case" ExpressionList | "default" . ExprSwitchCase = "case" ExpressionList | "default" .
...@@ -3306,7 +3305,7 @@ Cases then match literal types against the dynamic type of the expression ...@@ -3306,7 +3305,7 @@ Cases then match literal types against the dynamic type of the expression
in the type assertion. in the type assertion.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
TypeSwitchStmt = "switch" [ [ SimpleStmt ] ";" ] TypeSwitchGuard "{" { TypeCaseClause } "}" . TypeSwitchStmt = "switch" [ [ SimpleStmt ] ";" ] TypeSwitchGuard "{" { TypeCaseClause } "}" .
TypeSwitchGuard = identifier ":=" Expression "." "(" "type" ")" . TypeSwitchGuard = identifier ":=" Expression "." "(" "type" ")" .
TypeCaseClause = TypeSwitchCase ":" [ StatementList ] . TypeCaseClause = TypeSwitchCase ":" [ StatementList ] .
...@@ -3375,7 +3374,7 @@ A "for" statement specifies repeated execution of a block. The iteration is ...@@ -3375,7 +3374,7 @@ A "for" statement specifies repeated execution of a block. The iteration is
controlled by a condition, a "for" clause, or a "range" clause. controlled by a condition, a "for" clause, or a "range" clause.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
ForStmt = "for" [ Condition | ForClause | RangeClause ] Block . ForStmt = "for" [ Condition | ForClause | RangeClause ] Block .
Condition = Expression . Condition = Expression .
</pre> </pre>
...@@ -3403,7 +3402,7 @@ it declares ends at the end of the statement ...@@ -3403,7 +3402,7 @@ it declares ends at the end of the statement
(§Declarations and scope rules). (§Declarations and scope rules).
</p> </p>
<pre class="grammar"> <pre class="ebnf">
ForClause = [ InitStmt ] ";" [ Condition ] ";" [ PostStmt ] . ForClause = [ InitStmt ] ";" [ Condition ] ";" [ PostStmt ] .
InitStmt = SimpleStmt . InitStmt = SimpleStmt .
PostStmt = SimpleStmt . PostStmt = SimpleStmt .
...@@ -3439,7 +3438,7 @@ variable - or the current (index, element) or (key, value) pair to a pair ...@@ -3439,7 +3438,7 @@ variable - or the current (index, element) or (key, value) pair to a pair
of iteration variables - and then executes the block. of iteration variables - and then executes the block.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
RangeClause = ExpressionList ( "=" | ":=" ) "range" Expression . RangeClause = ExpressionList ( "=" | ":=" ) "range" Expression .
</pre> </pre>
...@@ -3518,7 +3517,7 @@ as an independent concurrent thread of control, or <i>goroutine</i>, ...@@ -3518,7 +3517,7 @@ as an independent concurrent thread of control, or <i>goroutine</i>,
within the same address space. within the same address space.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
GoStmt = "go" Expression . GoStmt = "go" Expression .
</pre> </pre>
...@@ -3542,7 +3541,7 @@ will proceed. It looks similar to a "switch" statement but with the ...@@ -3542,7 +3541,7 @@ will proceed. It looks similar to a "switch" statement but with the
cases all referring to communication operations. cases all referring to communication operations.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
SelectStmt = "select" "{" { CommClause } "}" . SelectStmt = "select" "{" { CommClause } "}" .
CommClause = CommCase ":" StatementList . CommClause = CommCase ":" StatementList .
CommCase = "case" ( SendExpr | RecvExpr) | "default" . CommCase = "case" ( SendExpr | RecvExpr) | "default" .
...@@ -3615,7 +3614,7 @@ A "return" statement terminates execution of the containing function ...@@ -3615,7 +3614,7 @@ A "return" statement terminates execution of the containing function
and optionally provides a result value or values to the caller. and optionally provides a result value or values to the caller.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
ReturnStmt = "return" [ ExpressionList ] . ReturnStmt = "return" [ ExpressionList ] .
</pre> </pre>
...@@ -3685,7 +3684,7 @@ A "break" statement terminates execution of the innermost ...@@ -3685,7 +3684,7 @@ A "break" statement terminates execution of the innermost
"for", "switch" or "select" statement. "for", "switch" or "select" statement.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
BreakStmt = "break" [ Label ]. BreakStmt = "break" [ Label ].
</pre> </pre>
...@@ -3711,7 +3710,7 @@ A "continue" statement begins the next iteration of the ...@@ -3711,7 +3710,7 @@ A "continue" statement begins the next iteration of the
innermost "for" loop at the post statement (§For statements). innermost "for" loop at the post statement (§For statements).
</p> </p>
<pre class="grammar"> <pre class="ebnf">
ContinueStmt = "continue" [ Label ]. ContinueStmt = "continue" [ Label ].
</pre> </pre>
...@@ -3725,7 +3724,7 @@ The optional label is analogous to that of a "break" statement. ...@@ -3725,7 +3724,7 @@ The optional label is analogous to that of a "break" statement.
A "goto" statement transfers control to the statement with the corresponding label. A "goto" statement transfers control to the statement with the corresponding label.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
GotoStmt = "goto" Label . GotoStmt = "goto" Label .
</pre> </pre>
...@@ -3760,7 +3759,7 @@ be used only as the final non-empty statement in a case or default clause in an ...@@ -3760,7 +3759,7 @@ be used only as the final non-empty statement in a case or default clause in an
expression "switch" statement. expression "switch" statement.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
FallthroughStmt = "fallthrough" . FallthroughStmt = "fallthrough" .
</pre> </pre>
...@@ -3772,7 +3771,7 @@ A "defer" statement invokes a function whose execution is deferred to the moment ...@@ -3772,7 +3771,7 @@ A "defer" statement invokes a function whose execution is deferred to the moment
the surrounding function returns. the surrounding function returns.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
DeferStmt = "defer" Expression . DeferStmt = "defer" Expression .
</pre> </pre>
...@@ -4016,7 +4015,7 @@ package clause acts as a block for scoping (§Declarations and scope ...@@ -4016,7 +4015,7 @@ package clause acts as a block for scoping (§Declarations and scope
rules). rules).
</p> </p>
<pre class="grammar"> <pre class="ebnf">
SourceFile = PackageClause { ImportDecl [ ";" ] } { Declaration [ ";" ] } . SourceFile = PackageClause { ImportDecl [ ";" ] } { Declaration [ ";" ] } .
</pre> </pre>
...@@ -4027,7 +4026,7 @@ A package clause begins each source file and defines the package ...@@ -4027,7 +4026,7 @@ A package clause begins each source file and defines the package
to which the file belongs. to which the file belongs.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
PackageClause = "package" PackageName . PackageClause = "package" PackageName .
</pre> </pre>
...@@ -4052,7 +4051,7 @@ the package. The file name may be relative to a repository of ...@@ -4052,7 +4051,7 @@ the package. The file name may be relative to a repository of
installed packages. installed packages.
</p> </p>
<pre class="grammar"> <pre class="ebnf">
ImportDecl = "import" ( ImportSpec | "(" [ ImportSpecList ] ")" ) . ImportDecl = "import" ( ImportSpec | "(" [ ImportSpecList ] ")" ) .
ImportSpecList = ImportSpec { ";" ImportSpec } [ ";" ] . ImportSpecList = ImportSpec { ";" ImportSpec } [ ";" ] .
ImportSpec = [ "." | PackageName ] PackageFileName . ImportSpec = [ "." | PackageName ] PackageFileName .
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment