summaryrefslogtreecommitdiff
path: root/usr/gri/pretty
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2008-10-31 14:27:34 -0700
committerRobert Griesemer <gri@golang.org>2008-10-31 14:27:34 -0700
commit9ba2767e2e37c0405cd197d2c9bf11fa81dc9c41 (patch)
tree54e72a4024713f3b1c85333b53be4787a222b0e1 /usr/gri/pretty
parent068dc3465b9085dad75fddc45465181c24971545 (diff)
downloadgolang-9ba2767e2e37c0405cd197d2c9bf11fa81dc9c41.tar.gz
- handle field tags in pretty printer
R=r OCL=18264 CL=18264
Diffstat (limited to 'usr/gri/pretty')
-rw-r--r--usr/gri/pretty/parser.go28
-rw-r--r--usr/gri/pretty/printer.go2
-rw-r--r--usr/gri/pretty/selftest0.go11
-rw-r--r--usr/gri/pretty/selftest1.go (renamed from usr/gri/pretty/selftest.go)0
-rwxr-xr-xusr/gri/pretty/test.sh8
5 files changed, 30 insertions, 19 deletions
diff --git a/usr/gri/pretty/parser.go b/usr/gri/pretty/parser.go
index d66958976..f9bb22a10 100644
--- a/usr/gri/pretty/parser.go
+++ b/usr/gri/pretty/parser.go
@@ -326,7 +326,7 @@ func (P *Parser) ParseVarDeclList(list *AST.List, ellipsis_ok bool) {
// parse a list of types
i0 := list.len();
for {
- list.Add(P.ParseVarDecl(i0 > 0));
+ list.Add(P.ParseVarDecl(ellipsis_ok /* param list */ && i0 > 0));
if P.tok == Scanner.COMMA {
P.Next();
} else {
@@ -340,7 +340,7 @@ func (P *Parser) ParseVarDeclList(list *AST.List, ellipsis_ok bool) {
P.Next();
}
- if i0 > 0 && typ == nil {
+ if ellipsis_ok /* param list */ && i0 > 0 && typ == nil {
// not the first parameter section; we must have a type
P.Error(P.pos, "type expected");
typ = AST.BadType;
@@ -365,18 +365,10 @@ func (P *Parser) ParseVarDeclList(list *AST.List, ellipsis_ok bool) {
} else {
// all list entries are types
// convert all type entries into type expressions
- if i0 > 0 {
- panic("internal parser error");
- }
-
- for i, n := 0, list.len(); i < n; i++ {
+ for i, n := i0, list.len(); i < n; i++ {
t := list.at(i).(*AST.Type);
list.set(i, AST.NewTypeExpr(t));
}
-
- if P.tok == Scanner.COMMA {
- panic("internal parser error");
- }
}
P.Ecart();
@@ -514,6 +506,8 @@ func (P *Parser) ParseMapType() *AST.Type {
}
+func (P *Parser) ParseOperand() *AST.Expr
+
func (P *Parser) ParseStructType() *AST.Type {
P.Trace("StructType");
@@ -522,10 +516,16 @@ func (P *Parser) ParseStructType() *AST.Type {
if P.tok == Scanner.LBRACE {
P.Next();
t.list = AST.NewList();
- for P.tok == Scanner.IDENT {
+ for P.tok != Scanner.RBRACE && P.tok != Scanner.EOF {
P.ParseVarDeclList(t.list, false);
- if P.tok != Scanner.RBRACE {
- P.Expect(Scanner.SEMICOLON);
+ if P.tok == Scanner.STRING {
+ // ParseOperand takes care of string concatenation
+ t.list.Add(P.ParseOperand());
+ }
+ if P.tok == Scanner.SEMICOLON {
+ P.Next();
+ } else {
+ break;
}
}
P.OptSemicolon();
diff --git a/usr/gri/pretty/printer.go b/usr/gri/pretty/printer.go
index fb5ceded0..cd20adb89 100644
--- a/usr/gri/pretty/printer.go
+++ b/usr/gri/pretty/printer.go
@@ -139,7 +139,7 @@ func (P *Printer) Fields(list *AST.List) {
for i, n := 0, list.len(); i < n; i++ {
x := list.at(i).(*AST.Expr);
if i > 0 {
- if prev == Scanner.TYPE {
+ if prev == Scanner.TYPE && x.tok != Scanner.STRING || prev == Scanner.STRING {
P.semi, P.newl = true, 1;
} else if prev == x.tok {
P.String(0, ", ");
diff --git a/usr/gri/pretty/selftest0.go b/usr/gri/pretty/selftest0.go
new file mode 100644
index 000000000..09b1283db
--- /dev/null
+++ b/usr/gri/pretty/selftest0.go
@@ -0,0 +1,11 @@
+// Copyright 2009 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 Proto struct {
+ a int "a tag";
+ b, c, d *Proto "bcd" "tag";
+ *Proto "proto tag"
+}
diff --git a/usr/gri/pretty/selftest.go b/usr/gri/pretty/selftest1.go
index 4365df607..4365df607 100644
--- a/usr/gri/pretty/selftest.go
+++ b/usr/gri/pretty/selftest1.go
diff --git a/usr/gri/pretty/test.sh b/usr/gri/pretty/test.sh
index a4ca3ecaa..141193cf2 100755
--- a/usr/gri/pretty/test.sh
+++ b/usr/gri/pretty/test.sh
@@ -21,7 +21,7 @@ count() {
apply1() {
#echo $1 $2
case `basename $F` in
- selftest.go | func3.go | bug014.go | bug029.go | bug032.go | bug050.go | \
+ selftest1.go | func3.go | bug014.go | bug029.go | bug032.go | bug050.go | \
bug068.go | bug088.go | bug083.go | bug106.go ) ;; # skip - files contain syntax errors
* ) $1 $2; count ;;
esac
@@ -120,11 +120,11 @@ runtests() {
}
-# run selftest always
-./pretty -t selftest.go > $TMP1
+# run selftest1 always
+./pretty -t selftest1.go > $TMP1
if [ $? != 0 ]; then
cat $TMP1
- echo "Error (selftest): pretty -t selftest.go"
+ echo "Error (selftest1): pretty -t selftest1.go"
exit 1
fi
count