]> Cypherpunks repositories - gostls13.git/commitdiff
- fixed bug which prevented parser.go from compiling
authorRobert Griesemer <gri@golang.org>
Fri, 19 Sep 2008 05:53:54 +0000 (22:53 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 19 Sep 2008 05:53:54 +0000 (22:53 -0700)
  (typo in ptr decl lead to an unresolved forward declaration)
- fixed parser bugs
- fixed Makefile
- now successfully parses most code

Issues:
- composite literals (cannot be identified easily from syntax alone)
- new(T, ...) (cannot be identified easily from syntax alone since
  new is not a keyword and thus could be a different function then
  the allocation function at which point "new((x + y))" is legal,
  but the inner "(x" looks like the beginning of a function type)

R=r
OCL=15515
CL=15515

usr/gri/pretty/Makefile
usr/gri/pretty/parser.go
usr/gri/pretty/pretty.go
usr/gri/pretty/scanner.go

index a1bde84f1e441e97cec44e9354e9812b1b758fcc..81ca81286fe7dfffdc44b25a4bc0473c5512f8c4 100644 (file)
@@ -8,9 +8,9 @@ L=6l
 pretty: pretty.6
        $(L) -o pretty pretty.6
 
-test: all
+test: pretty
        pretty *.go
-       pretty $(GOROOT)/test/fixedbugs/*.go  # some files legally don't compile
+       pretty $(GOROOT)/test/fixedbugs/*.go  # some files legally don't compile
        pretty $(GOROOT)/test/sieve.go
        pretty $(GOROOT)/src/pkg/*.go
        pretty $(GOROOT)/src/lib/flag.go
@@ -19,8 +19,6 @@ test: all
        pretty $(GOROOT)/src/lib/math/*.go
        pretty $(GOROOT)/src/lib/container/*.go
        pretty $(GOROOT)/src/syscall/*.go
-       pretty base.go decls.go
-       pretty -token_chan base.go decls.go
        echo "PASSED"
 
 install: pretty
index f66efd6216a6838e603cc04128543c8e979a42f8..130030365ce49926a4e45950398badda4fee00eb 100644 (file)
@@ -136,16 +136,19 @@ func (P *Parser) ParseIdent() *AST.Ident {
 }
 
 
-func (P *Parser) ParseIdentList() {
+func (P *Parser) ParseIdentList() int {
        P.Trace("IdentList");
 
        P.ParseIdent();
+       n := 1;
        for P.tok == Scanner.COMMA {
                P.Next();
                P.ParseIdent();
+               n++;
        }
 
        P.Ecart();
+       return n;
 }
 
 
@@ -155,6 +158,10 @@ func (P *Parser) ParseQualifiedIdent(ident *AST.Ident) AST.Expr {
        if ident == nil {
                ident = P.ParseIdent();
        }
+       if P.tok == Scanner.PERIOD {
+                P.Next();
+                ident = P.ParseIdent();
+       }
        
        P.Ecart();
        return ident;
@@ -204,6 +211,7 @@ func (P *Parser) ParseArrayType() {
                P.ParseExpression();
        }
        P.Expect(Scanner.RBRACK);
+       P.ParseType();
 
        P.Ecart();      
 }
@@ -227,39 +235,43 @@ func (P *Parser) ParseChannelType() {
 }
 
 
-func (P *Parser) ParseVarDeclList() {
+func (P *Parser) ParseVarDeclList() int {
        P.Trace("VarDeclList");
        
-       P.ParseIdentList();
+       n := P.ParseIdentList();
        P.ParseVarType();
        
        P.Ecart();
+       return n;
 }
 
 
-func (P *Parser) ParseParameterList() {
+func (P *Parser) ParseParameterList() int {
        P.Trace("ParameterList");
        
-       P.ParseVarDeclList();
+       n := P.ParseVarDeclList();
        for P.tok == Scanner.COMMA {
                P.Next();
-               P.ParseVarDeclList();
+               n += P.ParseVarDeclList();
        }
        
        P.Ecart();
+       return n;
 }
 
 
-func (P *Parser) ParseParameters() {
+func (P *Parser) ParseParameters() int {
        P.Trace("Parameters");
        
+       n := 0;
        P.Expect(Scanner.LPAREN);
        if P.tok != Scanner.RPAREN {
-               P.ParseParameterList();
+               n = P.ParseParameterList();
        }
        P.Expect(Scanner.RPAREN);
        
        P.Ecart();
+       return n;
 }
 
 
@@ -268,7 +280,7 @@ func (P *Parser) ParseResult() {
        
        if P.tok == Scanner.LPAREN {
                // one or more named results
-               // TODO: here we allow empty returns - should proably fix this
+               // TODO: here we allow empty returns - should probably fix this
                P.ParseParameters();
 
        } else {
@@ -316,14 +328,11 @@ func (P *Parser) ParseNamedSignature() *AST.Ident {
        
        P.OpenScope();
        P.level--;
-       p0 := 0;
 
        if P.tok == Scanner.LPAREN {
                recv_pos := P.pos;
-               P.ParseParameters();
-               //p0 = sig.entries.len;
-               if p0 != 1 {
-                       print("p0 = ", p0, "\n");
+               n := P.ParseParameters();
+               if n != 1 {
                        P.Error(recv_pos, "must have exactly one receiver");
                        panic("UNIMPLEMENTED (ParseNamedSignature)");
                        // TODO do something useful here
@@ -334,7 +343,6 @@ func (P *Parser) ParseNamedSignature() *AST.Ident {
 
        P.ParseParameters();
        
-       //r0 := sig.entries.len;
        P.ParseResult();
        P.level++;
        P.CloseScope();
@@ -348,7 +356,7 @@ func (P *Parser) ParseFunctionType() {
        P.Trace("FunctionType");
        
        typ := P.ParseSignature();
-       
+
        P.Ecart();
 }
 
@@ -515,7 +523,7 @@ func (P *Parser) ParseFunctionLit() AST.Expr {
        P.Trace("FunctionLit");
        
        P.Expect(Scanner.FUNC);
-       P.ParseFunctionType();
+       P.ParseSignature();  // replace this with ParseFunctionType() and it won't work - 6g bug?
        P.ParseBlock();
        
        P.Ecart();
@@ -671,7 +679,17 @@ func (P *Parser) ParseCall(x AST.Expr) AST.Expr {
 
        P.Expect(Scanner.LPAREN);
        if P.tok != Scanner.RPAREN {
-               P.ParseExpressionList();
+               // first arguments could be a type if the call is to "new"
+               if P.tok != Scanner.IDENT && P.TryType() {
+                       if P.tok == Scanner.COMMA {
+                                P.Next();
+                                if P.tok != Scanner.RPAREN {
+                                         P.ParseExpressionList();
+                                }
+                       }
+               } else {
+                       P.ParseExpressionList();
+               }
        }
        P.Expect(Scanner.RPAREN);
        
@@ -866,7 +884,7 @@ func (P *Parser) ParseControlFlowStat(tok int) {
 }
 
 
-func (P *Parser) ParseIfStat() *AST.IfStat {
+func (P *Parser) ParseIfStat() {
        P.Trace("IfStat");
        
        P.Expect(Scanner.IF);
@@ -895,7 +913,6 @@ func (P *Parser) ParseIfStat() *AST.IfStat {
        P.CloseScope();
        
        P.Ecart();
-       return nil;
 }
 
 
@@ -1152,7 +1169,7 @@ func (P *Parser) ParseTypeSpec(exported bool) {
 func (P *Parser) ParseVarSpec(exported bool) {
        P.Trace("VarSpec");
        
-       list := P.ParseIdentList();
+       P.ParseIdentList();
        if P.tok == Scanner.ASSIGN {
                P.Next();
                P.ParseExpressionList();
index 48f470f185d3e8181f0c61edbb424dfd7e5d7157..79763a51e4f0438b76dfa919cbdb40561c57ff66 100644 (file)
@@ -32,6 +32,7 @@ func main() {
                 return;
             }
 
+           print("- ", src_file, "\n");
            scanner := new(Scanner.Scanner);
             scanner.Open(src_file, src);
 
index 1e2645cb2649f1811a74b506dfe3247827b481f4..cb2d419518a0558547bd78545ffff6b791036b38 100644 (file)
@@ -777,7 +777,7 @@ export type Token struct {
 
 
 func (S *Scanner) TokenStream() *<-chan *Token {
-       ch := new(chan *Token);
+       ch := new(chan *Token, 100);
        go func(S *Scanner, ch *chan <- *Token) {
                for {
                        t := new(Token);