diff options
author | Robert Griesemer <gri@golang.org> | 2009-03-10 18:20:08 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2009-03-10 18:20:08 -0700 |
commit | 89593acddd3e4de46332b4c7581a90d930454efc (patch) | |
tree | c0fe4eb6def1ed4b3a614c2a13d2963f6259bcbd /usr/gri/pretty/parser.go | |
parent | 058c8414302cb47e5fc82f872619c9b9a487ce24 (diff) | |
download | golang-89593acddd3e4de46332b4c7581a90d930454efc.tar.gz |
snapshot of today
(little progress with interface printing, but now shows a
list of exported function names)
R=r
OCL=26082
CL=26082
Diffstat (limited to 'usr/gri/pretty/parser.go')
-rw-r--r-- | usr/gri/pretty/parser.go | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/usr/gri/pretty/parser.go b/usr/gri/pretty/parser.go index 4712996d9..4d37c87ad 100644 --- a/usr/gri/pretty/parser.go +++ b/usr/gri/pretty/parser.go @@ -8,8 +8,7 @@ // // A client may parse the entire program (ParseProgram), only the package // clause (ParsePackageClause), or the package clause and the import -// declarations (ParseImportDecls). The resulting AST represents the part -// of the program that is parsed. +// declarations (ParseImportDecls). // package Parser @@ -70,23 +69,11 @@ type Parser struct { // ---------------------------------------------------------------------------- // Helper functions -func unimplemented() { - panic("unimplemented"); -} - - func unreachable() { panic("unreachable"); } -func assert(pred bool) { - if !pred { - panic("assertion failed"); - } -} - - // ---------------------------------------------------------------------------- // Parsing support @@ -178,13 +165,6 @@ func (P *Parser) expect(tok int) { } -func (P *Parser) OptSemicolon() { - if P.tok == token.SEMICOLON { - P.next(); - } -} - - // ---------------------------------------------------------------------------- // Common productions @@ -194,7 +174,6 @@ func (P *Parser) parseStatement() ast.Stat; func (P *Parser) parseDeclaration() ast.Decl; -// If scope != nil, lookup identifier in scope. Otherwise create one. func (P *Parser) parseIdent() *ast.Ident { if P.trace { defer un(trace(P, "Ident")); @@ -662,7 +641,9 @@ func (P *Parser) parseStructType() ast.Expr { break; } } - P.OptSemicolon(); + if P.tok == token.SEMICOLON { + P.next(); + } end = P.pos; P.expect(token.RBRACE); @@ -812,9 +793,8 @@ func (P *Parser) parseStringLit() ast.Expr { defer un(trace(P, "StringLit")); } - assert(P.tok == token.STRING); var x ast.Expr = &ast.BasicLit{P.pos, P.tok, P.val}; - P.next(); + P.expect(token.STRING); // always satisfied for P.tok == token.STRING { y := &ast.BasicLit{P.pos, P.tok, P.val}; @@ -1605,7 +1585,9 @@ func (P *Parser) parseImportDecls() *vector.Vector { list := vector.New(0); for P.tok == token.IMPORT { list.Push(P.parseDecl(token.IMPORT)); - P.OptSemicolon(); + if P.tok == token.SEMICOLON { + P.next(); + } } return list; @@ -1651,7 +1633,9 @@ func (P *Parser) ParseProgram() *ast.Program { list := P.parseImportDecls(); for P.tok != token.EOF { list.Push(P.parseDeclaration()); - P.OptSemicolon(); + if P.tok == token.SEMICOLON { + P.next(); + } } // convert list |