Index: src/pkg/go/scanner/scanner.go |
=================================================================== |
--- a/src/pkg/go/scanner/scanner.go |
+++ b/src/pkg/go/scanner/scanner.go |
@@ -157,11 +157,15 @@ |
func (s *Scanner) scanComment() string { |
// initial '/' already consumed; s.ch == '/' || s.ch == '*' |
offs := s.offset - 1 // position of initial '/' |
+ hasCR := false |
if s.ch == '/' { |
//-style comment |
s.next() |
for s.ch != '\n' && s.ch >= 0 { |
+ if s.ch == '\r' { |
+ hasCR = true |
+ } |
s.next() |
} |
if offs == s.lineOffset { |
@@ -175,6 +179,9 @@ |
s.next() |
for s.ch >= 0 { |
ch := s.ch |
+ if ch == '\r' { |
+ hasCR = true |
+ } |
s.next() |
if ch == '*' && s.ch == '/' { |
s.next() |
@@ -185,7 +192,12 @@ |
s.error(offs, "comment not terminated") |
exit: |
- return string(s.src[offs:s.offset]) |
+ lit := s.src[offs:s.offset] |
+ if hasCR { |
+ lit = stripCR(lit) |
+ } |
+ |
+ return string(lit) |
} |
func (s *Scanner) findLineEnd() bool { |
@@ -527,6 +539,8 @@ |
// token.IMAG, token.CHAR, token.STRING) or token.COMMENT, the literal string |
// has the corresponding value. |
// |
+// If the returned token is a keyword, the literal string is the keyword. |
+// |
// If the returned token is token.SEMICOLON, the corresponding |
// literal string is ";" if the semicolon was present in the source, |
// and "\n" if the semicolon was inserted because of a newline or |