diff options
| author | Robert Griesemer <gri@golang.org> | 2009-11-06 14:24:38 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2009-11-06 14:24:38 -0800 |
| commit | 828334dd95ce8e4bf3662bd5c89d7c417f0741d0 (patch) | |
| tree | fd7e0c9961bc3af2ddf105e9cc1943f2509ac584 /src/pkg/go | |
| parent | eb5cdfd67ff6d32df4c4c27840eaee027c5e3512 (diff) | |
| download | golang-828334dd95ce8e4bf3662bd5c89d7c417f0741d0.tar.gz | |
- fine-tuning of one-line func heuristic (nodes.go)
- enabled for function declarations (not just function literals)
- applied gofmt -w $GOROOT/src
(look for instance at src/pkg/debug/elf/elf.go)
R=r, rsc
CC=go-dev
http://go/go-review/1026006
Diffstat (limited to 'src/pkg/go')
| -rw-r--r-- | src/pkg/go/ast/ast.go | 225 | ||||
| -rw-r--r-- | src/pkg/go/ast/scope.go | 4 | ||||
| -rw-r--r-- | src/pkg/go/doc/comment.go | 4 | ||||
| -rw-r--r-- | src/pkg/go/doc/doc.go | 28 | ||||
| -rw-r--r-- | src/pkg/go/parser/parser.go | 8 | ||||
| -rw-r--r-- | src/pkg/go/parser/parser_test.go | 4 | ||||
| -rw-r--r-- | src/pkg/go/printer/nodes.go | 77 | ||||
| -rw-r--r-- | src/pkg/go/printer/testdata/comments.golden | 3 | ||||
| -rw-r--r-- | src/pkg/go/printer/testdata/declarations.golden | 30 | ||||
| -rw-r--r-- | src/pkg/go/printer/testdata/statements.golden | 3 | ||||
| -rw-r--r-- | src/pkg/go/scanner/errors.go | 16 | ||||
| -rw-r--r-- | src/pkg/go/scanner/scanner_test.go | 4 | ||||
| -rw-r--r-- | src/pkg/go/token/token.go | 20 |
13 files changed, 153 insertions, 273 deletions
diff --git a/src/pkg/go/ast/ast.go b/src/pkg/go/ast/ast.go index 92f24d6ef..ec299c5f7 100644 --- a/src/pkg/go/ast/ast.go +++ b/src/pkg/go/ast/ast.go @@ -300,82 +300,42 @@ type ( // Pos() implementations for expression/type where the position // corresponds to the position of a sub-node. // -func (x *StringList) Pos() token.Position { - return x.Strings[0].Pos(); -} -func (x *FuncLit) Pos() token.Position { - return x.Type.Pos(); -} -func (x *CompositeLit) Pos() token.Position { - return x.Type.Pos(); -} -func (x *SelectorExpr) Pos() token.Position { - return x.X.Pos(); -} -func (x *IndexExpr) Pos() token.Position { - return x.X.Pos(); -} -func (x *TypeAssertExpr) Pos() token.Position { - return x.X.Pos(); -} -func (x *CallExpr) Pos() token.Position { - return x.Fun.Pos(); -} -func (x *BinaryExpr) Pos() token.Position { - return x.X.Pos(); -} -func (x *KeyValueExpr) Pos() token.Position { - return x.Key.Pos(); -} +func (x *StringList) Pos() token.Position { return x.Strings[0].Pos() } +func (x *FuncLit) Pos() token.Position { return x.Type.Pos() } +func (x *CompositeLit) Pos() token.Position { return x.Type.Pos() } +func (x *SelectorExpr) Pos() token.Position { return x.X.Pos() } +func (x *IndexExpr) Pos() token.Position { return x.X.Pos() } +func (x *TypeAssertExpr) Pos() token.Position { return x.X.Pos() } +func (x *CallExpr) Pos() token.Position { return x.Fun.Pos() } +func (x *BinaryExpr) Pos() token.Position { return x.X.Pos() } +func (x *KeyValueExpr) Pos() token.Position { return x.Key.Pos() } // exprNode() ensures that only expression/type nodes can be // assigned to an ExprNode. -func (x *BadExpr) exprNode() { -} -func (x *Ident) exprNode() { -} -func (x *Ellipsis) exprNode() { -} -func (x *BasicLit) exprNode() { -} -func (x *StringList) exprNode() { -} -func (x *FuncLit) exprNode() { -} -func (x *CompositeLit) exprNode() { -} -func (x *ParenExpr) exprNode() { -} -func (x *SelectorExpr) exprNode() { -} -func (x *IndexExpr) exprNode() { -} -func (x *TypeAssertExpr) exprNode() { -} -func (x *CallExpr) exprNode() { -} -func (x *StarExpr) exprNode() { -} -func (x *UnaryExpr) exprNode() { -} -func (x *BinaryExpr) exprNode() { -} -func (x *KeyValueExpr) exprNode() { -} - -func (x *ArrayType) exprNode() { -} -func (x *StructType) exprNode() { -} -func (x *FuncType) exprNode() { -} -func (x *InterfaceType) exprNode() { -} -func (x *MapType) exprNode() { -} -func (x *ChanType) exprNode() { -} +func (x *BadExpr) exprNode() {} +func (x *Ident) exprNode() {} +func (x *Ellipsis) exprNode() {} +func (x *BasicLit) exprNode() {} +func (x *StringList) exprNode() {} +func (x *FuncLit) exprNode() {} +func (x *CompositeLit) exprNode() {} +func (x *ParenExpr) exprNode() {} +func (x *SelectorExpr) exprNode() {} +func (x *IndexExpr) exprNode() {} +func (x *TypeAssertExpr) exprNode() {} +func (x *CallExpr) exprNode() {} +func (x *StarExpr) exprNode() {} +func (x *UnaryExpr) exprNode() {} +func (x *BinaryExpr) exprNode() {} +func (x *KeyValueExpr) exprNode() {} + +func (x *ArrayType) exprNode() {} +func (x *StructType) exprNode() {} +func (x *FuncType) exprNode() {} +func (x *InterfaceType) exprNode() {} +func (x *MapType) exprNode() {} +func (x *ChanType) exprNode() {} // IsExported returns whether name is an exported Go symbol @@ -387,13 +347,9 @@ func IsExported(name string) bool { // IsExported returns whether name is an exported Go symbol // (i.e., whether it begins with an uppercase letter). -func (name *Ident) IsExported() bool { - return IsExported(name.Value); -} +func (name *Ident) IsExported() bool { return IsExported(name.Value) } -func (name *Ident) String() string { - return name.Value; -} +func (name *Ident) String() string { return name.Value } // ---------------------------------------------------------------------------- @@ -566,68 +522,37 @@ type ( // Pos() implementations for statement nodes where the position // corresponds to the position of a sub-node. // -func (s *DeclStmt) Pos() token.Position { - return s.Decl.Pos(); -} -func (s *LabeledStmt) Pos() token.Position { - return s.Label.Pos(); -} -func (s *ExprStmt) Pos() token.Position { - return s.X.Pos(); -} -func (s *IncDecStmt) Pos() token.Position { - return s.X.Pos(); -} -func (s *AssignStmt) Pos() token.Position { - return s.Lhs[0].Pos(); -} +func (s *DeclStmt) Pos() token.Position { return s.Decl.Pos() } +func (s *LabeledStmt) Pos() token.Position { return s.Label.Pos() } +func (s *ExprStmt) Pos() token.Position { return s.X.Pos() } +func (s *IncDecStmt) Pos() token.Position { return s.X.Pos() } +func (s *AssignStmt) Pos() token.Position { return s.Lhs[0].Pos() } // stmtNode() ensures that only statement nodes can be // assigned to a StmtNode. // -func (s *BadStmt) stmtNode() { -} -func (s *DeclStmt) stmtNode() { -} -func (s *EmptyStmt) stmtNode() { -} -func (s *LabeledStmt) stmtNode() { -} -func (s *ExprStmt) stmtNode() { -} -func (s *IncDecStmt) stmtNode() { -} -func (s *AssignStmt) stmtNode() { -} -func (s *GoStmt) stmtNode() { -} -func (s *DeferStmt) stmtNode() { -} -func (s *ReturnStmt) stmtNode() { -} -func (s *BranchStmt) stmtNode() { -} -func (s *BlockStmt) stmtNode() { -} -func (s *IfStmt) stmtNode() { -} -func (s *CaseClause) stmtNode() { -} -func (s *SwitchStmt) stmtNode() { -} -func (s *TypeCaseClause) stmtNode() { -} -func (s *TypeSwitchStmt) stmtNode() { -} -func (s *CommClause) stmtNode() { -} -func (s *SelectStmt) stmtNode() { -} -func (s *ForStmt) stmtNode() { -} -func (s *RangeStmt) stmtNode() { -} +func (s *BadStmt) stmtNode() {} +func (s *DeclStmt) stmtNode() {} +func (s *EmptyStmt) stmtNode() {} +func (s *LabeledStmt) stmtNode() {} +func (s *ExprStmt) stmtNode() {} +func (s *IncDecStmt) stmtNode() {} +func (s *AssignStmt) stmtNode() {} +func (s *GoStmt) stmtNode() {} +func (s *DeferStmt) stmtNode() {} +func (s *ReturnStmt) stmtNode() {} +func (s *BranchStmt) stmtNode() {} +func (s *BlockStmt) stmtNode() {} +func (s *IfStmt) stmtNode() {} +func (s *CaseClause) stmtNode() {} +func (s *SwitchStmt) stmtNode() {} +func (s *TypeCaseClause) stmtNode() {} +func (s *TypeSwitchStmt) stmtNode() {} +func (s *CommClause) stmtNode() {} +func (s *SelectStmt) stmtNode() {} +func (s *ForStmt) stmtNode() {} +func (s *RangeStmt) stmtNode() {} // ---------------------------------------------------------------------------- @@ -680,23 +605,16 @@ func (s *ImportSpec) Pos() token.Position { return s.Path[0].Pos(); } -func (s *ValueSpec) Pos() token.Position { - return s.Names[0].Pos(); -} -func (s *TypeSpec) Pos() token.Position { - return s.Name.Pos(); -} +func (s *ValueSpec) Pos() token.Position { return s.Names[0].Pos() } +func (s *TypeSpec) Pos() token.Position { return s.Name.Pos() } // specNode() ensures that only spec nodes can be // assigned to a Spec. // -func (s *ImportSpec) specNode() { -} -func (s *ValueSpec) specNode() { -} -func (s *TypeSpec) specNode() { -} +func (s *ImportSpec) specNode() {} +func (s *ValueSpec) specNode() {} +func (s *TypeSpec) specNode() {} // A declaration is represented by one of the following declaration nodes. @@ -742,20 +660,15 @@ type ( // The position of a FuncDecl node is the position of its function type. -func (d *FuncDecl) Pos() token.Position { - return d.Type.Pos(); -} +func (d *FuncDecl) Pos() token.Position { return d.Type.Pos() } // declNode() ensures that only declaration nodes can be // assigned to a DeclNode. // -func (d *BadDecl) declNode() { -} -func (d *GenDecl) declNode() { -} -func (d *FuncDecl) declNode() { -} +func (d *BadDecl) declNode() {} +func (d *GenDecl) declNode() {} +func (d *FuncDecl) declNode() {} // ---------------------------------------------------------------------------- diff --git a/src/pkg/go/ast/scope.go b/src/pkg/go/ast/scope.go index 988b11e95..301630de6 100644 --- a/src/pkg/go/ast/scope.go +++ b/src/pkg/go/ast/scope.go @@ -17,9 +17,7 @@ type Scope struct { // NewScope creates a new scope nested in the outer scope. -func NewScope(outer *Scope) *Scope { - return &Scope{outer, make(map[string]*Ident)}; -} +func NewScope(outer *Scope) *Scope { return &Scope{outer, make(map[string]*Ident)} } // Declare inserts an identifier into the scope s. If the diff --git a/src/pkg/go/doc/comment.go b/src/pkg/go/doc/comment.go index 18fce5c4e..75eb7064b 100644 --- a/src/pkg/go/doc/comment.go +++ b/src/pkg/go/doc/comment.go @@ -165,9 +165,7 @@ func indentLen(s []byte) int { } -func isBlank(s []byte) bool { - return len(s) == 0 || (len(s) == 1 && s[0] == '\n'); -} +func isBlank(s []byte) bool { return len(s) == 0 || (len(s) == 1 && s[0] == '\n') } func commonPrefix(a, b []byte) []byte { diff --git a/src/pkg/go/doc/doc.go b/src/pkg/go/doc/doc.go index 7f8c558e7..d9d436ccb 100644 --- a/src/pkg/go/doc/doc.go +++ b/src/pkg/go/doc/doc.go @@ -324,12 +324,8 @@ type ValueDoc struct { type sortValueDoc []*ValueDoc -func (p sortValueDoc) Len() int { - return len(p); -} -func (p sortValueDoc) Swap(i, j int) { - p[i], p[j] = p[j], p[i]; -} +func (p sortValueDoc) Len() int { return len(p) } +func (p sortValueDoc) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func declName(d *ast.GenDecl) string { @@ -388,15 +384,9 @@ type FuncDoc struct { type sortFuncDoc []*FuncDoc -func (p sortFuncDoc) Len() int { - return len(p); -} -func (p sortFuncDoc) Swap(i, j int) { - p[i], p[j] = p[j], p[i]; -} -func (p sortFuncDoc) Less(i, j int) bool { - return p[i].Name < p[j].Name; -} +func (p sortFuncDoc) Len() int { return len(p) } +func (p sortFuncDoc) Swap(i, j int) { p[i], p[j] = p[j], p[i] } +func (p sortFuncDoc) Less(i, j int) bool { return p[i].Name < p[j].Name } func makeFuncDocs(m map[string]*ast.FuncDecl) []*FuncDoc { @@ -436,12 +426,8 @@ type TypeDoc struct { type sortTypeDoc []*TypeDoc -func (p sortTypeDoc) Len() int { - return len(p); -} -func (p sortTypeDoc) Swap(i, j int) { - p[i], p[j] = p[j], p[i]; -} +func (p sortTypeDoc) Len() int { return len(p) } +func (p sortTypeDoc) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func (p sortTypeDoc) Less(i, j int) bool { // sort by name // pull blocks (name = "") up to top diff --git a/src/pkg/go/parser/parser.go b/src/pkg/go/parser/parser.go index 9fd8de8f4..53fff192d 100644 --- a/src/pkg/go/parser/parser.go +++ b/src/pkg/go/parser/parser.go @@ -273,9 +273,7 @@ func openScope(p *parser) *parser { // Usage pattern: defer close(openScope(p)); -func close(p *parser) { - p.topScope = p.topScope.Outer; -} +func close(p *parser) { p.topScope = p.topScope.Outer } func (p *parser) declare(ident *ast.Ident) { @@ -787,9 +785,7 @@ func (p *parser) tryRawType(ellipsisOk bool) ast.Expr { } -func (p *parser) tryType() ast.Expr { - return p.tryRawType(false); -} +func (p *parser) tryType() ast.Expr { return p.tryRawType(false) } // ---------------------------------------------------------------------------- diff --git a/src/pkg/go/parser/parser_test.go b/src/pkg/go/parser/parser_test.go index fc366bcc3..257ef9a7f 100644 --- a/src/pkg/go/parser/parser_test.go +++ b/src/pkg/go/parser/parser_test.go @@ -72,9 +72,7 @@ func nameFilter(filename string) bool { } -func dirFilter(d *os.Dir) bool { - return nameFilter(d.Name); -} +func dirFilter(d *os.Dir) bool { return nameFilter(d.Name) } func TestParse4(t *testing.T) { diff --git a/src/pkg/go/printer/nodes.go b/src/pkg/go/printer/nodes.go index 7e27b3b6e..4c2f0c57f 100644 --- a/src/pkg/go/printer/nodes.go +++ b/src/pkg/go/printer/nodes.go @@ -18,19 +18,21 @@ import ( // Disabled formatting - enable eventually and remove the flag. const ( - oneLineFuncDecls = false; compositeLitBlank = false; stringListMode = exprListMode(0); // previously: noIndent ) -// Other outstanding formatting issues: +// Other 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 +// when the comment spans multiple lines; if such a comment is just two lines, formatting is +// not idempotent // - formatting of expression lists; especially for string lists (stringListMode) // - blank after { and before } in one-line composite literals probably looks better +// - should use blank instead of tab to separate one-line function bodies from +// the function header unless there is a group of consecutive one-liners // ---------------------------------------------------------------------------- @@ -497,7 +499,7 @@ func (p *printer) expr1(expr ast.Expr, prec1 int, multiLine *bool) (optSemi bool case *ast.FuncLit: p.expr(x.Type, multiLine); - p.funcBody(x.Body, true, multiLine); + p.funcBody(x.Body, distance(x.Type.Pos(), p.pos), true, multiLine); case *ast.ParenExpr: p.print(token.LPAREN); @@ -994,42 +996,50 @@ func (p *printer) genDecl(d *ast.GenDecl, context declContext, multiLine *bool) } -func (p *printer) isOneLiner(b *ast.BlockStmt) bool { - switch { - case len(b.List) > 1 || p.commentBefore(b.Rbrace): - return false; // too many statements or there is a comment - all bets are off - case len(b.List) == 0: - return true; // empty block and no comments - } - - // test-print the statement and see if it would fit +// nodeSize determines the size of n in chars after formatting. +// The result is <= maxSize if the node fits on one line with at +// most maxSize chars and the formatted output doesn't contain +// any control chars. Otherwise, the result is > maxSize. +// +func (p *printer) nodeSize(n ast.Node, maxSize int) (size int) { + size = maxSize+1; // assume n doesn't fit var buf bytes.Buffer; - _, err := p.Config.Fprint(&buf, b.List[0]); - if err != nil { - return false; // don't try - } - - if buf.Len() > 40 { - return false; // too long + if _, err := p.Config.Fprint(&buf, n); err != nil { + return; } - - for _, ch := range buf.Bytes() { - if ch < ' ' { - return false; // contains control chars (tabs, newlines) + if buf.Len() <= maxSize { + for _, ch := range buf.Bytes() { + if ch < ' ' { + return; + } } + size = buf.Len(); // n fits } + return; +} - return true; + +func (p *printer) isOneLineFunc(b *ast.BlockStmt, headerSize int) bool { + const maxSize = 90; // adjust as appropriate, this is an approximate value + bodySize := 0; + switch { + case len(b.List) > 1 || p.commentBefore(b.Rbrace): + return false; // too many statements or there is a comment - all bets are off + case len(b.List) == 1: + bodySize = p.nodeSize(b.List[0], maxSize); + } + // require both headers and overall size to be not "too large" + return headerSize <= maxSize/2 && headerSize + bodySize <= maxSize; } // Sets multiLine to true if the function body spans multiple lines. -func (p *printer) funcBody(b *ast.BlockStmt, isLit bool, multiLine *bool) { +func (p *printer) funcBody(b *ast.BlockStmt, headerSize int, isLit bool, multiLine *bool) { if b == nil { return; } - if (oneLineFuncDecls || isLit) && p.isOneLiner(b) { + if p.isOneLineFunc(b, headerSize) { sep := vtab; if isLit { sep = blank; @@ -1050,6 +1060,17 @@ func (p *printer) funcBody(b *ast.BlockStmt, isLit bool, multiLine *bool) { } +// distance returns the column difference between from and to if both +// are on the same line; if they are on different lines (or unknown) +// the result is infinity (1<<30). +func distance(from, to token.Position) int { + if from.IsValid() && to.IsValid() && from.Line == to.Line { + return to.Column - from.Column; + } + return 1<<30; +} + + // Sets multiLine to true if the declaration spans multiple lines. func (p *printer) funcDecl(d *ast.FuncDecl, multiLine *bool) { p.leadComment(d.Doc); @@ -1066,7 +1087,7 @@ func (p *printer) funcDecl(d *ast.FuncDecl, multiLine *bool) { } p.expr(d.Name, multiLine); p.signature(d.Type.Params, d.Type.Results, multiLine); - p.funcBody(d.Body, false, multiLine); + p.funcBody(d.Body, distance(d.Pos(), p.pos), false, multiLine); } diff --git a/src/pkg/go/printer/testdata/comments.golden b/src/pkg/go/printer/testdata/comments.golden index 94a4d8da6..cb2827476 100644 --- a/src/pkg/go/printer/testdata/comments.golden +++ b/src/pkg/go/printer/testdata/comments.golden @@ -278,8 +278,7 @@ func _() { // Some interesting interspersed comments -func _( /* this */ x /* is */ /* an */ int) { -} +func _( /* this */ x /* is */ /* an */ int) {} // Line comments with tabs diff --git a/src/pkg/go/printer/testdata/declarations.golden b/src/pkg/go/printer/testdata/declarations.golden index 2f5cf6059..43ba1fd53 100644 --- a/src/pkg/go/printer/testdata/declarations.golden +++ b/src/pkg/go/printer/testdata/declarations.golden @@ -445,26 +445,14 @@ func _() { // formatting of consecutive single-line functions -func _() { -} -func _() { -} -func _() { -} +func _() {} +func _() {} +func _() {} -func _() { -} // an empty line before this function -func _() { -} -func _() { -} +func _() {} // an empty line before this function +func _() {} +func _() {} -func _() { - f(1, 2, 3); -} -func _(x int) int { - return x+1; -} -func _() int { - type T struct{} -} +func _() { f(1, 2, 3) } +func _(x int) int { return x+1 } +func _() int { type T struct{} } diff --git a/src/pkg/go/printer/testdata/statements.golden b/src/pkg/go/printer/testdata/statements.golden index a1839aa18..875bac40b 100644 --- a/src/pkg/go/printer/testdata/statements.golden +++ b/src/pkg/go/printer/testdata/statements.golden @@ -6,8 +6,7 @@ package statements var expr bool -func use(x interface{}) { -} +func use(x interface{}) {} // Formatting of if-statement headers. func _() { diff --git a/src/pkg/go/scanner/errors.go b/src/pkg/go/scanner/errors.go index 090066701..a8219b190 100644 --- a/src/pkg/go/scanner/errors.go +++ b/src/pkg/go/scanner/errors.go @@ -39,9 +39,7 @@ type ErrorVector struct { // Init initializes an ErrorVector. -func (h *ErrorVector) Init() { - h.errors.Init(0); -} +func (h *ErrorVector) Init() { h.errors.Init(0) } // NewErrorVector creates a new ErrorVector. @@ -53,9 +51,7 @@ func NewErrorVector() *ErrorVector { // ErrorCount returns the number of errors collected. -func (h *ErrorVector) ErrorCount() int { - return h.errors.Len(); -} +func (h *ErrorVector) ErrorCount() int { return h.errors.Len() } // Within ErrorVector, an error is represented by an Error node. The @@ -83,12 +79,8 @@ type ErrorList []*Error // ErrorList implements the sort Interface. -func (p ErrorList) Len() int { - return len(p); -} -func (p ErrorList) Swap(i, j int) { - p[i], p[j] = p[j], p[i]; -} +func (p ErrorList) Len() int { return len(p) } +func (p ErrorList) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func (p ErrorList) Less(i, j int) bool { diff --git a/src/pkg/go/scanner/scanner_test.go b/src/pkg/go/scanner/scanner_test.go index 052f3a8a8..0b036e8b4 100644 --- a/src/pkg/go/scanner/scanner_test.go +++ b/src/pkg/go/scanner/scanner_test.go @@ -357,7 +357,9 @@ func TestStdErrorHander(t *testing.T) { v := NewErrorVector(); nerrors := Tokenize("File1", strings.Bytes(src), v, 0, - func(pos token.Position, tok token.Token, litb []byte) bool { return tok != token.EOF }); + func(pos token.Position, tok token.Token, litb []byte) bool { + return tok != token.EOF; + }); list := v.GetErrorList(Raw); if len(list) != 9 { diff --git a/src/pkg/go/token/token.go b/src/pkg/go/token/token.go index b3191c22c..28c335461 100644 --- a/src/pkg/go/token/token.go +++ b/src/pkg/go/token/token.go @@ -308,23 +308,17 @@ func Lookup(ident []byte) Token { // IsLiteral returns true for tokens corresponding to identifiers // and basic type literals; returns false otherwise. // -func (tok Token) IsLiteral() bool { - return literal_beg < tok && tok < literal_end; -} +func (tok Token) IsLiteral() bool { return literal_beg < tok && tok < literal_end } // IsOperator returns true for tokens corresponding to operators and // delimiters; returns false otherwise. // -func (tok Token) IsOperator() bool { - return operator_beg < tok && tok < operator_end; -} +func (tok Token) IsOperator() bool { return operator_beg < tok && tok < operator_end } // IsKeyword returns true for tokens corresponding to keywords; // returns false otherwise. // -func (tok Token) IsKeyword() bool { - return keyword_beg < tok && tok < keyword_end; -} +func (tok Token) IsKeyword() bool { return keyword_beg < tok && tok < keyword_end } // Token source positions are represented by a Position value. @@ -341,15 +335,11 @@ type Position struct { // Pos is an accessor method for anonymous Position fields. // It returns its receiver. // -func (pos *Position) Pos() Position { - return *pos; -} +func (pos *Position) Pos() Position { return *pos } // IsValid returns true if the position is valid. -func (pos *Position) IsValid() bool { - return pos.Line > 0; -} +func (pos *Position) IsValid() bool { return pos.Line > 0 } func (pos Position) String() string { |
