summaryrefslogtreecommitdiff
path: root/test/syntax
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-01-26 23:13:22 -0800
committerRuss Cox <rsc@golang.org>2010-01-26 23:13:22 -0800
commitada0b68687ffc33bdb8259a0c14498aa4b574f32 (patch)
tree1535ebe4c0e90e048e14683b415f114c7471341a /test/syntax
parent84f677d33e0cfca4cd5994d3202e340b442361d1 (diff)
downloadgo-ada0b68687ffc33bdb8259a0c14498aa4b574f32.tar.gz
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 http://codereview.appspot.com/194085
Diffstat (limited to 'test/syntax')
-rw-r--r--test/syntax/forvar.go10
-rw-r--r--test/syntax/import.go14
-rw-r--r--test/syntax/interface.go14
-rw-r--r--test/syntax/semi1.go14
-rw-r--r--test/syntax/semi2.go14
-rw-r--r--test/syntax/semi3.go14
-rw-r--r--test/syntax/semi4.go14
-rw-r--r--test/syntax/semi5.go13
-rw-r--r--test/syntax/semi6.go13
-rw-r--r--test/syntax/semi7.go14
-rw-r--r--test/syntax/slice.go9
11 files changed, 143 insertions, 0 deletions
diff --git a/test/syntax/forvar.go b/test/syntax/forvar.go
new file mode 100644
index 000000000..f12ce55ca
--- /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 000000000..90e7df007
--- /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 000000000..a7f43533a
--- /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 000000000..c805bb006
--- /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 000000000..237fac8f3
--- /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 000000000..2dbcb5984
--- /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 000000000..2268cf75a
--- /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 000000000..7f907fb8f
--- /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 000000000..75de3e0a1
--- /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 000000000..458904357
--- /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 000000000..4bc5d4d8d
--- /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"