s.Error(s, msg)
return
}
- fmt.Fprintf(os.Stderr, "%s: %s", s.Position, msg)
+ fmt.Fprintf(os.Stderr, "%s: %s\n", s.Position, msg)
}
}
-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
}
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 {