mirror of
https://github.com/golang/go
synced 2024-11-26 22:01:27 -07:00
8415280699
- removed excessive ";"'s - no ()'s around expressions where not needed - parser.go now reproduced and parseable again R=r OCL=15881 CL=15881
73 lines
1.5 KiB
Go
73 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"
|
|
import Platform "platform"
|
|
import Scanner "scanner"
|
|
import AST "ast" // should not be needed
|
|
import Parser "parser"
|
|
import Printer "printer"
|
|
|
|
|
|
var (
|
|
silent = Flag.Bool("s", false, nil, "silent mode: no pretty print output");
|
|
verbose = Flag.Bool("v", false, nil, "verbose mode: trace parsing");
|
|
sixg = Flag.Bool("6g", false, nil, "6g compatibility mode");
|
|
tokenchan = Flag.Bool("token_chan", false, nil, "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);
|
|
|
|
src, ok := Platform.ReadSourceFile(src_file);
|
|
if !ok {
|
|
print("cannot open ", src_file, "\n");
|
|
sys.exit(1);
|
|
}
|
|
|
|
if silent.BVal() {
|
|
print("- ", src_file, "\n");
|
|
}
|
|
|
|
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);
|
|
|
|
prog := parser.ParseProgram();
|
|
|
|
if scanner.nerrors > 0 {
|
|
sys.exit(1);
|
|
}
|
|
|
|
if !silent.BVal() {
|
|
Printer.Print(prog);
|
|
}
|
|
}
|
|
}
|