Commit d7acfc75 authored by Robert Griesemer's avatar Robert Griesemer

format package

R=r,rsc
DELTA=2871  (1712 added, 1118 deleted, 41 changed)
OCL=29222
CL=29704
parent 2494bcb4
...@@ -10,6 +10,7 @@ exec.install: os.install strings.install ...@@ -10,6 +10,7 @@ exec.install: os.install strings.install
exvar.install: fmt.install http.install io.install log.install strconv.install sync.install exvar.install: fmt.install http.install io.install log.install strconv.install sync.install
flag.install: fmt.install os.install strconv.install flag.install: fmt.install os.install strconv.install
fmt.install: io.install os.install reflect.install strconv.install utf8.install fmt.install: io.install os.install reflect.install strconv.install utf8.install
format.install: container/vector.install flag.install fmt.install go/scanner.install go/token.install io.install os.install reflect.install runtime.install strconv.install strings.install
go/ast.install: go/token.install unicode.install utf8.install go/ast.install: go/token.install unicode.install utf8.install
go/doc.install: container/vector.install fmt.install go/ast.install go/token.install io.install once.install regexp.install sort.install strings.install template.install go/doc.install: container/vector.install fmt.install go/ast.install go/token.install io.install once.install regexp.install sort.install strings.install template.install
go/parser.install: container/vector.install fmt.install go/ast.install go/scanner.install go/token.install io.install os.install go/parser.install: container/vector.install fmt.install go/ast.install go/scanner.install go/token.install io.install os.install
......
...@@ -26,6 +26,7 @@ DIRS=\ ...@@ -26,6 +26,7 @@ DIRS=\
exvar\ exvar\
flag\ flag\
fmt\ fmt\
format\
go/ast\ go/ast\
go/doc\ go/doc\
go/parser\ go/parser\
...@@ -73,6 +74,7 @@ TEST=\ ...@@ -73,6 +74,7 @@ TEST=\
exvar\ exvar\
flag\ flag\
fmt\ fmt\
format\
go/parser\ go/parser\
go/scanner\ go/scanner\
hash/adler32\ hash/adler32\
......
# 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.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
D=
O_arm=5
O_amd64=6
O_386=8
OS=568vq
O=$(O_$(GOARCH))
GC=$(O)g -I_obj
CC=$(O)c -FVw
AS=$(O)a
AR=6ar
default: packages
clean:
rm -rf *.[$(OS)] *.a [$(OS)].out _obj
test: packages
gotest
coverage: packages
gotest
6cov -g `pwd` | grep -v '_test\.go:'
%.$O: %.go
$(GC) $*.go
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
O1=\
format.$O\
O2=\
parser.$O\
phases: a1 a2
_obj$D/format.a: phases
a1: $(O1)
$(AR) grc _obj$D/format.a format.$O
rm -f $(O1)
a2: $(O2)
$(AR) grc _obj$D/format.a parser.$O
rm -f $(O2)
newpkg: clean
mkdir -p _obj$D
$(AR) grc _obj$D/format.a
$(O1): newpkg
$(O2): a1
$(O3): a2
nuke: clean
rm -f $(GOROOT)/pkg$D/format.a
packages: _obj$D/format.a
install: packages
test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg$D
cp _obj$D/format.a $(GOROOT)/pkg$D/format.a
This diff is collapsed.
// 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 format
import (
"fmt";
"format";
"io";
"os";
"testing";
)
func parse(t *testing.T, form string, fmap format.FormatterMap) format.Format {
f, err := format.Parse(io.StringBytes(form), fmap);
if err != nil {
t.Errorf("Parse(%s): %v", err);
return nil;
}
return f;
}
func verify(t *testing.T, f format.Format, expected string, args ...) {
if f == nil {
return; // allow other tests to run
}
result := f.Sprint(args);
if result != expected {
t.Errorf(
"result : `%s`\nexpected: `%s`\n\n",
result, expected
)
}
}
func formatter(s *format.State, value interface{}, rule_name string) bool {
switch rule_name {
case "/":
fmt.Fprintf(s, "%d %d %d", s.Pos().Line, s.LinePos().Column, s.Pos().Column);
return true;
case "blank":
s.Write([]byte{' '});
return true;
case "int":
if value.(int) & 1 == 0 {
fmt.Fprint(s, "even ");
} else {
fmt.Fprint(s, "odd ");
}
return true;
case "nil":
return false;
}
panic("unreachable");
return false;
}
func TestCustomFormatters(t *testing.T) {
fmap0 := format.FormatterMap{ "/": formatter };
fmap1 := format.FormatterMap{ "int": formatter, "blank": formatter, "nil": formatter };
f := parse(t, `int=`, fmap0);
verify(t, f, ``, 1, 2, 3);
f = parse(t, `int="#"`, nil);
verify(t, f, `###`, 1, 2, 3);
f = parse(t, `int="#";string="%s"`, fmap0);
verify(t, f, "#1 0 1#1 0 7#1 0 13\n2 0 0foo2 0 8\n", 1, 2, 3, "\n", "foo", "\n");
f = parse(t, ``, fmap1);
verify(t, f, `even odd even odd `, 0, 1, 2, 3);
f = parse(t, `/ =^:blank; float="#"`, fmap1);
verify(t, f, `# # #`, 0.0, 1.0, 2.0);
f = parse(t, `float=^:nil`, fmap1);
verify(t, f, ``, 0.0, 1.0, 2.0);
// TODO needs more tests
}
// ----------------------------------------------------------------------------
// Formatting of basic and simple composite types
func check(t *testing.T, form, expected string, args ...) {
f := parse(t, form, nil);
result := f.Sprint(args);
if result != expected {
t.Errorf(
"format : %s\nresult : `%s`\nexpected: `%s`\n\n",
form, result, expected
)
}
}
func TestBasicTypes(t *testing.T) {
check(t, ``, ``);
check(t, `bool=":%v"`, `:true:false`, true, false);
check(t, `int="%b %d %o 0x%x"`, `101010 42 52 0x2a`, 42);
check(t, `int="%"`, `%`, 42);
check(t, `int="%%"`, `%`, 42);
check(t, `int="**%%**"`, `**%**`, 42);
check(t, `int="%%%%%%"`, `%%%`, 42);
check(t, `int="%%%d%%"`, `%42%`, 42);
const i = -42;
const is = `-42`;
check(t, `int ="%d"`, is, i);
check(t, `int8 ="%d"`, is, int8(i));
check(t, `int16="%d"`, is, int16(i));
check(t, `int32="%d"`, is, int32(i));
check(t, `int64="%d"`, is, int64(i));
const u = 42;
const us = `42`;
check(t, `uint ="%d"`, us, uint(u));
check(t, `uint8 ="%d"`, us, uint8(u));
check(t, `uint16="%d"`, us, uint16(u));
check(t, `uint32="%d"`, us, uint32(u));
check(t, `uint64="%d"`, us, uint64(u));
const f = 3.141592;
const fs = `3.141592`;
check(t, `float ="%g"`, fs, f);
check(t, `float32="%g"`, fs, float32(f));
check(t, `float64="%g"`, fs, float64(f));
}
func TestArrayTypes(t *testing.T) {
var a0 [10]int;
check(t, `array="array";`, `array`, a0);
a1 := [...]int{1, 2, 3};
check(t, `array="array";`, `array`, a1);
check(t, `array={*}; int="%d";`, `123`, a1);
check(t, `array={* / ", "}; int="%d";`, `1, 2, 3`, a1);
check(t, `array={* / *}; int="%d";`, `12233`, a1);
a2 := []interface{}{42, "foo", 3.14};
check(t, `array={* / ", "}; interface=*; string="bar"; default="%v";`, `42, bar, 3.14`, a2);
}
func TestChanTypes(t *testing.T) {
var c0 chan int;
check(t, `chan="chan"`, `chan`, c0);
c1 := make(chan int);
go func(){ c1 <- 42 }();
check(t, `chan="chan"`, `chan`, c1);
// check(t, `chan=*`, `42`, c1); // reflection support for chans incomplete
}
func TestFuncTypes(t *testing.T) {
var f0 func() int;
check(t, `func="func"`, `func`, f0);
f1 := func() int { return 42; };
check(t, `func="func"`, `func`, f1);
// check(t, `func=*`, `42`, f1); // reflection support for funcs incomplete
}
func TestInterfaceTypes(t *testing.T) {
var i0 interface{};
check(t, `interface="interface"`, `interface`, i0);
i0 = "foo";
check(t, `interface="interface"`, `interface`, i0);
check(t, `interface=*; string="%s"`, `foo`, i0);
}
func TestMapTypes(t *testing.T) {
var m0 map[string]int;
check(t, `map="map"`, `map`, m0);
m1 := map[string]int{};
check(t, `map="map"`, `map`, m1);
// check(t, `map=*`, ``, m1); // reflection support for maps incomplete
}
func TestPointerTypes(t *testing.T) {
var p0 *int;
check(t, `ptr="ptr"`, `ptr`, p0);
check(t, `ptr=*`, ``, p0);
check(t, `ptr=*|"nil"`, `nil`, p0);
x := 99991;
p1 := &x;
check(t, `ptr="ptr"`, `ptr`, p1);
check(t, `ptr=*; int="%d"`, `99991`, p1);
}
func TestDefaultRule(t *testing.T) {
check(t, `default="%v"`, `42foo3.14`, 42, "foo", 3.14);
check(t, `default="%v"; int="%x"`, `abcdef`, 10, 11, 12, 13, 14, 15);
check(t, `default="%v"; int="%x"`, `ab**ef`, 10, 11, "**", 14, 15);
check(t, `default="%x"; int=^:default`, `abcdef`, 10, 11, 12, 13, 14, 15);
}
func TestGlobalSeparatorRule(t *testing.T) {
check(t, `int="%d"; / ="-"`, `1-2-3-4`, 1, 2, 3, 4);
check(t, `int="%x%x"; / ="*"`, `aa*aa`, 10, 10);
}
// ----------------------------------------------------------------------------
// Formatting of a struct
type T1 struct {
a int;
}
const F1 =
`format "format";`
`int = "%d";`
`format.T1 = "<" a ">";`
func TestStruct1(t *testing.T) {
check(t, F1, "<42>", T1{42});
}
// ----------------------------------------------------------------------------
// Formatting of a struct with an optional field (ptr)
type T2 struct {
s string;
p *T1;
}
const F2a =
F1 +
`string = "%s";`
`ptr = *;`
`format.T2 = s ["-" p "-"];`
const F2b =
F1 +
`string = "%s";`
`ptr = *;`
`format.T2 = s ("-" p "-" | "empty");`;
func TestStruct2(t *testing.T) {
check(t, F2a, "foo", T2{"foo", nil});
check(t, F2a, "bar-<17>-", T2{"bar", &T1{17}});
check(t, F2b, "fooempty", T2{"foo", nil});
}
// ----------------------------------------------------------------------------
// Formatting of a struct with a repetitive field (slice)
type T3 struct {
s string;
a []int;
}
const F3a =
`format "format";`
`default = "%v";`
`array = *;`
`format.T3 = s {" " a a / ","};`
const F3b =
`format "format";`
`int = "%d";`
`string = "%s";`
`array = *;`
`nil = ;`
`empty = *:nil;`
`format.T3 = s [a:empty ": " {a / "-"}]`
func TestStruct3(t *testing.T) {
check(t, F3a, "foo", T3{"foo", nil});
check(t, F3a, "foo 00, 11, 22", T3{"foo", []int{0, 1, 2}});
check(t, F3b, "bar", T3{"bar", nil});
check(t, F3b, "bal: 2-3-5", T3{"bal", []int{2, 3, 5}});
}
// ----------------------------------------------------------------------------
// Formatting of a struct with alternative field
type T4 struct {
x *int;
a []int;
}
const F4a =
`format "format";`
`int = "%d";`
`ptr = *;`
`array = *;`
`nil = ;`
`empty = *:nil;`
`format.T4 = "<" (x:empty x | "-") ">" `
const F4b =
`format "format";`
`int = "%d";`
`ptr = *;`
`array = *;`
`nil = ;`
`empty = *:nil;`
`format.T4 = "<" (a:empty {a / ", "} | "-") ">" `
func TestStruct4(t *testing.T) {
x := 7;
check(t, F4a, "<->", T4{nil, nil});
check(t, F4a, "<7>", T4{&x, nil});
check(t, F4b, "<->", T4{nil, nil});
check(t, F4b, "<2, 3, 7>", T4{nil, []int{2, 3, 7}});
}
// ----------------------------------------------------------------------------
// Formatting a struct (documentation example)
type Point struct {
name string;
x, y int;
}
const FPoint =
`format "format";`
`int = "%d";`
`hexInt = "0x%x";`
`string = "---%s---";`
`format.Point = name "{" x ", " y:hexInt "}";`
func TestStructPoint(t *testing.T) {
p := Point{"foo", 3, 15};
check(t, FPoint, "---foo---{3, 0xf}", p);
}
// ----------------------------------------------------------------------------
// Formatting a slice (documentation example)
const FSlice =
`int = "%b";`
`array = { * / ", " }`
func TestSlice(t *testing.T) {
check(t, FSlice, "10, 11, 101, 111", []int{2, 3, 5, 7});
}
// TODO add more tests
This diff is collapsed.
...@@ -32,7 +32,7 @@ clean: ...@@ -32,7 +32,7 @@ clean:
godoc.6: astprinter.6 godoc.6: astprinter.6
pretty.6: astprinter.6 format.6 pretty.6: astprinter.6
%.6: %.go %.6: %.go
$(G) $(F) $< $(G) $(F) $<
...@@ -13,7 +13,7 @@ token "token"; ...@@ -13,7 +13,7 @@ token "token";
array = array =
*; *;
pointer = ptr =
*; *;
string = string =
...@@ -47,6 +47,9 @@ token.Token = ...@@ -47,6 +47,9 @@ token.Token =
^:string; ^:string;
ast.Comment = ast.Comment =
// TODO this doesn't indent properly after //-style comments because
// the '\n'-char is printed as part of the comment - need to
// address this
Text:string [Text:isMultiLineComment "\n"]; Text:string [Text:isMultiLineComment "\n"];
ast.Comments = ast.Comments =
...@@ -84,7 +87,7 @@ ast.StringList = ...@@ -84,7 +87,7 @@ ast.StringList =
{Strings / "\n"}; {Strings / "\n"};
ast.FuncLit = ast.FuncLit =
Type " " Body; Type " " Body ^:clearOptSemi; // no optional ; after a func literal body
ast.CompositeLit = ast.CompositeLit =
Type "{" {Elts / ", "} "}"; Type "{" {Elts / ", "} "}";
...@@ -123,9 +126,9 @@ ast.StructType = ...@@ -123,9 +126,9 @@ ast.StructType =
"struct" "struct"
[Lbrace:isValidPos " {"] [Lbrace:isValidPos " {"]
[ Fields:exists [ Fields:exists
>> "\t" "\n" ( "\t" >> "\n"
{Fields / ";\n"} {Fields / ";\n"}
<< "\n" ) "\n"
] ]
[Rbrace:isValidPos "}"]; [Rbrace:isValidPos "}"];
...@@ -142,9 +145,9 @@ ast.InterfaceType = ...@@ -142,9 +145,9 @@ ast.InterfaceType =
"interface" "interface"
[Lbrace:isValidPos " {"] [Lbrace:isValidPos " {"]
[ Methods:exists [ Methods:exists
>> "\t" "\n" ( "\t" >> "\n"
{Methods / ";\n"} {Methods / ";\n"}
<< "\n" ) "\n"
] ]
[Rbrace:isValidPos "}"]; [Rbrace:isValidPos "}"];
...@@ -197,14 +200,17 @@ ast.ReturnStmt = ...@@ -197,14 +200,17 @@ ast.ReturnStmt =
ast.BranchStmt = ast.BranchStmt =
Tok [" " Label]; Tok [" " Label];
stmtList =
{^ / ^:optSemi "\n"};
blockStmt = // like ast.BlockStmt but w/o indentation blockStmt = // like ast.BlockStmt but w/o indentation
"{" "{"
[List:exists [List:exists
"\n" "\n"
{List / ";\n"} List:stmtList
"\n" "\n"
] ]
"}"; "}" ^:setOptSemi;
blockStmtPtr = blockStmtPtr =
*:blockStmt; *:blockStmt;
...@@ -212,11 +218,11 @@ blockStmtPtr = ...@@ -212,11 +218,11 @@ blockStmtPtr =
ast.BlockStmt = ast.BlockStmt =
"{" "{"
[List:exists [List:exists
>> "\t" "\n" ( "\t" >> "\n"
{List / ";\n"} List:stmtList
<< "\n" ) "\n"
] ]
"}"; "}" ^:setOptSemi;
ast.IfStmt = ast.IfStmt =
"if " [Init "; "] [Cond " "] Body [" else " Else]; "if " [Init "; "] [Cond " "] Body [" else " Else];
...@@ -227,9 +233,9 @@ ast.CaseClause = ...@@ -227,9 +233,9 @@ ast.CaseClause =
) )
":" ":"
[Body:exists [Body:exists
>> "\t" "\n" ( "\t" >> "\n"
{Body / ";\n"} Body:stmtList
<< )
]; ];
ast.SwitchStmt = ast.SwitchStmt =
...@@ -242,9 +248,9 @@ ast.TypeCaseClause = ...@@ -242,9 +248,9 @@ ast.TypeCaseClause =
) )
":" ":"
[Body:exists [Body:exists
>> "\t" "\n" ( "\t" >> "\n"
{Body / ";\n"} Body:stmtList
<< )
]; ];
ast.TypeSwitchStmt = ast.TypeSwitchStmt =
...@@ -257,9 +263,9 @@ ast.CommClause = ...@@ -257,9 +263,9 @@ ast.CommClause =
) )
":" ":"
[Body:exists [Body:exists
>> "\t" "\n" ( "\t" >> "\n"
{Body / ";\n"} Body:stmtList
<< )
]; ];
ast.SelectStmt = ast.SelectStmt =
...@@ -303,11 +309,13 @@ ast.BadDecl = ...@@ -303,11 +309,13 @@ ast.BadDecl =
ast.GenDecl = ast.GenDecl =
Doc Doc
Tok " " Tok " "
( Lparen:isValidPos ( Lparen:isValidPos "("
>> "\t" "(\n" [Specs:exists
{Specs / ";\n"} ( "\t" >> "\n"
<< {Specs / ";\n"}
"\n)" ) "\n"
]
")" ^:setOptSemi
| {Specs / ";\n"} | {Specs / ";\n"}
); );
......
This diff is collapsed.
// 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 format
import (
"format";
"io";
"testing";
)
func check(t *testing.T, form, expected string, args ...) {
f, err := format.Parse(io.StringBytes(form), nil);
if err != nil {
panic(form + ": " + err.String());
}
result := f.Sprint(args);
if result != expected {
t.Errorf(
"format : %s\nresult : `%s`\nexpected: `%s`\n\n",
form, result, expected
)
}
}
// ----------------------------------------------------------------------------
// Syntax
func TestA(t *testing.T) {
// TODO fill this in
}
// ----------------------------------------------------------------------------
// - formatting of basic types
func Test0(t *testing.T) {
check(t, `bool = "%v"`, "false", false);
check(t, `int = "%b %d %o 0x%x"`, "101010 42 52 0x2a", 42);
}
// ----------------------------------------------------------------------------
// - formatting of a struct
type T1 struct {
a int;
}
const F1 =
`format "format";`
`int = "%d";`
`format.T1 = "<" a ">";`
func Test1(t *testing.T) {
check(t, F1, "<42>", T1{42});
}
// ----------------------------------------------------------------------------
// - formatting of a struct with an optional field (pointer)
type T2 struct {
s string;
p *T1;
}
const F2a =
F1 +
`string = "%s";`
`pointer = *;`
`format.T2 = s ["-" p "-"];`
const F2b =
F1 +
`string = "%s";`
`pointer = *;`
`format.T2 = s ("-" p "-" | "empty");`;
func Test2(t *testing.T) {
check(t, F2a, "foo", T2{"foo", nil});
check(t, F2a, "bar-<17>-", T2{"bar", &T1{17}});
check(t, F2b, "fooempty", T2{"foo", nil});
}
// ----------------------------------------------------------------------------
// - formatting of a struct with a repetitive field (slice)
type T3 struct {
s string;
a []int;
}
const F3a =
`format "format";`
`default = "%v";`
`array = *;`
`format.T3 = s {" " a a / ","};`
const F3b =
`format "format";`
`int = "%d";`
`string = "%s";`
`array = *;`
`nil = ;`
`empty = *:nil;`
`format.T3 = s [a:empty ": " {a / "-"}]`
func Test3(t *testing.T) {
check(t, F3a, "foo", T3{"foo", nil});
check(t, F3a, "foo 00, 11, 22", T3{"foo", []int{0, 1, 2}});
check(t, F3b, "bar", T3{"bar", nil});
check(t, F3b, "bal: 2-3-5", T3{"bal", []int{2, 3, 5}});
}
// ----------------------------------------------------------------------------
// - formatting of a struct with alternative field
type T4 struct {
x *int;
a []int;
}
const F4a =
`format "format";`
`int = "%d";`
`pointer = *;`
`array = *;`
`nil = ;`
`empty = *:nil;`
`format.T4 = "<" (x:empty x | "-") ">" `
const F4b =
`format "format";`
`int = "%d";`
`pointer = *;`
`array = *;`
`nil = ;`
`empty = *:nil;`
`format.T4 = "<" (a:empty {a / ", "} | "-") ">" `
func Test4(t *testing.T) {
x := 7;
check(t, F4a, "<->", T4{nil, nil});
check(t, F4a, "<7>", T4{&x, nil});
check(t, F4b, "<->", T4{nil, nil});
check(t, F4b, "<2, 3, 7>", T4{nil, []int{2, 3, 7}});
}
...@@ -70,31 +70,67 @@ func makeTabwriter(writer io.Writer) *tabwriter.Writer { ...@@ -70,31 +70,67 @@ func makeTabwriter(writer io.Writer) *tabwriter.Writer {
} }
func isValidPos(w io.Writer, env, value interface{}, name string) bool { func isValidPos(state *format.State, value interface{}, rule_name string) bool {
pos := value.(token.Position); pos := value.(token.Position);
return pos.IsValid(); return pos.IsValid();
} }
func isSend(w io.Writer, env, value interface{}, name string) bool { func isSend(state *format.State, value interface{}, rule_name string) bool {
return value.(ast.ChanDir) & ast.SEND != 0; return value.(ast.ChanDir) & ast.SEND != 0;
} }
func isRecv(w io.Writer, env, value interface{}, name string) bool { func isRecv(state *format.State, value interface{}, rule_name string) bool {
return value.(ast.ChanDir) & ast.RECV != 0; return value.(ast.ChanDir) & ast.RECV != 0;
} }
func isMultiLineComment(w io.Writer, env, value interface{}, name string) bool {
return value.([]byte)[1] == '*' func isMultiLineComment(state *format.State, value interface{}, rule_name string) bool {
return value.([]byte)[1] == '*';
}
type environment struct {
optSemi *bool;
}
func (e environment) Copy() format.Environment {
optSemi := *e.optSemi;
return environment{&optSemi};
}
func clearOptSemi(state *format.State, value interface{}, rule_name string) bool {
*state.Env().(environment).optSemi = false;
return true;
} }
var fmap = format.FormatterMap{ func setOptSemi(state *format.State, value interface{}, rule_name string) bool {
*state.Env().(environment).optSemi = true;
return true;
}
func optSemi(state *format.State, value interface{}, rule_name string) bool {
if !*state.Env().(environment).optSemi {
state.Write([]byte{';'});
}
return true;
}
var fmap = format.FormatterMap {
"isValidPos": isValidPos, "isValidPos": isValidPos,
"isSend": isSend, "isSend": isSend,
"isRecv": isRecv, "isRecv": isRecv,
"isMultiLineComment": isMultiLineComment, "isMultiLineComment": isMultiLineComment,
"/": clearOptSemi,
"clearOptSemi": clearOptSemi,
"setOptSemi": setOptSemi,
"optSemi": optSemi,
} }
...@@ -120,7 +156,7 @@ func main() { ...@@ -120,7 +156,7 @@ func main() {
} }
ast_format, err := format.Parse(src, fmap); ast_format, err := format.Parse(src, fmap);
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "%s:%v\n", ast_txt, err); fmt.Fprintf(os.Stderr, "%s: %v\n", ast_txt, err);
os.Exit(1); os.Exit(1);
} }
...@@ -153,10 +189,10 @@ func main() { ...@@ -153,10 +189,10 @@ func main() {
if !*silent { if !*silent {
tw := makeTabwriter(os.Stdout); tw := makeTabwriter(os.Stdout);
if *formatter { if *formatter {
var optSemi bool; // formatting environment env := environment{new(bool)};
_, err := ast_format.Fprint(tw, &optSemi, prog); _, err := ast_format.Fprint(tw, env, prog);
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "format error$$: %s", err); fmt.Fprintf(os.Stderr, "format error: %v\n", err);
exitcode = 1; exitcode = 1;
continue; // proceed with next file continue; // proceed with next file
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment