aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2010-10-29 15:07:04 -0700
committerRobert Griesemer <gri@golang.org>2010-10-29 15:07:04 -0700
commit907e998cba8a5313639d020040f24ac6b4bc1baa (patch)
treef74922d54b92486280ec64d6ee9c6b3798733644
parent11684680fa66f82b474e617be58368a97fa02a36 (diff)
downloadgo-907e998cba8a5313639d020040f24ac6b4bc1baa.tar.gz
go-907e998cba8a5313639d020040f24ac6b4bc1baa.zip
go/scanner: added another test case, clarified some code
R=rsc CC=golang-dev https://golang.org/cl/2741042
-rw-r--r--src/pkg/go/scanner/scanner.go12
-rw-r--r--src/pkg/go/scanner/scanner_test.go3
2 files changed, 7 insertions, 8 deletions
diff --git a/src/pkg/go/scanner/scanner.go b/src/pkg/go/scanner/scanner.go
index 81d3f1ae9d..f38c0252c3 100644
--- a/src/pkg/go/scanner/scanner.go
+++ b/src/pkg/go/scanner/scanner.go
@@ -197,11 +197,11 @@ func (S *Scanner) scanComment(pos token.Position) {
func (S *Scanner) findLineEnd(pos token.Position) bool {
- // first '/' already consumed; assume S.ch == '/' || S.ch == '*'
+ // initial '/' already consumed; pos is position of '/'
// read ahead until a newline, EOF, or non-comment token is found
lineend := false
- for pos1 := pos; S.ch >= 0; {
+ for pos1 := pos; S.ch == '/' || S.ch == '*'; {
if S.ch == '/' {
//-style comment always contains a newline
lineend = true
@@ -224,17 +224,13 @@ func (S *Scanner) findLineEnd(pos token.Position) bool {
break
}
pos1 = S.pos
- S.next()
- if S.ch != '/' && S.ch != '*' {
- // non-comment token
- break
- }
+ S.next() // consume '/'
}
// reset position to where it was upon calling findLineEnd
S.pos = pos
S.offset = pos.Offset + 1
- S.next()
+ S.next() // consume initial '/' again
return lineend
}
diff --git a/src/pkg/go/scanner/scanner_test.go b/src/pkg/go/scanner/scanner_test.go
index e2ffb1e0cf..480502e3fb 100644
--- a/src/pkg/go/scanner/scanner_test.go
+++ b/src/pkg/go/scanner/scanner_test.go
@@ -407,8 +407,11 @@ var lines = []string{
"foo $/*comment*/ \n",
"foo $/*0*/ /*1*/ /*2*/ \n",
"foo $/**/ /*-------------*/ /*----\n*/bar $/* \n*/baa$\n",
+ "foo $/* an EOF terminates a line */",
+ "foo $/* an EOF terminates a line *//*",
"package main$\n\nfunc main() {\n\tif {\n\t\treturn /* */ }$\n}$\n",
+ "package main$",
}