go/usr/gri/pretty/pretty.go
Robert Griesemer 6dd93bbfbc - changed pretty parser to parse and print new function type syntax
- added more test cases
- fixed a bug in test script which prevented errors to show up...

R=r
OCL=23832
CL=23974
2009-01-30 15:31:04 -08:00

66 lines
1.5 KiB
Go

// 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";
Platform "platform";
Printer "printer";
Compilation "compilation";
)
var (
flags Compilation.Flags;
silent = Flag.Bool("s", false, "silent mode: no pretty print output");
)
func init() {
Flag.BoolVar(&flags.Verbose, "v", false, "verbose mode: trace parsing");
Flag.BoolVar(&flags.Sixg, "6g", true, "6g compatibility mode");
//TODO fix this code again
//Flag.BoolVar(&flags.Deps, "d", false, "print dependency information only");
Flag.BoolVar(&flags.Columns, "columns", Platform.USER == "gri", "print column info in error messages");
Flag.BoolVar(&flags.Testmode, "t", false, "test mode: interprets /* ERROR */ and /* SYNC */ comments");
Flag.BoolVar(&flags.Tokenchan, "token_chan", false, "use token channel for scanner-parser connection");
}
func usage() {
print("usage: pretty { flags } { files }\n");
Flag.PrintDefaults();
sys.Exit(0);
}
func main() {
Flag.Parse();
if Flag.NFlag() == 0 && Flag.NArg() == 0 {
usage();
}
// process files
for i := 0; i < Flag.NArg(); i++ {
src_file := Flag.Arg(i);
if false /* DISABLED flags.deps */ {
Compilation.ComputeDeps(src_file, &flags);
} else {
prog, nerrors := Compilation.Compile(src_file, &flags);
if nerrors > 0 {
if flags.Testmode {
return; // TODO we shouldn't need this
}
sys.Exit(1);
}
if !*silent && !flags.Testmode {
Printer.Print(prog);
}
}
}
}