summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Clements <aclements@csail.mit.edu>2009-07-30 16:58:19 -0700
committerAustin Clements <aclements@csail.mit.edu>2009-07-30 16:58:19 -0700
commite383d220bd4e700a329ac87dd8ff3fc14eb3e545 (patch)
tree48be18906a57eed3291b9c905275afed0048fb2e
parent775a36ebf074ae48e5db28d257a7eaa9d1407955 (diff)
downloadgolang-e383d220bd4e700a329ac87dd8ff3fc14eb3e545.tar.gz
String method for token.Position. Extracted from gri's tree.
R=gri APPROVED=gri DELTA=33 (20 added, 6 deleted, 7 changed) OCL=32544 CL=32546
-rw-r--r--src/pkg/Make.deps4
-rw-r--r--src/pkg/go/scanner/errors.go15
-rw-r--r--src/pkg/go/token/token.go21
3 files changed, 27 insertions, 13 deletions
diff --git a/src/pkg/Make.deps b/src/pkg/Make.deps
index 9508ad946..68c6c9f57 100644
--- a/src/pkg/Make.deps
+++ b/src/pkg/Make.deps
@@ -24,7 +24,7 @@ go/doc.install: container/vector.install fmt.install go/ast.install go/token.ins
go/parser.install: bytes.install container/vector.install fmt.install go/ast.install go/scanner.install go/token.install io.install os.install path.install strings.install
go/printer.install: fmt.install go/ast.install go/token.install io.install os.install reflect.install strings.install
go/scanner.install: bytes.install container/vector.install fmt.install go/token.install io.install os.install sort.install strconv.install unicode.install utf8.install
-go/token.install: strconv.install
+go/token.install: fmt.install strconv.install
gob.install: bytes.install fmt.install io.install math.install os.install reflect.install strings.install sync.install unicode.install
hash.install: io.install
hash/adler32.install: hash.install os.install
@@ -42,7 +42,7 @@ path.install: strings.install
rand.install:
reflect.install: runtime.install strconv.install strings.install
regexp.install: bytes.install container/vector.install io.install os.install runtime.install utf8.install
-rpc.install: bufio.install gob.install http.install io.install log.install net.install os.install reflect.install strconv.install strings.install sync.install unicode.install utf8.install
+rpc.install: bufio.install fmt.install gob.install http.install io.install log.install net.install os.install reflect.install sort.install strconv.install strings.install sync.install template.install unicode.install utf8.install
runtime.install:
sort.install:
strconv.install: bytes.install math.install os.install utf8.install
diff --git a/src/pkg/go/scanner/errors.go b/src/pkg/go/scanner/errors.go
index 54770f020..fde211216 100644
--- a/src/pkg/go/scanner/errors.go
+++ b/src/pkg/go/scanner/errors.go
@@ -69,17 +69,12 @@ type Error struct {
func (e *Error) String() string {
- s := e.Pos.Filename;
- if s != "" {
- s += ":";
+ if e.Pos.Filename != "" || e.Pos.IsValid() {
+ // don't print "<unknown position>"
+ // TODO(gri) reconsider the semantics of Position.IsValid
+ return e.Pos.String() + ": " + e.Msg;
}
- if e.Pos.IsValid() {
- s += fmt.Sprintf("%d:%d:", e.Pos.Line, e.Pos.Column);
- }
- if s != "" {
- s += " ";
- }
- return s + e.Msg;
+ return e.Msg;
}
diff --git a/src/pkg/go/token/token.go b/src/pkg/go/token/token.go
index f165d1978..61a0c622c 100644
--- a/src/pkg/go/token/token.go
+++ b/src/pkg/go/token/token.go
@@ -8,7 +8,11 @@
//
package token
-import "strconv"
+import (
+ "fmt";
+ "strconv";
+)
+
// Token is the set of lexical tokens of the Go programming language.
type Token int
@@ -346,3 +350,18 @@ func (pos *Position) Pos() Position {
func (pos *Position) IsValid() bool {
return pos.Line > 0
}
+
+
+func (pos *Position) String() string {
+ s := pos.Filename;
+ if pos.IsValid() {
+ if s != "" {
+ s += ":";
+ }
+ s += fmt.Sprintf("%d:%d", pos.Line, pos.Column);
+ }
+ if s != "" {
+ return s;
+ }
+ return "<unknown position>";
+}