Skip to content

Commit

Permalink
spec: permit parentheses around builtin function names
Browse files Browse the repository at this point in the history
Not a language change.

This is simply documenting the status quo which permits
builtin function names to be parenthesized in calls; e.g.,
both

        len(s)
and
        (((len)))(s)

are accepted by all compilers and go/types.

Changed the grammar by merging the details of BuiltinCall
with ordinary Calls. Also renamed the Call production to
Arguments which more clearly identifies that part of the
grammar and also matches better with its counterpart on
the declaration side (Parameters).

The fact that the first argument can be a type (for builtins)
or cannot be a type (for regular function calls) is expressed
in the prose, no need to make the grammar more complicated.

Fixes golang#9001.

LGTM=iant, r, rsc
R=r, rsc, iant, ken, dave
CC=golang-codereviews
https://golang.org/cl/160570043
  • Loading branch information
griesemer authored and wheatman committed Jul 18, 2018
1 parent 4656081 commit 576b6c4
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions doc/go_spec.html
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of October 23, 2014",
"Subtitle": "Version of October 27, 2014",
"Path": "/ref/spec"
}-->

Expand Down Expand Up @@ -2446,21 +2446,19 @@ <h3 id="Primary_expressions">Primary expressions</h3>
PrimaryExpr =
Operand |
Conversion |
BuiltinCall |
PrimaryExpr Selector |
PrimaryExpr Index |
PrimaryExpr Slice |
PrimaryExpr TypeAssertion |
PrimaryExpr Call .
PrimaryExpr Arguments .

Selector = "." identifier .
Index = "[" Expression "]" .
Slice = "[" ( [ Expression ] ":" [ Expression ] ) |
( [ Expression ] ":" Expression ":" Expression )
"]" .
TypeAssertion = "." "(" Type ")" .
Call = "(" [ ArgumentList [ "," ] ] ")" .
ArgumentList = ExpressionList [ "..." ] .
Arguments = "(" [ ( ExpressionList | Type [ "," ExpressionList ] ) [ "..." ] [ "," ] ] ")" .
</pre>


Expand Down Expand Up @@ -3163,7 +3161,7 @@ <h3 id="Calls">Calls</h3>
<pre>
math.Atan2(x, y) // function call
var pt *Point
pt.Scale(3.5) // method call with receiver pt
pt.Scale(3.5) // method call with receiver pt
</pre>

<p>
Expand Down Expand Up @@ -5368,11 +5366,6 @@ <h2 id="Built-in_functions">Built-in functions</h2>
they cannot be used as function values.
</p>

<pre class="ebnf">
BuiltinCall = identifier "(" [ BuiltinArgs [ "," ] ] ")" .
BuiltinArgs = Type [ "," ArgumentList ] | ArgumentList .
</pre>

<h3 id="Close">Close</h3>

<p>
Expand Down

0 comments on commit 576b6c4

Please sign in to comment.