Commit 3c7271f0 authored by Robert Griesemer's avatar Robert Griesemer

go spec: be precise with the use of the informal ellipsis … and the Go token ...

Fixes #1867.

R=r
CC=golang-dev
https://golang.org/cl/4538092
parent 46f482a2
...@@ -48,7 +48,7 @@ The syntax is specified using Extended Backus-Naur Form (EBNF): ...@@ -48,7 +48,7 @@ The syntax is specified using Extended Backus-Naur Form (EBNF):
Production = production_name "=" [ Expression ] "." . Production = production_name "=" [ Expression ] "." .
Expression = Alternative { "|" Alternative } . Expression = Alternative { "|" Alternative } .
Alternative = Term { Term } . Alternative = Term { Term } .
Term = production_name | token [ "..." token ] | Group | Option | Repetition . Term = production_name | token [ "" token ] | Group | Option | Repetition .
Group = "(" Expression ")" . Group = "(" Expression ")" .
Option = "[" Expression "]" . Option = "[" Expression "]" .
Repetition = "{" Expression "}" . Repetition = "{" Expression "}" .
...@@ -72,8 +72,12 @@ double quotes <code>""</code> or back quotes <code>``</code>. ...@@ -72,8 +72,12 @@ double quotes <code>""</code> or back quotes <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. The horizontal
ellipis … is also used elsewhere in the spec to informally denote various
enumerations or code snippets that are not further specified. The character …
(as opposed to the three characters <code>...</code>) is not a token of the Go
language.
</p> </p>
<h2 id="Source_code_representation">Source code representation</h2> <h2 id="Source_code_representation">Source code representation</h2>
...@@ -122,9 +126,9 @@ The underscore character <code>_</code> (U+005F) is considered a letter. ...@@ -122,9 +126,9 @@ The underscore character <code>_</code> (U+005F) is considered a letter.
</p> </p>
<pre class="ebnf"> <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" .
hex_digit = "0" ... "9" | "A" ... "F" | "a" ... "f" . hex_digit = "0" … "9" | "A" … "F" | "a" … "f" .
</pre> </pre>
<h2 id="Lexical_elements">Lexical elements</h2> <h2 id="Lexical_elements">Lexical elements</h2>
...@@ -286,7 +290,7 @@ An optional prefix sets a non-decimal base: <code>0</code> for octal, <code>0x</ ...@@ -286,7 +290,7 @@ An optional prefix sets a non-decimal base: <code>0</code> for octal, <code>0x</
</p> </p>
<pre class="ebnf"> <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 } .
hex_lit = "0" ( "x" | "X" ) hex_digit { hex_digit } . hex_lit = "0" ( "x" | "X" ) hex_digit { hex_digit } .
</pre> </pre>
...@@ -1053,9 +1057,9 @@ have the method set ...@@ -1053,9 +1057,9 @@ have the method set
</p> </p>
<pre> <pre>
func (p T) Read(b Buffer) bool { return ... } func (p T) Read(b Buffer) bool { return }
func (p T) Write(b Buffer) bool { return ... } func (p T) Write(b Buffer) bool { return }
func (p T) Close() { ... } func (p T) Close() { }
</pre> </pre>
<p> <p>
...@@ -1093,8 +1097,8 @@ If <code>S1</code> and <code>S2</code> also implement ...@@ -1093,8 +1097,8 @@ If <code>S1</code> and <code>S2</code> also implement
</p> </p>
<pre> <pre>
func (p T) Lock() { ... } func (p T) Lock() { }
func (p T) Unlock() { ... } func (p T) Unlock() { }
</pre> </pre>
<p> <p>
...@@ -2099,7 +2103,7 @@ element index plus one. A slice literal has the form ...@@ -2099,7 +2103,7 @@ element index plus one. A slice literal has the form
</p> </p>
<pre> <pre>
[]T{x1, x2, ... xn} []T{x1, x2, xn}
</pre> </pre>
<p> <p>
...@@ -2107,7 +2111,7 @@ and is a shortcut for a slice operation applied to an array literal: ...@@ -2107,7 +2111,7 @@ and is a shortcut for a slice operation applied to an array literal:
</p> </p>
<pre> <pre>
[n]T{x1, x2, ... xn}[0 : n] [n]T{x1, x2, xn}[0 : n]
</pre> </pre>
<p> <p>
...@@ -2133,8 +2137,8 @@ parentheses. ...@@ -2133,8 +2137,8 @@ parentheses.
</p> </p>
<pre> <pre>
if x == (T{a,b,c}[i]) { ... } if x == (T{a,b,c}[i]) { }
if (x == T{a,b,c}[i]) { ... } if (x == T{a,b,c}[i]) { }
</pre> </pre>
<p> <p>
...@@ -2567,11 +2571,11 @@ Given an expression <code>f</code> of function type ...@@ -2567,11 +2571,11 @@ Given an expression <code>f</code> of function type
</p> </p>
<pre> <pre>
f(a1, a2, ... an) f(a1, a2, an)
</pre> </pre>
<p> <p>
calls <code>f</code> with arguments <code>a1, a2, ... an</code>. calls <code>f</code> with arguments <code>a1, a2, an</code>.
Except for one special case, arguments must be single-valued expressions Except for one special case, arguments must be single-valued expressions
<a href="#Assignability">assignable</a> to the parameter types of <a href="#Assignability">assignable</a> to the parameter types of
<code>F</code> and are evaluated before the function is called. <code>F</code> and are evaluated before the function is called.
...@@ -2650,7 +2654,7 @@ arguments bound to the final parameter and may differ for each call site. ...@@ -2650,7 +2654,7 @@ arguments bound to the final parameter and may differ for each call site.
Given the function and call Given the function and call
</p> </p>
<pre> <pre>
func Greeting(prefix string, who ... string) func Greeting(prefix string, who ...string)
Greeting("hello:", "Joe", "Anna", "Eileen") Greeting("hello:", "Joe", "Anna", "Eileen")
</pre> </pre>
...@@ -4891,7 +4895,7 @@ package main ...@@ -4891,7 +4895,7 @@ package main
import "fmt" import "fmt"
// Send the sequence 2, 3, 4, ... to channel 'ch'. // Send the sequence 2, 3, 4, to channel 'ch'.
func generate(ch chan&lt;- int) { func generate(ch chan&lt;- int) {
for i := 2; ; i++ { for i := 2; ; i++ {
ch &lt;- i // Send 'i' to channel 'ch'. ch &lt;- i // Send 'i' to channel 'ch'.
...@@ -5042,7 +5046,7 @@ arguments and returns no value. ...@@ -5042,7 +5046,7 @@ arguments and returns no value.
</p> </p>
<pre> <pre>
func main() { ... } func main() { }
</pre> </pre>
<p> <p>
......
...@@ -99,7 +99,8 @@ func (p *ebnfParser) parseTerm() bool { ...@@ -99,7 +99,8 @@ func (p *ebnfParser) parseTerm() bool {
case token.STRING: case token.STRING:
p.next() p.next()
if p.tok == token.ELLIPSIS { const ellipsis = "…" // U+2026, the horizontal ellipsis character
if p.tok == token.ILLEGAL && p.lit == ellipsis {
p.next() p.next()
p.expect(token.STRING) p.expect(token.STRING)
} }
...@@ -157,7 +158,7 @@ func (p *ebnfParser) parse(fset *token.FileSet, out io.Writer, src []byte) { ...@@ -157,7 +158,7 @@ func (p *ebnfParser) parse(fset *token.FileSet, out io.Writer, src []byte) {
p.out = out p.out = out
p.src = src p.src = src
p.file = fset.AddFile("", fset.Base(), len(src)) p.file = fset.AddFile("", fset.Base(), len(src))
p.scanner.Init(p.file, src, p, 0) p.scanner.Init(p.file, src, p, scanner.AllowIllegalChars)
p.next() // initializes pos, tok, lit p.next() // initializes pos, tok, lit
// process source // process source
......
...@@ -22,7 +22,7 @@ var grammars = []string{ ...@@ -22,7 +22,7 @@ var grammars = []string{
`Program = "a" | "b" "c" .`, `Program = "a" | "b" "c" .`,
`Program = "a" ... "z" .`, `Program = "a" "z" .`,
`Program = Song . `Program = Song .
Song = { Note } . Song = { Note } .
......
...@@ -95,7 +95,8 @@ func (p *parser) parseTerm() (x Expression) { ...@@ -95,7 +95,8 @@ func (p *parser) parseTerm() (x Expression) {
case token.STRING: case token.STRING:
tok := p.parseToken() tok := p.parseToken()
x = tok x = tok
if p.tok == token.ELLIPSIS { const ellipsis = "…" // U+2026, the horizontal ellipsis character
if p.tok == token.ILLEGAL && p.lit == ellipsis {
p.next() p.next()
x = &Range{tok, p.parseToken()} x = &Range{tok, p.parseToken()}
} }
...@@ -177,7 +178,7 @@ func (p *parser) parse(fset *token.FileSet, filename string, src []byte) Grammar ...@@ -177,7 +178,7 @@ func (p *parser) parse(fset *token.FileSet, filename string, src []byte) Grammar
// initialize parser // initialize parser
p.fset = fset p.fset = fset
p.ErrorVector.Reset() p.ErrorVector.Reset()
p.scanner.Init(fset.AddFile(filename, fset.Base(), len(src)), src, p, 0) p.scanner.Init(fset.AddFile(filename, fset.Base(), len(src)), src, p, scanner.AllowIllegalChars)
p.next() // initializes pos, tok, lit p.next() // initializes pos, tok, lit
grammar := make(Grammar) grammar := make(Grammar)
......
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