diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-04-26 09:55:32 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-04-26 09:55:32 +0200 |
commit | 7b15ed9ef455b6b66c6b376898a88aef5d6a9970 (patch) | |
tree | 3ef530baa80cdf29436ba981f5783be6b4d2202b /src/pkg/scanner/scanner.go | |
parent | 50104cc32a498f7517a51c8dc93106c51c7a54b4 (diff) | |
download | golang-7b15ed9ef455b6b66c6b376898a88aef5d6a9970.tar.gz |
Imported Upstream version 2011.04.13upstream/2011.04.13
Diffstat (limited to 'src/pkg/scanner/scanner.go')
-rw-r--r-- | src/pkg/scanner/scanner.go | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/src/pkg/scanner/scanner.go b/src/pkg/scanner/scanner.go index 2396cdd9a..ec2266477 100644 --- a/src/pkg/scanner/scanner.go +++ b/src/pkg/scanner/scanner.go @@ -115,7 +115,7 @@ func TokenString(tok int) string { if s, found := tokenString[tok]; found { return s } - return fmt.Sprintf("U+%04X", tok) + return fmt.Sprintf("%q", string(tok)) } @@ -331,7 +331,7 @@ func (s *Scanner) error(msg string) { s.Error(s, msg) return } - fmt.Fprintf(os.Stderr, "%s: %s", s.Position, msg) + fmt.Fprintf(os.Stderr, "%s: %s\n", s.Position, msg) } @@ -503,41 +503,32 @@ func (s *Scanner) scanChar() { } -func (s *Scanner) scanLineComment() { - ch := s.next() // read character after "//" - for ch != '\n' { - if ch < 0 { - s.error("comment not terminated") - return +func (s *Scanner) scanComment(ch int) int { + // ch == '/' || ch == '*' + if ch == '/' { + // line comment + ch = s.next() // read character after "//" + for ch != '\n' && ch >= 0 { + ch = s.next() } - ch = s.next() + return ch } -} - -func (s *Scanner) scanGeneralComment() { - ch := s.next() // read character after "/*" + // general comment + ch = s.next() // read character after "/*" for { if ch < 0 { s.error("comment not terminated") - return + break } ch0 := ch ch = s.next() if ch0 == '*' && ch == '/' { + ch = s.next() break } } -} - - -func (s *Scanner) scanComment(ch int) { - // ch == '/' || ch == '*' - if ch == '/' { - s.scanLineComment() - return - } - s.scanGeneralComment() + return ch } @@ -619,13 +610,11 @@ redo: if (ch == '/' || ch == '*') && s.Mode&ScanComments != 0 { if s.Mode&SkipComments != 0 { s.tokPos = -1 // don't collect token text - s.scanComment(ch) - ch = s.next() + ch = s.scanComment(ch) goto redo } - s.scanComment(ch) + ch = s.scanComment(ch) tok = Comment - ch = s.next() } case '`': if s.Mode&ScanRawStrings != 0 { |