diff options
author | Robert Griesemer <gri@golang.org> | 2008-09-18 16:58:37 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2008-09-18 16:58:37 -0700 |
commit | 9fb7da748396894cb2cb15188f82e124933b8b7a (patch) | |
tree | 3f83983bfab51a4a981b8537379eee656016617d /usr/gri/pretty/pretty.go | |
parent | 2180a3dc9c5c80c097f56350539fbde490845493 (diff) | |
download | golang-9fb7da748396894cb2cb15188f82e124933b8b7a.tar.gz |
First cut at a Go pretty printer:
- code scavenged from Go-in-Go front-end (will merge back)
- using "symbol-table" free parsing to build AST
- no printing yet
R=r
OCL=15504
CL=15504
Diffstat (limited to 'usr/gri/pretty/pretty.go')
-rw-r--r-- | usr/gri/pretty/pretty.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/usr/gri/pretty/pretty.go b/usr/gri/pretty/pretty.go new file mode 100644 index 000000000..48f470f18 --- /dev/null +++ b/usr/gri/pretty/pretty.go @@ -0,0 +1,48 @@ +// 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 + +import Flag "flag" +import Platform "platform" +import Scanner "scanner" +import AST "ast" // should not be needed +import Parser "parser" +import Printer "printer" + + +var ( + verbose = Flag.Bool("v", false, nil, "verbose mode"); + sixg = Flag.Bool("6g", false, nil, "6g compatibility mode"); + tokenchan = Flag.Bool("token_chan", false, nil, "use token channel for scanner-parser connection"); +) + + +func main() { + Flag.Parse(); + + // process files + for i := 0; i < Flag.NArg(); i++ { + src_file := Flag.Arg(i); + + src, ok := Platform.ReadSourceFile(src_file); + if !ok { + print("cannot open ", src_file, "\n"); + return; + } + + scanner := new(Scanner.Scanner); + scanner.Open(src_file, src); + + var tstream *<-chan *Scanner.Token; + if tokenchan.BVal() { + tstream = scanner.TokenStream(); + } + + parser := new(Parser.Parser); + parser.Open(verbose.BVal(), scanner, tstream); + + parser.ParseProgram(); + } +} |