pretty $(GOROOT)/usr/r/*/*.go
echo "DONE"
-# These tests don't work yet
-testfull: pretty
- pretty *.go
- pretty ../gosrc/*.go
- pretty $(GOROOT)/test/*.go
- pretty $(GOROOT)/src/pkg/*.go
- pretty $(GOROOT)/src/lib/*.go
- pretty $(GOROOT)/src/lib/*/*.go
- pretty $(GOROOT)/usr/r/*/*.go
- echo "DONE"
-
install: pretty
cp pretty $(HOME)/bin/pretty
pos := P.pos;
P.Next();
y := P.ParseIdentList();
- x := Node.NewExpr(pos, Scanner.COMMA, x, y);
+ x = Node.NewExpr(pos, Scanner.COMMA, x, y);
}
P.Ecart();
}
-func (P *Parser) ParseMethodDecl() *Node.Decl {
+func (P *Parser) ParseMethodSpec(list *Node.List) {
P.Trace("MethodDecl");
- P.ParseIdent();
- P.ParseFunctionType();
+ list.Add(P.ParseIdent());
+ list.Add(Node.NewTypeExpr(P.ParseFunctionType()));
P.Ecart();
- return nil;
}
P.Expect(Scanner.INTERFACE);
if P.tok == Scanner.LBRACE {
P.Next();
+ t.list = Node.NewList();
for P.tok == Scanner.IDENT {
- P.ParseMethodDecl();
+ P.ParseMethodSpec(t.list);
if P.tok != Scanner.RBRACE {
P.Expect(Scanner.SEMICOLON);
}
func (P *Parser) ParseSelectorOrTypeGuard(x *Node.Expr) *Node.Expr {
P.Trace("SelectorOrTypeGuard");
- pos := P.pos;
+ x = Node.NewExpr(P.pos, Scanner.PERIOD, x, nil);
P.Expect(Scanner.PERIOD);
if P.tok == Scanner.IDENT {
- y := P.ParseIdent();
- x = Node.NewExpr(pos, Scanner.PERIOD, x, y);
+ x.y = P.ParseIdent();
} else {
P.Expect(Scanner.LPAREN);
- P.ParseType();
+ x.t = P.ParseType();
P.Expect(Scanner.RPAREN);
}
func (P *Printer) Fields(list *Node.List) {
+ P.OpenScope(" {");
var prev int;
for i, n := 0, list.len(); i < n; i++ {
x := list.at(i).(*Node.Expr);
prev = x.tok;
}
P.newl = 1;
+ P.CloseScope("}");
}
P.String(0, "]");
P.Type(t.elt);
- case Scanner.STRUCT:
- P.String(t.pos, "struct");
+ case Scanner.STRUCT, Scanner.INTERFACE:
+ P.Token(t.pos, t.tok);
if t.list != nil {
- P.OpenScope(" {");
+ P.Blank();
P.Fields(t.list);
- P.CloseScope("}");
}
case Scanner.MAP:
P.String(t.pos, m);
P.Type(t.elt);
- case Scanner.INTERFACE:
- P.String(t.pos, "interface");
- if t.list != nil {
- P.OpenScope(" {");
- /*
- for i := 0; i < x.methods.len(); i++ {
- P.Print(x.methods.at(i));
- P.newl, P.semi = true, true;
- }
- */
- P.CloseScope("}");
- }
-
case Scanner.MUL:
P.String(t.pos, "*");
P.Type(t.elt);
switch x.tok {
case Scanner.TYPE:
+ // type expr
P.Type(x.t);
case Scanner.IDENT, Scanner.INT, Scanner.STRING, Scanner.FLOAT:
+ // literal
P.String(x.pos, x.s);
case Scanner.COMMA:
+ // list
P.Expr1(x.x, 0);
P.String(x.pos, ", ");
P.Expr1(x.y, 0);
case Scanner.PERIOD:
+ // selector or type guard
P.Expr1(x.x, 8); // 8 == highest precedence
P.String(x.pos, ".");
- P.Expr1(x.y, 8);
+ if x.y != nil {
+ P.Expr1(x.y, 8);
+ } else {
+ P.String(0, "(");
+ P.Type(x.t);
+ P.String(0, ")");
+ }
case Scanner.LBRACK:
+ // index
P.Expr1(x.x, 8);
P.String(x.pos, "[");
P.Expr1(x.y, 0);
P.String(0, "]");
case Scanner.LPAREN:
+ // call
P.Expr1(x.x, 8);
P.String(x.pos, "(");
P.Expr1(x.y, 0);
P.String(0, ")");
case Scanner.LBRACE:
+ // composite
P.Expr1(x.x, 8);
P.String(x.pos, "{");
P.Expr1(x.y, 0);
P.String(0, "}");
default:
+ // unary and binary expressions
if x.x == nil {
// unary expression
P.Token(x.pos, x.tok);
func (P *Printer) ControlClause(s *Node.Stat) {
- if s.init != nil {
- P.Blank();
- P.Stat(s.init);
- P.semi = true;
- }
- if s.expr != nil {
+ has_post := s.tok == Scanner.FOR && s.post != nil; // post also used by "if"
+ if s.init == nil && !has_post {
+ // no semicolons required
+ if s.expr != nil {
+ P.Blank();
+ P.Expr(s.expr);
+ }
+ } else {
+ // all semicolons required
P.Blank();
- P.Expr(s.expr);
- P.semi = false;
- }
- if s.tok == Scanner.FOR && s.post != nil {
+ if s.init != nil {
+ P.Stat(s.init);
+ }
P.semi = true;
P.Blank();
- P.Stat(s.post);
- P.semi = false;
+ if s.expr != nil {
+ P.Expr(s.expr);
+ }
+ if has_post {
+ P.semi = true;
+ P.Blank();
+ P.Stat(s.post);
+ P.semi = false
+ }
}
P.Blank();
}
P.Expr(s.expr);
}
P.String(0, ":");
- P.OpenScope("");
+ P.indent++;
+ P.newl = 1;
P.StatementList(s.block);
- P.CloseScope("");
+ P.indent--;
+ P.newl = 1;
case Scanner.GO, Scanner.RETURN, Scanner.FALLTHROUGH, Scanner.BREAK, Scanner.CONTINUE, Scanner.GOTO:
P.Token(s.pos, s.tok);