Commit 9717a794 authored by Austin Clements's avatar Austin Clements

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
parent 07a497fe
......@@ -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
......
......@@ -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;
}
......
......@@ -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>";
}
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