summaryrefslogtreecommitdiff
path: root/src/pkg/go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-10-06 19:41:51 -0700
committerRuss Cox <rsc@golang.org>2009-10-06 19:41:51 -0700
commit6c2652e6fd54ce34ca3be95540c54cebb52bfece (patch)
tree2366cc62ab4dee2e5698d6d6e5b299d6819a7edd /src/pkg/go
parentdb62e99a735a036afda2098f1a721fe8dbf6ce76 (diff)
downloadgolang-6c2652e6fd54ce34ca3be95540c54cebb52bfece.tar.gz
apply gofmt to go, gob, hash, http, image, io, json, log
R=gri DELTA=1359 (138 added, 32 deleted, 1189 changed) OCL=35408 CL=35420
Diffstat (limited to 'src/pkg/go')
-rw-r--r--src/pkg/go/ast/ast.go497
-rw-r--r--src/pkg/go/ast/filter.go22
-rw-r--r--src/pkg/go/parser/interface.go26
-rw-r--r--src/pkg/go/parser/parser_test.go6
-rw-r--r--src/pkg/go/scanner/errors.go26
-rw-r--r--src/pkg/go/scanner/scanner.go167
6 files changed, 406 insertions, 338 deletions
diff --git a/src/pkg/go/ast/ast.go b/src/pkg/go/ast/ast.go
index 8861049aa..c346c48b3 100644
--- a/src/pkg/go/ast/ast.go
+++ b/src/pkg/go/ast/ast.go
@@ -65,8 +65,8 @@ type Decl interface {
// A Comment node represents a single //-style or /*-style comment.
type Comment struct {
- token.Position; // beginning position of the comment
- Text []byte; // comment text (excluding '\n' for //-style comments)
+ token.Position; // beginning position of the comment
+ Text []byte; // comment text (excluding '\n' for //-style comments)
}
@@ -74,8 +74,8 @@ type Comment struct {
// with no other tokens and no empty lines between.
//
type CommentGroup struct {
- List []*Comment;
- Next *CommentGroup; // next comment group in source order
+ List []*Comment;
+ Next *CommentGroup; // next comment group in source order
}
@@ -87,12 +87,12 @@ type CommentGroup struct {
// in a signature.
//
type Field struct {
- Doc *CommentGroup; // associated documentation; or nil
- Names []*Ident; // field/method/parameter names; or nil if anonymous field
- Type Expr; // field/method/parameter type
- Tag []*BasicLit; // field tag; or nil
- Comment *CommentGroup; // line comments; or nil
-};
+ Doc *CommentGroup; // associated documentation; or nil
+ Names []*Ident; // field/method/parameter names; or nil if anonymous field
+ Type Expr; // field/method/parameter type
+ Tag []*BasicLit; // field tag; or nil
+ Comment *CommentGroup; // line comments; or nil
+}
// An expression is represented by a tree consisting of one
@@ -103,28 +103,28 @@ type (
// syntax errors for which no correct expression nodes can be
// created.
//
- BadExpr struct {
- token.Position; // beginning position of bad expression
+ BadExpr struct {
+ token.Position; // beginning position of bad expression
};
// An Ident node represents an identifier.
- Ident struct {
- token.Position; // identifier position
- Value string; // identifier string (e.g. foobar)
+ Ident struct {
+ token.Position; // identifier position
+ Value string; // identifier string (e.g. foobar)
};
// An Ellipsis node stands for the "..." type in a
// parameter list or the "..." length in an array type.
//
- Ellipsis struct {
- token.Position; // position of "..."
+ Ellipsis struct {
+ token.Position; // position of "..."
};
// A BasicLit node represents a literal of basic type.
- BasicLit struct {
- token.Position; // literal position
- Kind token.Token; // token.INT, token.FLOAT, token.CHAR, or token.STRING
- Value []byte; // literal string; e.g. 42, 0x7f, 3.14, 1e-9, 'a', '\x7f', "foo" or `\m\n\o`
+ BasicLit struct {
+ token.Position; // literal position
+ Kind token.Token; // token.INT, token.FLOAT, token.CHAR, or token.STRING
+ Value []byte; // literal string; e.g. 42, 0x7f, 3.14, 1e-9, 'a', '\x7f', "foo" or `\m\n\o`
};
// A StringList node represents a sequence of adjacent string literals.
@@ -132,93 +132,93 @@ type (
// node; StringList nodes are used only if there are two or more string
// literals in a sequence.
//
- StringList struct {
- Strings []*BasicLit; // list of strings, len(Strings) > 1
+ StringList struct {
+ Strings []*BasicLit; // list of strings, len(Strings) > 1
};
// A FuncLit node represents a function literal.
- FuncLit struct {
- Type *FuncType; // function type
- Body *BlockStmt; // function body
+ FuncLit struct {
+ Type *FuncType; // function type
+ Body *BlockStmt; // function body
};
// A CompositeLit node represents a composite literal.
//
- CompositeLit struct {
- Type Expr; // literal type
- Lbrace token.Position; // position of "{"
- Elts []Expr; // list of composite elements
- Rbrace token.Position; // position of "}"
+ CompositeLit struct {
+ Type Expr; // literal type
+ Lbrace token.Position; // position of "{"
+ Elts []Expr; // list of composite elements
+ Rbrace token.Position; // position of "}"
};
// A ParenExpr node represents a parenthesized expression.
- ParenExpr struct {
- token.Position; // position of "("
- X Expr; // parenthesized expression
- Rparen token.Position; // position of ")"
+ ParenExpr struct {
+ token.Position; // position of "("
+ X Expr; // parenthesized expression
+ Rparen token.Position; // position of ")"
};
// A SelectorExpr node represents an expression followed by a selector.
- SelectorExpr struct {
- X Expr; // expression
- Sel *Ident; // field selector
+ SelectorExpr struct {
+ X Expr; // expression
+ Sel *Ident; // field selector
};
// An IndexExpr node represents an expression followed by an index or slice.
- IndexExpr struct {
- X Expr; // expression
- Index Expr; // index expression or beginning of slice range
- End Expr; // end of slice range; or nil
+ IndexExpr struct {
+ X Expr; // expression
+ Index Expr; // index expression or beginning of slice range
+ End Expr; // end of slice range; or nil
};
// A TypeAssertExpr node represents an expression followed by a
// type assertion.
//
- TypeAssertExpr struct {
- X Expr; // expression
- Type Expr; // asserted type; nil means type switch X.(type)
+ TypeAssertExpr struct {
+ X Expr; // expression
+ Type Expr; // asserted type; nil means type switch X.(type)
};
// A CallExpr node represents an expression followed by an argument list.
- CallExpr struct {
- Fun Expr; // function expression
- Lparen token.Position; // position of "("
- Args []Expr; // function arguments
- Rparen token.Position; // positions of ")"
+ CallExpr struct {
+ Fun Expr; // function expression
+ Lparen token.Position; // position of "("
+ Args []Expr; // function arguments
+ Rparen token.Position; // positions of ")"
};
// A StarExpr node represents an expression of the form "*" Expression.
// Semantically it could be a unary "*" expression, or a pointer type.
- StarExpr struct {
- token.Position; // position of "*"
- X Expr; // operand
+ StarExpr struct {
+ token.Position; // position of "*"
+ X Expr; // operand
};
// A UnaryExpr node represents a unary expression.
// Unary "*" expressions are represented via StarExpr nodes.
//
- UnaryExpr struct {
- token.Position; // position of Op
- Op token.Token; // operator
- X Expr; // operand
+ UnaryExpr struct {
+ token.Position; // position of Op
+ Op token.Token; // operator
+ X Expr; // operand
};
// A BinaryExpr node represents a binary expression.
//
- BinaryExpr struct {
- X Expr; // left operand
- OpPos token.Position; // position of Op
- Op token.Token; // operator
- Y Expr; // right operand
+ BinaryExpr struct {
+ X Expr; // left operand
+ OpPos token.Position; // position of Op
+ Op token.Token; // operator
+ Y Expr; // right operand
};
// A KeyValueExpr node represents (key : value) pairs
// in composite literals.
//
- KeyValueExpr struct {
- Key Expr;
- Colon token.Position; // position of ":"
- Value Expr;
+ KeyValueExpr struct {
+ Key Expr;
+ Colon token.Position; // position of ":"
+ Value Expr;
};
)
@@ -227,8 +227,9 @@ type (
// of the following constants.
//
type ChanDir int
+
const (
- SEND ChanDir = 1 << iota;
+ SEND ChanDir = 1<<iota;
RECV;
)
@@ -239,51 +240,51 @@ const (
//
type (
// An ArrayType node represents an array or slice type.
- ArrayType struct {
- token.Position; // position of "["
- Len Expr; // Ellipsis node for [...]T array types, nil for slice types
- Elt Expr; // element type
+ ArrayType struct {
+ token.Position; // position of "["
+ Len Expr; // Ellipsis node for [...]T array types, nil for slice types
+ Elt Expr; // element type
};
// A StructType node represents a struct type.
- StructType struct {
- token.Position; // position of "struct" keyword
- Lbrace token.Position; // position of "{"
- Fields []*Field; // list of field declarations
- Rbrace token.Position; // position of "}"
- Incomplete bool; // true if (source) fields are missing in the Fields list
+ StructType struct {
+ token.Position; // position of "struct" keyword
+ Lbrace token.Position; // position of "{"
+ Fields []*Field; // list of field declarations
+ Rbrace token.Position; // position of "}"
+ Incomplete bool; // true if (source) fields are missing in the Fields list
};
// Pointer types are represented via StarExpr nodes.
// A FuncType node represents a function type.
- FuncType struct {
- token.Position; // position of "func" keyword
- Params []*Field; // (incoming) parameters
- Results []*Field; // (outgoing) results
+ FuncType struct {
+ token.Position; // position of "func" keyword
+ Params []*Field; // (incoming) parameters
+ Results []*Field; // (outgoing) results
};
// An InterfaceType node represents an interface type.
- InterfaceType struct {
- token.Position; // position of "interface" keyword
- Lbrace token.Position; // position of "{"
- Methods []*Field; // list of methods
- Rbrace token.Position; // position of "}"
- Incomplete bool; // true if (source) methods are missing in the Methods list
+ InterfaceType struct {
+ token.Position; // position of "interface" keyword
+ Lbrace token.Position; // position of "{"
+ Methods []*Field; // list of methods
+ Rbrace token.Position; // position of "}"
+ Incomplete bool; // true if (source) methods are missing in the Methods list
};
// A MapType node represents a map type.
- MapType struct {
- token.Position; // position of "map" keyword
- Key Expr;
- Value Expr;
+ MapType struct {
+ token.Position; // position of "map" keyword
+ Key Expr;
+ Value Expr;
};
// A ChanType node represents a channel type.
- ChanType struct {
- token.Position; // position of "chan" keyword or "<-" (whichever comes first)
- Dir ChanDir; // channel direction
- Value Expr; // value type
+ ChanType struct {
+ token.Position; // position of "chan" keyword or "<-" (whichever comes first)
+ Dir ChanDir; // channel direction
+ Value Expr; // value type
};
)
@@ -291,15 +292,33 @@ 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
@@ -358,12 +377,12 @@ type (
// syntax errors for which no correct statement nodes can be
// created.
//
- BadStmt struct {
- token.Position; // beginning position of bad statement
+ BadStmt struct {
+ token.Position; // beginning position of bad statement
};
// A DeclStmt node represents a declaration in a statement list.
- DeclStmt struct {
+ DeclStmt struct {
Decl Decl;
};
@@ -371,145 +390,145 @@ type (
// The "position" of the empty statement is the position
// of the immediately preceeding semicolon.
//
- EmptyStmt struct {
- token.Position; // position of preceeding ";"
+ EmptyStmt struct {
+ token.Position; // position of preceeding ";"
};
// A LabeledStmt node represents a labeled statement.
- LabeledStmt struct {
- Label *Ident;
- Stmt Stmt;
+ LabeledStmt struct {
+ Label *Ident;
+ Stmt Stmt;
};
// An ExprStmt node represents a (stand-alone) expression
// in a statement list.
//
- ExprStmt struct {
- X Expr; // expression
+ ExprStmt struct {
+ X Expr; // expression
};
// An IncDecStmt node represents an increment or decrement statement.
- IncDecStmt struct {
- X Expr;
- Tok token.Token; // INC or DEC
+ IncDecStmt struct {
+ X Expr;
+ Tok token.Token; // INC or DEC
};
// An AssignStmt node represents an assignment or
// a short variable declaration.
- AssignStmt struct {
- Lhs []Expr;
- TokPos token.Position; // position of Tok
- Tok token.Token; // assignment token, DEFINE
- Rhs []Expr;
+ AssignStmt struct {
+ Lhs []Expr;
+ TokPos token.Position; // position of Tok
+ Tok token.Token; // assignment token, DEFINE
+ Rhs []Expr;
};
// A GoStmt node represents a go statement.
- GoStmt struct {
- token.Position; // position of "go" keyword
- Call *CallExpr;
+ GoStmt struct {
+ token.Position; // position of "go" keyword
+ Call *CallExpr;
};
// A DeferStmt node represents a defer statement.
- DeferStmt struct {
- token.Position; // position of "defer" keyword
- Call *CallExpr;
+ DeferStmt struct {
+ token.Position; // position of "defer" keyword
+ Call *CallExpr;
};
// A ReturnStmt node represents a return statement.
- ReturnStmt struct {
- token.Position; // position of "return" keyword
- Results []Expr;
+ ReturnStmt struct {
+ token.Position; // position of "return" keyword
+ Results []Expr;
};
// A BranchStmt node represents a break, continue, goto,
// or fallthrough statement.
//
- BranchStmt struct {
- token.Position; // position of Tok
- Tok token.Token; // keyword token (BREAK, CONTINUE, GOTO, FALLTHROUGH)
- Label *Ident;
+ BranchStmt struct {
+ token.Position; // position of Tok
+ Tok token.Token; // keyword token (BREAK, CONTINUE, GOTO, FALLTHROUGH)
+ Label *Ident;
};
// A BlockStmt node represents a braced statement list.
- BlockStmt struct {
- token.Position; // position of "{"
- List []Stmt;
- Rbrace token.Position; // position of "}"
+ BlockStmt struct {
+ token.Position; // position of "{"
+ List []Stmt;
+ Rbrace token.Position; // position of "}"
};
// An IfStmt node represents an if statement.
- IfStmt struct {
- token.Position; // position of "if" keyword
- Init Stmt;
- Cond Expr;
- Body *BlockStmt;
- Else Stmt;
+ IfStmt struct {
+ token.Position; // position of "if" keyword
+ Init Stmt;
+ Cond Expr;
+ Body *BlockStmt;
+ Else Stmt;
};
// A CaseClause represents a case of an expression switch statement.
- CaseClause struct {
- token.Position; // position of "case" or "default" keyword
- Values []Expr; // nil means default case
- Colon token.Position; // position of ":"
- Body []Stmt; // statement list; or nil
+ CaseClause struct {
+ token.Position; // position of "case" or "default" keyword
+ Values []Expr; // nil means default case
+ Colon token.Position; // position of ":"
+ Body []Stmt; // statement list; or nil
};
// A SwitchStmt node represents an expression switch statement.
- SwitchStmt struct {
- token.Position; // position of "switch" keyword
- Init Stmt;
- Tag Expr;
- Body *BlockStmt; // CaseClauses only
+ SwitchStmt struct {
+ token.Position; // position of "switch" keyword
+ Init Stmt;
+ Tag Expr;
+ Body *BlockStmt; // CaseClauses only
};
// A TypeCaseClause represents a case of a type switch statement.
- TypeCaseClause struct {
- token.Position; // position of "case" or "default" keyword
- Types []Expr; // nil means default case
- Colon token.Position; // position of ":"
- Body []Stmt; // statement list; or nil
+ TypeCaseClause struct {
+ token.Position; // position of "case" or "default" keyword
+ Types []Expr; // nil means default case
+ Colon token.Position; // position of ":"
+ Body []Stmt; // statement list; or nil
};
// An TypeSwitchStmt node represents a type switch statement.
- TypeSwitchStmt struct {
- token.Position; // position of "switch" keyword
- Init Stmt;
- Assign Stmt; // x := y.(type)
- Body *BlockStmt; // TypeCaseClauses only
+ TypeSwitchStmt struct {
+ token.Position; // position of "switch" keyword
+ Init Stmt;
+ Assign Stmt; // x := y.(type)
+ Body *BlockStmt; // TypeCaseClauses only
};
// A CommClause node represents a case of a select statement.
- CommClause struct {
- token.Position; // position of "case" or "default" keyword
- Tok token.Token; // ASSIGN or DEFINE (valid only if Lhs != nil)
- Lhs, Rhs Expr; // Rhs == nil means default case
- Colon token.Position; // position of ":"
- Body []Stmt; // statement list; or nil
+ CommClause struct {
+ token.Position; // position of "case" or "default" keyword
+ Tok token.Token; // ASSIGN or DEFINE (valid only if Lhs != nil)
+ Lhs, Rhs Expr; // Rhs == nil means default case
+ Colon token.Position; // position of ":"
+ Body []Stmt; // statement list; or nil
};
// An SelectStmt node represents a select statement.
- SelectStmt struct {
- token.Position; // position of "select" keyword
- Body *BlockStmt; // CommClauses only
+ SelectStmt struct {
+ token.Position; // position of "select" keyword
+ Body *BlockStmt; // CommClauses only
};
// A ForStmt represents a for statement.
- ForStmt struct {
- token.Position; // position of "for" keyword
- Init Stmt;
- Cond Expr;
- Post Stmt;
- Body *BlockStmt;
+ ForStmt struct {
+ token.Position; // position of "for" keyword
+ Init Stmt;
+ Cond Expr;
+ Post Stmt;
+ Body *BlockStmt;
};
// A RangeStmt represents a for statement with a range clause.
- RangeStmt struct {
- token.Position; // position of "for" keyword
- Key, Value Expr; // Value may be nil
- TokPos token.Position; // position of Tok
- Tok token.Token; // ASSIGN, DEFINE
- X Expr; // value to range over
- Body *BlockStmt;
+ RangeStmt struct {
+ token.Position; // position of "for" keyword
+ Key, Value Expr; // Value may be nil
+ TokPos token.Position; // position of Tok
+ Tok token.Token; // ASSIGN, DEFINE
+ X Expr; // value to range over
+ Body *BlockStmt;
};
)
@@ -517,11 +536,21 @@ 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
@@ -558,34 +587,34 @@ func (s *RangeStmt) stmtNode() {}
//
type (
// The Spec type stands for any of *ImportSpec, *ValueSpec, and *TypeSpec.
- Spec interface {
+ Spec interface {
specNode();
};
// An ImportSpec node represents a single package import.
- ImportSpec struct {
- Doc *CommentGroup; // associated documentation; or nil
- Name *Ident; // local package name (including "."); or nil
- Path []*BasicLit; // package path
- Comment *CommentGroup; // line comments; or nil
+ ImportSpec struct {
+ Doc *CommentGroup; // associated documentation; or nil
+ Name *Ident; // local package name (including "."); or nil
+ Path []*BasicLit; // package path
+ Comment *CommentGroup; // line comments; or nil
};
// A ValueSpec node represents a constant or variable declaration
// (ConstSpec or VarSpec production).
- ValueSpec struct {
- Doc *CommentGroup; // associated documentation; or nil
- Names []*Ident; // value names
- Type Expr; // value type; or nil
- Values []Expr; // initial values; or nil
- Comment *CommentGroup; // line comments; or nil
+ ValueSpec struct {
+ Doc *CommentGroup; // associated documentation; or nil
+ Names []*Ident; // value names
+ Type Expr; // value type; or nil
+ Values []Expr; // initial values; or nil
+ Comment *CommentGroup; // line comments; or nil
};
// A TypeSpec node represents a type declaration (TypeSpec production).
- TypeSpec struct {
- Doc *CommentGroup; // associated documentation; or nil
- Name *Ident; // type name
- Type Expr;
- Comment *CommentGroup; // line comments; or nil
+ TypeSpec struct {
+ Doc *CommentGroup; // associated documentation; or nil
+ Name *Ident; // type name
+ Type Expr;
+ Comment *CommentGroup; // line comments; or nil
};
)
@@ -605,8 +634,8 @@ type (
// syntax errors for which no correct declaration nodes can be
// created.
//
- BadDecl struct {
- token.Position; // beginning position of bad declaration
+ BadDecl struct {
+ token.Position; // beginning position of bad declaration
};
// A GenDecl node (generic declaration node) represents an import,
@@ -620,28 +649,30 @@ type (
// token.TYPE *TypeSpec
// token.VAR *ValueSpec
//
- GenDecl struct {
- Doc *CommentGroup; // associated documentation; or nil
- token.Position; // position of Tok
- Tok token.Token; // IMPORT, CONST, TYPE, VAR
- Lparen token.Position; // position of '(', if any
- Specs []Spec;
- Rparen token.Position; // position of ')', if any
+ GenDecl struct {
+ Doc *CommentGroup; // associated documentation; or nil
+ token.Position; // position of Tok
+ Tok token.Token; // IMPORT, CONST, TYPE, VAR
+ Lparen token.Position; // position of '(', if any
+ Specs []Spec;
+ Rparen token.Position; // position of ')', if any
};
// A FuncDecl node represents a function declaration.
- FuncDecl struct {
- Doc *CommentGroup; // associated documentation; or nil
- Recv *Field; // receiver (methods); or nil (functions)
- Name *Ident; // function/method name
- Type *FuncType; // position of Func keyword, parameters and results
- Body *BlockStmt; // function body; or nil (forward declaration)
+ FuncDecl struct {
+ Doc *CommentGroup; // associated documentation; or nil
+ Recv *Field; // receiver (methods); or nil (functions)
+ Name *Ident; // function/method name
+ Type *FuncType; // position of Func keyword, parameters and results
+ Body *BlockStmt; // function body; or nil (forward declaration)
};
)
// 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
@@ -658,11 +689,11 @@ func (d *FuncDecl) declNode() {}
// A File node represents a Go source file.
//
type File struct {
- Doc *CommentGroup; // associated documentation; or nil
- token.Position; // position of "package" keyword
- Name *Ident; // package name
- Decls []Decl; // top-level declarations
- Comments *CommentGroup; // list of all comments in the source file
+ Doc *CommentGroup; // associated documentation; or nil
+ token.Position; // position of "package" keyword
+ Name *Ident; // package name
+ Decls []Decl; // top-level declarations
+ Comments *CommentGroup; // list of all comments in the source file
}
@@ -670,7 +701,7 @@ type File struct {
// collectively building a Go package.
//
type Package struct {
- Name string; // package name
- Path string; // package path
- Files map[string]*File; // path-relative filenames
+ Name string; // package name
+ Path string; // package path
+ Files map[string]*File; // path-relative filenames
}
diff --git a/src/pkg/go/ast/filter.go b/src/pkg/go/ast/filter.go
index 467f772be..9d0679a5a 100644
--- a/src/pkg/go/ast/filter.go
+++ b/src/pkg/go/ast/filter.go
@@ -4,7 +4,7 @@
package ast
-import "go/token";
+import "go/token"
func filterIdentList(list []*Ident) []*Ident {
@@ -15,7 +15,7 @@ func filterIdentList(list []*Ident) []*Ident {
j++;
}
}
- return list[0 : j];
+ return list[0:j];
}
@@ -65,7 +65,7 @@ func filterFieldList(list []*Field, incomplete *bool) []*Field {
if j < len(list) {
*incomplete = true;
}
- return list[0 : j];
+ return list[0:j];
}
@@ -76,7 +76,7 @@ func filterParamList(list []*Field) {
}
-var noPos token.Position;
+var noPos token.Position
func filterType(typ Expr) {
switch t := typ.(type) {
@@ -126,7 +126,7 @@ func filterSpecList(list []Spec) []Spec {
j++;
}
}
- return list[0 : j];
+ return list[0:j];
}
@@ -139,7 +139,7 @@ func filterDecl(decl Decl) bool {
// TODO consider removing function declaration altogether if
// forward declaration (i.e., if d.Body == nil) because
// in that case the actual declaration will come later.
- d.Body = nil; // strip body
+ d.Body = nil; // strip body
return d.Name.IsExported();
}
return false;
@@ -164,7 +164,7 @@ func FileExports(src *File) bool {
j++;
}
}
- src.Decls = src.Decls[0 : j];
+ src.Decls = src.Decls[0:j];
return j > 0;
}
@@ -190,7 +190,7 @@ func PackageExports(pkg *Package) bool {
// separator is an empty //-style comment that is interspersed between
// different comment groups when they are concatenated into a single group
//
-var separator = &Comment{noPos, []byte{'/', '/'}};
+var separator = &Comment{noPos, []byte{'/', '/'}}
// MergePackageFiles creates a file AST by merging the ASTs of the
@@ -203,7 +203,7 @@ func MergePackageFiles(pkg *Package) *File {
ndecls := 0;
for _, f := range pkg.Files {
if f.Doc != nil {
- ncomments += len(f.Doc.List) + 1; // +1 for separator
+ ncomments += len(f.Doc.List) + 1; // +1 for separator
}
ndecls += len(f.Decls);
}
@@ -215,7 +215,7 @@ func MergePackageFiles(pkg *Package) *File {
// than drop them on the floor.
var doc *CommentGroup;
if ncomments > 0 {
- list := make([]*Comment, ncomments - 1); // -1: no separator before first group
+ list := make([]*Comment, ncomments-1); // -1: no separator before first group
i := 0;
for _, f := range pkg.Files {
if f.Doc != nil {
@@ -226,7 +226,7 @@ func MergePackageFiles(pkg *Package) *File {
}
for _, c := range f.Doc.List {
list[i] = c;
- i++
+ i++;
}
}
}
diff --git a/src/pkg/go/parser/interface.go b/src/pkg/go/parser/interface.go
index f0a323b7a..193a1e7d8 100644
--- a/src/pkg/go/parser/interface.go
+++ b/src/pkg/go/parser/interface.go
@@ -7,14 +7,14 @@
package parser
import (
- "bytes";
- "fmt";
- "go/ast";
- "go/scanner";
- "io";
- "os";
- pathutil "path";
- "strings";
+ "bytes";
+ "fmt";
+ "go/ast";
+ "go/scanner";
+ "io";
+ "os";
+ pathutil "path";
+ "strings";
)
@@ -63,7 +63,7 @@ func ParseExpr(filename string, src interface{}) (ast.Expr, os.Error) {
var p parser;
p.init(filename, data, 0);
- x := p.parseExpr(); // TODO 6g bug - function call order in expr lists
+ x := p.parseExpr(); // TODO 6g bug - function call order in expr lists
return x, p.GetError(scanner.Sorted);
}
@@ -81,7 +81,7 @@ func ParseStmtList(filename string, src interface{}) ([]ast.Stmt, os.Error) {
var p parser;
p.init(filename, data, 0);
- list := p.parseStmtList(); // TODO 6g bug - function call order in expr lists
+ list := p.parseStmtList(); // TODO 6g bug - function call order in expr lists
return list, p.GetError(scanner.Sorted);
}
@@ -99,7 +99,7 @@ func ParseDeclList(filename string, src interface{}) ([]ast.Decl, os.Error) {
var p parser;
p.init(filename, data, 0);
- list := p.parseDeclList(); // TODO 6g bug - function call order in expr lists
+ list := p.parseDeclList(); // TODO 6g bug - function call order in expr lists
return list, p.GetError(scanner.Sorted);
}
@@ -130,7 +130,7 @@ func ParseFile(filename string, src interface{}, mode uint) (*ast.File, os.Error
var p parser;
p.init(filename, data, mode);
- prog := p.parseFile(); // TODO 6g bug - function call order in expr lists
+ prog := p.parseFile(); // TODO 6g bug - function call order in expr lists
return prog, p.GetError(scanner.NoMultiples);
}
@@ -158,7 +158,7 @@ func ParsePkgFile(pkgname, filename string, mode uint) (*ast.File, os.Error) {
}
// ignore flags that control partial parsing
- return ParseFile(filename, src, mode &^ (PackageClauseOnly | ImportsOnly));
+ return ParseFile(filename, src, mode&^(PackageClauseOnly | ImportsOnly));
}
diff --git a/src/pkg/go/parser/parser_test.go b/src/pkg/go/parser/parser_test.go
index bb07f2928..fc366bcc3 100644
--- a/src/pkg/go/parser/parser_test.go
+++ b/src/pkg/go/parser/parser_test.go
@@ -10,7 +10,7 @@ import (
)
-var illegalInputs = []interface{} {
+var illegalInputs = []interface{}{
nil,
3.14,
[]byte(nil),
@@ -28,7 +28,7 @@ func TestParseIllegalInputs(t *testing.T) {
}
-var validPrograms = []interface{} {
+var validPrograms = []interface{}{
`package main`,
`package main import "fmt" func main() { fmt.Println("Hello, World!") }`,
}
@@ -44,7 +44,7 @@ func TestParseValidPrograms(t *testing.T) {
}
-var validFiles = []string {
+var validFiles = []string{
"parser.go",
"parser_test.go",
}
diff --git a/src/pkg/go/scanner/errors.go b/src/pkg/go/scanner/errors.go
index fde211216..73429f1fa 100644
--- a/src/pkg/go/scanner/errors.go
+++ b/src/pkg/go/scanner/errors.go
@@ -63,8 +63,8 @@ func (h *ErrorVector) ErrorCount() int {
// token, and the error condition is described by Msg.
//
type Error struct {
- Pos token.Position;
- Msg string;
+ Pos token.Position;
+ Msg string;
}
@@ -83,11 +83,15 @@ type ErrorList []*Error
// ErrorList implements the SortInterface.
-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 {
+func (p ErrorList) Less(i, j int) bool {
e := &p[i].Pos;
f := &p[j].Pos;
// Note that it is not sufficient to simply compare file offsets because
@@ -115,7 +119,7 @@ func (p ErrorList) String() string {
case 1:
return p[0].String();
}
- return fmt.Sprintf("%s (and %d more errors)", p[0].String(), len(p) - 1);
+ return fmt.Sprintf("%s (and %d more errors)", p[0].String(), len(p)-1);
}
@@ -123,9 +127,9 @@ func (p ErrorList) String() string {
// returned by GetErrors.
//
const (
- Raw = iota; // leave error list unchanged
- Sorted; // sort error list by file, line, and column number
- NoMultiples; // sort error list and leave only the first error per line
+ Raw = iota; // leave error list unchanged
+ Sorted; // sort error list by file, line, and column number
+ NoMultiples; // sort error list and leave only the first error per line
)
@@ -148,7 +152,7 @@ func (h *ErrorVector) GetErrorList(mode int) ErrorList {
}
if mode >= NoMultiples {
- var last token.Position; // initial last.Line is != any legal error line
+ var last token.Position; // initial last.Line is != any legal error line
i := 0;
for _, e := range list {
if e.Pos.Filename != last.Filename || e.Pos.Line != last.Line {
@@ -157,7 +161,7 @@ func (h *ErrorVector) GetErrorList(mode int) ErrorList {
i++;
}
}
- list = list[0 : i];
+ list = list[0:i];
}
return list;
diff --git a/src/pkg/go/scanner/scanner.go b/src/pkg/go/scanner/scanner.go
index c4a5ad838..03899a428 100644
--- a/src/pkg/go/scanner/scanner.go
+++ b/src/pkg/go/scanner/scanner.go
@@ -24,17 +24,17 @@ import (
//
type Scanner struct {
// immutable state
- src []byte; // source
- err ErrorHandler; // error reporting; or nil
- mode uint; // scanning mode
+ src []byte; // source
+ err ErrorHandler; // error reporting; or nil
+ mode uint; // scanning mode
// scanning state
- pos token.Position; // previous reading position (position before ch)
- offset int; // current reading offset (position after ch)
- ch int; // one char look-ahead
+ pos token.Position; // previous reading position (position before ch)
+ offset int; // current reading offset (position after ch)
+ ch int; // one char look-ahead
// public state - ok to modify
- ErrorCount int; // number of errors encountered
+ ErrorCount int; // number of errors encountered
}
@@ -58,7 +58,7 @@ func (S *Scanner) next() {
S.ch = r;
} else {
S.pos.Offset = len(S.src);
- S.ch = -1; // eof
+ S.ch = -1; // eof
}
}
@@ -67,8 +67,8 @@ func (S *Scanner) next() {
// They control scanner behavior.
//
const (
- ScanComments = 1 << iota; // return comments as COMMENT tokens
- AllowIllegalChars; // do not report an error for illegal chars
+ ScanComments = 1<<iota; // return comments as COMMENT tokens
+ AllowIllegalChars; // do not report an error for illegal chars
)
@@ -95,17 +95,28 @@ func (S *Scanner) Init(filename string, src []byte, err ErrorHandler, mode uint)
func charString(ch int) string {
var s string;
switch ch {
- case -1: return `EOF`;
- case '\a': s = `\a`;
- case '\b': s = `\b`;
- case '\f': s = `\f`;
- case '\n': s = `\n`;
- case '\r': s = `\r`;
- case '\t': s = `\t`;
- case '\v': s = `\v`;
- case '\\': s = `\\`;
- case '\'': s = `\'`;
- default : s = string(ch);
+ case -1:
+ return `EOF`;
+ case '\a':
+ s = `\a`;
+ case '\b':
+ s = `\b`;
+ case '\f':
+ s = `\f`;
+ case '\n':
+ s = `\n`;
+ case '\r':
+ s = `\r`;
+ case '\t':
+ s = `\t`;
+ case '\v':
+ s = `\v`;
+ case '\\':
+ s = `\\`;
+ case '\'':
+ s = `\'`;
+ default:
+ s = string(ch);
}
return "'" + s + "' (U+" + strconv.Itob(ch, 16) + ")";
}
@@ -123,11 +134,11 @@ func (S *Scanner) expect(ch int) {
if S.ch != ch {
S.error(S.pos, "expected " + charString(ch) + ", found " + charString(S.ch));
}
- S.next(); // always make progress
+ S.next(); // always make progress
}
-var prefix = []byte{'l', 'i', 'n', 'e', ' '}; // "line "
+var prefix = []byte{'l', 'i', 'n', 'e', ' '} // "line "
func (S *Scanner) scanComment(pos token.Position) {
// first '/' already consumed
@@ -140,7 +151,7 @@ func (S *Scanner) scanComment(pos token.Position) {
// '\n' is not part of the comment
// (the comment ends on the same line where it started)
if pos.Column == 1 {
- text := S.src[pos.Offset+2 : S.pos.Offset];
+ text := S.src[pos.Offset + 2 : S.pos.Offset];
if bytes.HasPrefix(text, prefix) {
// comment starts at beginning of line with "//line ";
// get filename and line number, if any
@@ -149,7 +160,7 @@ func (S *Scanner) scanComment(pos token.Position) {
if line, err := strconv.Atoi(string(text[i+1 : len(text)])); err == nil && line > 0 {
// valid //line filename:line comment;
// update scanner position
- S.pos.Filename = string(text[len(prefix) : i]);
+ S.pos.Filename = string(text[len(prefix):i]);
S.pos.Line = line;
}
}
@@ -177,18 +188,12 @@ func (S *Scanner) scanComment(pos token.Position) {
func isLetter(ch int) bool {
- return
- 'a' <= ch && ch <= 'z' ||
- 'A' <= ch && ch <= 'Z' ||
- ch == '_' ||
- ch >= 0x80 && unicode.IsLetter(ch);
+ return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= 0x80 && unicode.IsLetter(ch);
}
func isDigit(ch int) bool {
- return
- '0' <= ch && ch <= '9' ||
- ch >= 0x80 && unicode.IsDigit(ch);
+ return '0' <= ch && ch <= '9' || ch >= 0x80 && unicode.IsDigit(ch);
}
@@ -203,11 +208,14 @@ func (S *Scanner) scanIdentifier() token.Token {
func digitVal(ch int) int {
switch {
- case '0' <= ch && ch <= '9': return ch - '0';
- case 'a' <= ch && ch <= 'f': return ch - 'a' + 10;
- case 'A' <= ch && ch <= 'F': return ch - 'A' + 10;
+ case '0' <= ch && ch <= '9':
+ return ch-'0';
+ case 'a' <= ch && ch <= 'f':
+ return ch-'a'+10;
+ case 'A' <= ch && ch <= 'F':
+ return ch-'A'+10;
}
- return 16; // larger than any legal digit val
+ return 16; // larger than any legal digit val
}
@@ -242,7 +250,7 @@ func (S *Scanner) scanNumber(seen_decimal_point bool) token.Token {
tok = token.FLOAT;
goto mantissa;
}
- // octal int
+ // octal int
}
goto exit;
}
@@ -255,7 +263,7 @@ mantissa:
// float
tok = token.FLOAT;
S.next();
- S.scanMantissa(10)
+ S.scanMantissa(10);
}
exponent:
@@ -291,9 +299,9 @@ func (S *Scanner) scanEscape(quote int) {
S.next();
switch ch {
case 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', quote:
- // nothing to do
+ // nothing to do
case '0', '1', '2', '3', '4', '5', '6', '7':
- S.scanDigits(8, 3 - 1); // 1 char read already
+ S.scanDigits(8, 3-1); // 1 char read already
case 'x':
S.scanDigits(16, 2);
case 'u':
@@ -440,14 +448,22 @@ scan_again:
case digitVal(ch) < 10:
tok = S.scanNumber(false);
default:
- S.next(); // always make progress
+ S.next(); // always make progress
switch ch {
- case -1 : tok = token.EOF;
- case '"' : tok = token.STRING; S.scanString(pos);
- case '\'': tok = token.CHAR; S.scanChar(pos);
- case '`' : tok = token.STRING; S.scanRawString(pos);
- case ':' : tok = S.switch2(token.COLON, token.DEFINE);
- case '.' :
+ case -1:
+ tok = token.EOF;
+ case '"':
+ tok = token.STRING;
+ S.scanString(pos);
+ case '\'':
+ tok = token.CHAR;
+ S.scanChar(pos);
+ case '`':
+ tok = token.STRING;
+ S.scanRawString(pos);
+ case ':':
+ tok = S.switch2(token.COLON, token.DEFINE);
+ case '.':
if digitVal(S.ch) < 10 {
tok = S.scanNumber(true);
} else if S.ch == '.' {
@@ -459,17 +475,28 @@ scan_again:
} else {
tok = token.PERIOD;
}
- case ',': tok = token.COMMA;
- case ';': tok = token.SEMICOLON;
- case '(': tok = token.LPAREN;
- case ')': tok = token.RPAREN;
- case '[': tok = token.LBRACK;
- case ']': tok = token.RBRACK;
- case '{': tok = token.LBRACE;
- case '}': tok = token.RBRACE;
- case '+': tok = S.switch3(token.ADD, token.ADD_ASSIGN, '+', token.INC);
- case '-': tok = S.switch3(token.SUB, token.SUB_ASSIGN, '-', token.DEC);
- case '*': tok = S.switch2(token.MUL, token.MUL_ASSIGN);
+ case ',':
+ tok = token.COMMA;
+ case ';':
+ tok = token.SEMICOLON;
+ case '(':
+ tok = token.LPAREN;
+ case ')':
+ tok = token.RPAREN;
+ case '[':
+ tok = token.LBRACK;
+ case ']':
+ tok = token.RBRACK;
+ case '{':
+ tok = token.LBRACE;
+ case '}':
+ tok = token.RBRACE;
+ case '+':
+ tok = S.switch3(token.ADD, token.ADD_ASSIGN, '+', token.INC);
+ case '-':
+ tok = S.switch3(token.SUB, token.SUB_ASSIGN, '-', token.DEC);
+ case '*':
+ tok = S.switch2(token.MUL, token.MUL_ASSIGN);
case '/':
if S.ch == '/' || S.ch == '*' {
S.scanComment(pos);
@@ -480,8 +507,10 @@ scan_again:
} else {
tok = S.switch2(token.QUO, token.QUO_ASSIGN);
}
- case '%': tok = S.switch2(token.REM, token.REM_ASSIGN);
- case '^': tok = S.switch2(token.XOR, token.XOR_ASSIGN);
+ case '%':
+ tok = S.switch2(token.REM, token.REM_ASSIGN);
+ case '^':
+ tok = S.switch2(token.XOR, token.XOR_ASSIGN);
case '<':
if S.ch == '-' {
S.next();
@@ -489,9 +518,12 @@ scan_again:
} else {
tok = S.switch4(token.LSS, token.LEQ, '<', token.SHL, token.SHL_ASSIGN);
}
- case '>': tok = S.switch4(token.GTR, token.GEQ, '>', token.SHR, token.SHR_ASSIGN);
- case '=': tok = S.switch2(token.ASSIGN, token.EQL);
- case '!': tok = S.switch2(token.NOT, token.NEQ);
+ case '>':
+ tok = S.switch4(token.GTR, token.GEQ, '>', token.SHR, token.SHR_ASSIGN);
+ case '=':
+ tok = S.switch2(token.ASSIGN, token.EQL);
+ case '!':
+ tok = S.switch2(token.NOT, token.NEQ);
case '&':
if S.ch == '^' {
S.next();
@@ -499,7 +531,8 @@ scan_again:
} else {
tok = S.switch3(token.AND, token.AND_ASSIGN, '&', token.LAND);
}
- case '|': tok = S.switch3(token.OR, token.OR_ASSIGN, '|', token.LOR);
+ case '|':
+ tok = S.switch3(token.OR, token.OR_ASSIGN, '|', token.LOR);
default:
if S.mode & AllowIllegalChars == 0 {
S.error(pos, "illegal character " + charString(ch));
@@ -517,11 +550,11 @@ scan_again:
// false (usually when the token value is token.EOF). The result is the number
// of errors encountered.
//
-func Tokenize(filename string, src []byte, err ErrorHandler, mode uint, f func (pos token.Position, tok token.Token, lit []byte) bool) int {
+func Tokenize(filename string, src []byte, err ErrorHandler, mode uint, f func(pos token.Position, tok token.Token, lit []byte) bool) int {
var s Scanner;
s.Init(filename, src, err, mode);
for f(s.Scan()) {
- // action happens in f
+ // action happens in f
}
return s.ErrorCount;
}