summaryrefslogtreecommitdiff
path: root/src/pkg/go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/go')
-rw-r--r--src/pkg/go/scanner/errors.go15
-rw-r--r--src/pkg/go/token/token.go21
2 files changed, 25 insertions, 11 deletions
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>";
+}