diff options
author | Russ Cox <rsc@golang.org> | 2010-01-26 23:13:22 -0800 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-01-26 23:13:22 -0800 |
commit | 2a01d7287851e988d1e093dbe5788d3631e770b5 (patch) | |
tree | 396cef5e7b5379213c4d9f6ed1d6aa64c60a7f78 /test/syntax | |
parent | 9f5264f2999b7fa44a3642cf489a93c52d9d0b2f (diff) | |
download | go-2a01d7287851e988d1e093dbe5788d3631e770b5.tar.gz go-2a01d7287851e988d1e093dbe5788d3631e770b5.zip |
gc: improved syntax errors
* example-based syntax errors (go.errors)
* enable bison's more specific errors
and translate grammar token names into
tokens like ++
* test cases
R=ken2, r, ken3
CC=golang-dev
https://golang.org/cl/194085
Diffstat (limited to 'test/syntax')
-rw-r--r-- | test/syntax/forvar.go | 10 | ||||
-rw-r--r-- | test/syntax/import.go | 14 | ||||
-rw-r--r-- | test/syntax/interface.go | 14 | ||||
-rw-r--r-- | test/syntax/semi1.go | 14 | ||||
-rw-r--r-- | test/syntax/semi2.go | 14 | ||||
-rw-r--r-- | test/syntax/semi3.go | 14 | ||||
-rw-r--r-- | test/syntax/semi4.go | 14 | ||||
-rw-r--r-- | test/syntax/semi5.go | 13 | ||||
-rw-r--r-- | test/syntax/semi6.go | 13 | ||||
-rw-r--r-- | test/syntax/semi7.go | 14 | ||||
-rw-r--r-- | test/syntax/slice.go | 9 |
11 files changed, 143 insertions, 0 deletions
diff --git a/test/syntax/forvar.go b/test/syntax/forvar.go new file mode 100644 index 0000000000..f12ce55cae --- /dev/null +++ b/test/syntax/forvar.go @@ -0,0 +1,10 @@ +// errchk $G -e $D/$F.go + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + for var x = 0; x < 10; x++ { // ERROR "var declaration not allowed in for initializer" diff --git a/test/syntax/import.go b/test/syntax/import.go new file mode 100644 index 0000000000..90e7df007e --- /dev/null +++ b/test/syntax/import.go @@ -0,0 +1,14 @@ +// errchk $G -e $D/$F.go + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "io", // ERROR "unexpected ," + "os" +) + + diff --git a/test/syntax/interface.go b/test/syntax/interface.go new file mode 100644 index 0000000000..a7f43533a2 --- /dev/null +++ b/test/syntax/interface.go @@ -0,0 +1,14 @@ +// errchk $G -e $D/$F.go + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type T interface { + f, g () // ERROR "name list not allowed in interface type" +} + + + diff --git a/test/syntax/semi1.go b/test/syntax/semi1.go new file mode 100644 index 0000000000..c805bb0064 --- /dev/null +++ b/test/syntax/semi1.go @@ -0,0 +1,14 @@ +// errchk $G -e $D/$F.go + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + if x; y // ERROR "unexpected ; or newline before {" + { + z + + diff --git a/test/syntax/semi2.go b/test/syntax/semi2.go new file mode 100644 index 0000000000..237fac8f3b --- /dev/null +++ b/test/syntax/semi2.go @@ -0,0 +1,14 @@ +// errchk $G -e $D/$F.go + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + switch x; y // ERROR "unexpected ; or newline before {" + { + z + + diff --git a/test/syntax/semi3.go b/test/syntax/semi3.go new file mode 100644 index 0000000000..2dbcb59843 --- /dev/null +++ b/test/syntax/semi3.go @@ -0,0 +1,14 @@ +// errchk $G -e $D/$F.go + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + for x; y; z // ERROR "unexpected ; or newline before {" + { + z + + diff --git a/test/syntax/semi4.go b/test/syntax/semi4.go new file mode 100644 index 0000000000..2268cf75af --- /dev/null +++ b/test/syntax/semi4.go @@ -0,0 +1,14 @@ +// errchk $G -e $D/$F.go + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + for x + { // ERROR "unexpected ; or newline before {" + z + + diff --git a/test/syntax/semi5.go b/test/syntax/semi5.go new file mode 100644 index 0000000000..7f907fb8f8 --- /dev/null +++ b/test/syntax/semi5.go @@ -0,0 +1,13 @@ +// errchk $G -e $D/$F.go + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() +{ // ERROR "unexpected ; or newline before {" + + + diff --git a/test/syntax/semi6.go b/test/syntax/semi6.go new file mode 100644 index 0000000000..75de3e0a15 --- /dev/null +++ b/test/syntax/semi6.go @@ -0,0 +1,13 @@ +// errchk $G -e $D/$F.go + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type T // ERROR "unexpected ; or newline in type declaration" +{ + + + diff --git a/test/syntax/semi7.go b/test/syntax/semi7.go new file mode 100644 index 0000000000..4589043575 --- /dev/null +++ b/test/syntax/semi7.go @@ -0,0 +1,14 @@ +// errchk $G -e $D/$F.go + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + if x { } + else { } // ERROR "unexpected ; or newline before else" +} + + diff --git a/test/syntax/slice.go b/test/syntax/slice.go new file mode 100644 index 0000000000..4bc5d4d8d2 --- /dev/null +++ b/test/syntax/slice.go @@ -0,0 +1,9 @@ +// errchk $G -e $D/$F.go + +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +var x = y[:z] // ERROR "missing lower bound in slice expression" |