scanComment scans for a comment starting at the current position. For block-style comments, returns the comment string scanned. For line-style comments, returns an empty string. In either case, also returns whether a comment was present, and whether scanning succeeded.
(lval *sqlSymType)
| 483 | // For line-style comments, returns an empty string. |
| 484 | // In either case, also returns whether a comment was present, and whether scanning succeeded. |
| 485 | func (s *scanner) scanComment(lval *sqlSymType) (comment string, present, ok bool) { |
| 486 | start := s.pos |
| 487 | ch := s.peek() |
| 488 | |
| 489 | if ch == '/' { |
| 490 | sb := strings.Builder{} |
| 491 | sb.WriteRune('/') |
| 492 | |
| 493 | s.pos++ |
| 494 | if s.peek() != '*' { |
| 495 | s.pos-- |
| 496 | return "", false, true |
| 497 | } |
| 498 | sb.WriteRune('*') |
| 499 | |
| 500 | s.pos++ |
| 501 | depth := 1 |
| 502 | for { |
| 503 | next := s.next() |
| 504 | sb.WriteRune(rune(next)) |
| 505 | |
| 506 | switch next { |
| 507 | case '*': |
| 508 | if s.peek() == '/' { |
| 509 | s.pos++ |
| 510 | depth-- |
| 511 | sb.WriteRune(rune('/')) |
| 512 | |
| 513 | if depth == 0 { |
| 514 | return sb.String(), true, true |
| 515 | } |
| 516 | continue |
| 517 | } |
| 518 | |
| 519 | case '/': |
| 520 | if s.peek() == '*' { |
| 521 | s.pos++ |
| 522 | depth++ |
| 523 | sb.WriteRune(rune('*')) |
| 524 | continue |
| 525 | } |
| 526 | |
| 527 | case eof: |
| 528 | lval.id = ERROR |
| 529 | lval.pos = int32(start) |
| 530 | lval.str = "unterminated comment" |
| 531 | return "", false, false |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | if ch == '-' { |
| 537 | s.pos++ |
| 538 | if s.peek() != '-' { |
| 539 | s.pos-- |
| 540 | return "", false, true |
| 541 | } |
| 542 | for { |
no test coverage detected