Commit 0ea9dd81 authored by Robert Griesemer's avatar Robert Griesemer

gofmt the last outstanding files in src/pkg

- added a list of issues to printer/nodes.go

R=rsc
http://go/go-review/1024002
parent 39fd52d3
......@@ -623,7 +623,7 @@ const (
string */
DF_SYMBOLIC DynFlag = 0x0002; /* Indicates "symbolic" linking. */
DF_TEXTREL DynFlag = 0x0004; /* Indicates there may be relocations in
non-writable segments. */
non-writable segments. */
DF_BIND_NOW DynFlag = 0x0008; /* Indicates that the dynamic linker should
process all relocations for the object
containing this entry before transferring
......@@ -1394,7 +1394,7 @@ type Header32 struct {
*/
type Section32 struct {
Name uint32; /* Section name (index into the
section header string table). */
section header string table). */
Type uint32; /* Section type. */
Flags uint32; /* Section flags. */
Addr uint32; /* Address in memory image. */
......@@ -1508,7 +1508,7 @@ type Header64 struct {
type Section64 struct {
Name uint32; /* Section name (index into the
section header string table). */
section header string table). */
Type uint32; /* Section type. */
Flags uint64; /* Section flags. */
Addr uint64; /* Address in memory image. */
......
......@@ -232,40 +232,40 @@ type Formatter func(state *State, value interface{}, ruleName string) bool
// A FormatterMap is a set of custom formatters.
// It maps a rule name to a formatter function.
//
type FormatterMap map [string] Formatter;
type FormatterMap map[string]Formatter
// A parsed format expression is built from the following nodes.
//
type (
expr interface {};
expr interface{};
alternatives []expr; // x | y | z
alternatives []expr; // x | y | z
sequence []expr; // x y z
sequence []expr; // x y z
literal [][]byte; // a list of string segments, possibly starting with '%'
literal [][]byte; // a list of string segments, possibly starting with '%'
field struct {
fieldName string; // including "@", "*"
ruleName string; // "" if no rule name specified
field struct {
fieldName string; // including "@", "*"
ruleName string; // "" if no rule name specified
};
group struct {
indent, body expr; // (indent >> body)
group struct {
indent, body expr; // (indent >> body)
};
option struct {
body expr; // [body]
option struct {
body expr; // [body]
};
repetition struct {
body, separator expr; // {body / separator}
repetition struct {
body, separator expr; // {body / separator}
};
custom struct {
ruleName string;
fun Formatter
custom struct {
ruleName string;
fun Formatter;
};
)
......@@ -273,7 +273,7 @@ type (
// A Format is the result of parsing a format specification.
// The format may be applied repeatedly to format values.
//
type Format map [string] expr;
type Format map[string]expr
// ----------------------------------------------------------------------------
......@@ -290,7 +290,7 @@ type Format map [string] expr;
// the receiver, and thus can be very light-weight.
//
type Environment interface {
Copy() Environment
Copy() Environment;
}
......@@ -298,15 +298,15 @@ type Environment interface {
// It is provided as argument to custom formatters.
//
type State struct {
fmt Format; // format in use
env Environment; // user-supplied environment
errors chan os.Error; // not chan *Error (errors <- nil would be wrong!)
hasOutput bool; // true after the first literal has been written
indent bytes.Buffer; // current indentation
output bytes.Buffer; // format output
linePos token.Position; // position of line beginning (Column == 0)
default_ expr; // possibly nil
separator expr; // possibly nil
fmt Format; // format in use
env Environment; // user-supplied environment
errors chan os.Error; // not chan *Error (errors <- nil would be wrong!)
hasOutput bool; // true after the first literal has been written
indent bytes.Buffer; // current indentation
output bytes.Buffer; // format output
linePos token.Position; // position of line beginning (Column == 0)
default_ expr; // possibly nil
separator expr; // possibly nil
}
......@@ -365,22 +365,22 @@ func (s *State) Write(data []byte) (int, os.Error) {
// write text segment and indentation
n1, _ := s.output.Write(data[i0 : i+1]);
n2, _ := s.output.Write(s.indent.Bytes());
n += n1 + n2;
i0 = i + 1;
n += n1+n2;
i0 = i+1;
s.linePos.Offset = s.output.Len();
s.linePos.Line++;
}
}
n3, _ := s.output.Write(data[i0 : len(data)]);
return n + n3, nil;
n3, _ := s.output.Write(data[i0:len(data)]);
return n+n3, nil;
}
type checkpoint struct {
env Environment;
hasOutput bool;
outputLen int;
linePos token.Position;
env Environment;
hasOutput bool;
outputLen int;
linePos token.Position;
}
......@@ -489,13 +489,13 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool {
if s.hasOutput {
// not the first literal
if s.separator != nil {
sep := s.separator; // save current separator
s.separator = nil; // and disable it (avoid recursion)
sep := s.separator; // save current separator
s.separator = nil; // and disable it (avoid recursion)
mark := s.save();
if !s.eval(sep, value, index) {
s.restore(mark);
}
s.separator = sep; // enable it again
s.separator = sep; // enable it again
}
}
s.hasOutput = true;
......@@ -505,7 +505,7 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool {
// segment contains a %-format at the beginning
if lit[1] == '%' {
// "%%" is printed as a single "%"
s.Write(lit[1 : len(lit)]);
s.Write(lit[1:len(lit)]);
} else {
// use s instead of s.output to get indentation right
fmt.Fprintf(s, string(lit), value.Interface());
......@@ -515,7 +515,7 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool {
s.Write(lit);
}
}
return true; // a literal never evaluates to nil
return true; // a literal never evaluates to nil
case *field:
// determine field value
......@@ -580,7 +580,7 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool {
ruleName := t.ruleName;
if ruleName == "" {
// no alternate rule name, value type determines rule
ruleName = typename(value.Type())
ruleName = typename(value.Type());
}
fexpr = s.getFormat(ruleName);
......@@ -620,10 +620,10 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool {
// evaluate the body and append the result to the state's output
// buffer unless the result is nil
mark := s.save();
if !s.eval(t.body, value, 0) { // TODO is 0 index correct?
if !s.eval(t.body, value, 0) { // TODO is 0 index correct?
s.restore(mark);
}
return true; // an option never evaluates to nil
return true; // an option never evaluates to nil
case *repetition:
// evaluate the body and append the result to the state's output
......@@ -643,7 +643,7 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool {
break;
}
}
return true; // a repetition never evaluates to nil
return true; // a repetition never evaluates to nil
case *custom:
// invoke the custom formatter to obtain the result
......@@ -680,14 +680,14 @@ func (f Format) Eval(env Environment, args ...) ([]byte, os.Error) {
for i := 0; i < value.NumField(); i++ {
fld := value.Field(i);
mark := s.save();
if !s.eval(s.getFormat(typename(fld.Type())), fld, 0) { // TODO is 0 index correct?
if !s.eval(s.getFormat(typename(fld.Type())), fld, 0) { // TODO is 0 index correct?
s.restore(mark);
}
}
errors <- nil; // no errors
errors <- nil; // no errors
}();
err := <- errors;
err := <-errors;
return s.output.Bytes(), err;
}
......
......@@ -23,14 +23,13 @@ func parse(t *testing.T, form string, fmap FormatterMap) Format {
func verify(t *testing.T, f Format, expected string, args ...) {
if f == nil {
return; // allow other tests to run
return; // allow other tests to run
}
result := f.Sprint(args);
if result != expected {
t.Errorf(
"result : `%s`\nexpected: `%s`\n\n",
result, expected
)
result, expected);
}
}
......@@ -62,9 +61,9 @@ func formatter(s *State, value interface{}, rule_name string) bool {
func TestCustomFormatters(t *testing.T) {
fmap0 := FormatterMap{ "/": formatter };
fmap1 := FormatterMap{ "int": formatter, "blank": formatter, "nil": formatter };
fmap2 := FormatterMap{ "testing.T": formatter };
fmap0 := FormatterMap{"/": formatter};
fmap1 := FormatterMap{"int": formatter, "blank": formatter, "nil": formatter};
fmap2 := FormatterMap{"testing.T": formatter};
f := parse(t, `int=`, fmap0);
verify(t, f, ``, 1, 2, 3);
......@@ -97,14 +96,13 @@ func TestCustomFormatters(t *testing.T) {
func check(t *testing.T, form, expected string, args ...) {
f := parse(t, form, nil);
if f == nil {
return; // allow other tests to run
return; // allow other tests to run
}
result := f.Sprint(args);
if result != expected {
t.Errorf(
"format : %s\nresult : `%s`\nexpected: `%s`\n\n",
form, result, expected
)
form, result, expected);
}
}
......@@ -164,7 +162,7 @@ func TestChanTypes(t *testing.T) {
check(t, `chan="chan"`, `chan`, c0);
c1 := make(chan int);
go func(){ c1 <- 42 }();
go func() { c1 <- 42 }();
check(t, `chan="chan"`, `chan`, c1);
// check(t, `chan=*`, `42`, c1); // reflection support for chans incomplete
}
......@@ -174,14 +172,14 @@ func TestFuncTypes(t *testing.T) {
var f0 func() int;
check(t, `func="func"`, `func`, f0);
f1 := func() int { return 42; };
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{};
var i0 interface{}
check(t, `interface="interface"`, `interface`, i0);
i0 = "foo";
......@@ -234,8 +232,7 @@ type T1 struct {
a int;
}
const F1 =
`datafmt "datafmt";`
const F1 = `datafmt "datafmt";`
`int = "%d";`
`datafmt.T1 = "<" a ">";`
......@@ -248,21 +245,19 @@ func TestStruct1(t *testing.T) {
// Formatting of a struct with an optional field (ptr)
type T2 struct {
s string;
p *T1;
s string;
p *T1;
}
const F2a =
F1 +
const F2a = F1 +
`string = "%s";`
`ptr = *;`
`datafmt.T2 = s ["-" p "-"];`
`ptr = *;`
`datafmt.T2 = s ["-" p "-"];`
const F2b =
F1 +
const F2b = F1 +
`string = "%s";`
`ptr = *;`
`datafmt.T2 = s ("-" p "-" | "empty");`;
`ptr = *;`
`datafmt.T2 = s ("-" p "-" | "empty");`
func TestStruct2(t *testing.T) {
check(t, F2a, "foo", T2{"foo", nil});
......@@ -275,18 +270,16 @@ func TestStruct2(t *testing.T) {
// Formatting of a struct with a repetitive field (slice)
type T3 struct {
s string;
a []int;
s string;
a []int;
}
const F3a =
`datafmt "datafmt";`
const F3a = `datafmt "datafmt";`
`default = "%v";`
`array = *;`
`datafmt.T3 = s {" " a a / ","};`
const F3b =
`datafmt "datafmt";`
const F3b = `datafmt "datafmt";`
`int = "%d";`
`string = "%s";`
`array = *;`
......@@ -306,12 +299,11 @@ func TestStruct3(t *testing.T) {
// Formatting of a struct with alternative field
type T4 struct {
x *int;
a []int;
x *int;
a []int;
}
const F4a =
`datafmt "datafmt";`
const F4a = `datafmt "datafmt";`
`int = "%d";`
`ptr = *;`
`array = *;`
......@@ -319,8 +311,7 @@ const F4a =
`empty = *:nil;`
`datafmt.T4 = "<" (x:empty x | "-") ">" `
const F4b =
`datafmt "datafmt";`
const F4b = `datafmt "datafmt";`
`int = "%d";`
`ptr = *;`
`array = *;`
......@@ -341,12 +332,11 @@ func TestStruct4(t *testing.T) {
// Formatting a struct (documentation example)
type Point struct {
name string;
x, y int;
name string;
x, y int;
}
const FPoint =
`datafmt "datafmt";`
const FPoint = `datafmt "datafmt";`
`int = "%d";`
`hexInt = "0x%x";`
`string = "---%s---";`
......@@ -361,8 +351,7 @@ func TestStructPoint(t *testing.T) {
// ----------------------------------------------------------------------------
// Formatting a slice (documentation example)
const FSlice =
`int = "%b";`
const FSlice = `int = "%b";`
`array = { * / ", " }`
func TestSlice(t *testing.T) {
......
This diff is collapsed.
......@@ -24,6 +24,15 @@ const (
)
// Other outstanding formatting issues:
// - replacement of expression spacing algorithm with rsc's algorithm
// - support for one-line composite types (e.g. structs) as composite literals types
// - better comment formatting for /*-style comments at the end of a line (e.g. a declaration)
// when the comment spans multiple lines
// - formatting of expression lists; especially for string lists (stringListMode)
// - blank after { and before } in one-line composite literals probably looks better
// ----------------------------------------------------------------------------
// Common AST nodes.
......
This diff is collapsed.
......@@ -16,7 +16,8 @@ const testInput = `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<body xmlns:foo="ns1" xmlns="ns2" xmlns:tag="ns3" ` "\r\n\t" ` >
<body xmlns:foo="ns1" xmlns="ns2" xmlns:tag="ns3" `
"\r\n\t" ` >
<hello lang="en">World &lt;&gt;&apos;&quot; &#x767d;&#40300;翔</hello>
<goodbye />
<outer foo:attr="value" xmlns:tag="ns4">
......@@ -90,8 +91,8 @@ var cookedTokens = []Token{
}
type stringReader struct {
s string;
off int;
s string;
off int;
}
func (r *stringReader) Read(b []byte) (n int, err os.Error) {
......@@ -116,7 +117,7 @@ func (r *stringReader) ReadByte() (b byte, err os.Error) {
}
func StringReader(s string) io.Reader {
return &stringReader{s, 0}
return &stringReader{s, 0};
}
func TestRawToken(t *testing.T) {
......@@ -146,4 +147,3 @@ func TestToken(t *testing.T) {
}
}
}
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