aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/source.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2017-03-09 13:38:10 -0800
committerRobert Griesemer <gri@golang.org>2017-03-09 23:28:48 +0000
commit1f9f0ea32b2dcee027b107f2c3d0bc723274a810 (patch)
tree1c3d499526e0ab668b714ebc2cb0ac1ed76fb7dc /src/cmd/compile/internal/syntax/source.go
parentbfc164c64d33edfaf774b5c29b9bf5648a6447fb (diff)
downloadgo-1f9f0ea32b2dcee027b107f2c3d0bc723274a810.tar.gz
go-1f9f0ea32b2dcee027b107f2c3d0bc723274a810.zip
cmd/compile/internal/syntax: start line offset (column) numbers at 1
We could leave it alone and fix line offset (column) numbers when reporting errors, but that is likely to cause confusion (internal numbers don't match reported numbers). Instead, switch to default numbering starting at 1. For package syntax-internal use only, introduced constants defining the line and column bases, and use them throughout the code and its tests. It is possible to change these constants and package syntax will continue to work. But changing them is going to break any client that makes explicit assumptions about line and column numbers (which is "all of them"). Change-Id: Ia3d136a8ec8d9372ed9c05ca47d3dff222cf030e Reviewed-on: https://go-review.googlesource.com/37996 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/source.go')
-rw-r--r--src/cmd/compile/internal/syntax/source.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/syntax/source.go b/src/cmd/compile/internal/syntax/source.go
index 4ce35a3615..93547213c0 100644
--- a/src/cmd/compile/internal/syntax/source.go
+++ b/src/cmd/compile/internal/syntax/source.go
@@ -18,6 +18,10 @@ import (
"unicode/utf8"
)
+// starting points for line and column numbers
+const linebase = 1
+const colbase = 1
+
// buf [...read...|...|...unread...|s|...free...]
// ^ ^ ^ ^
// | | | |
@@ -49,8 +53,8 @@ func (s *source) init(src io.Reader, errh func(line, pos uint, msg string)) {
s.buf[0] = utf8.RuneSelf // terminate with sentinel
s.offs = 0
s.r0, s.r, s.w = 0, 0, 0
- s.line0, s.line = 1, 1
- s.col0, s.col = 0, 0
+ s.line0, s.line = 0, linebase
+ s.col0, s.col = 0, colbase
s.ioerr = nil
s.lit = s.lit[:0]
@@ -112,7 +116,7 @@ redo:
}
if b == '\n' {
s.line++
- s.col = 0
+ s.col = colbase
}
return rune(b)
}