]> Cypherpunks repositories - gostls13.git/commitdiff
go/scanner: added another test case, clarified some code
authorRobert Griesemer <gri@golang.org>
Fri, 29 Oct 2010 22:07:04 +0000 (15:07 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 29 Oct 2010 22:07:04 +0000 (15:07 -0700)
R=rsc
CC=golang-dev
https://golang.org/cl/2741042

src/pkg/go/scanner/scanner.go
src/pkg/go/scanner/scanner_test.go

index 81d3f1ae9d9f2ae77d24bd06090c1433b393fbc6..f38c0252c3d6323e12f7f52ad2fcc3d14749f4a5 100644 (file)
@@ -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
 }
index e2ffb1e0cf60dae14cb48fb631a3770ec1c66b7b..480502e3fbb55d304d60af7e5462942a62d8b681 100644 (file)
@@ -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$",
 }