ScanComment scans the input as a comment.
(lval ScanSymType)
| 550 | |
| 551 | // ScanComment scans the input as a comment. |
| 552 | func (s *Scanner) ScanComment(lval ScanSymType) (present, ok bool) { |
| 553 | start := s.pos |
| 554 | ch := s.peek() |
| 555 | |
| 556 | if ch == '/' { |
| 557 | s.pos++ |
| 558 | if s.peek() != '*' { |
| 559 | s.pos-- |
| 560 | return false, true |
| 561 | } |
| 562 | s.pos++ |
| 563 | depth := 1 |
| 564 | for { |
| 565 | switch s.next() { |
| 566 | case '*': |
| 567 | if s.peek() == '/' { |
| 568 | s.pos++ |
| 569 | depth-- |
| 570 | if depth == 0 { |
| 571 | return true, true |
| 572 | } |
| 573 | continue |
| 574 | } |
| 575 | |
| 576 | case '/': |
| 577 | if s.peek() == '*' { |
| 578 | s.pos++ |
| 579 | depth++ |
| 580 | continue |
| 581 | } |
| 582 | |
| 583 | case eof: |
| 584 | lval.SetID(lexbase.ERROR) |
| 585 | lval.SetPos(int32(start)) |
| 586 | lval.SetStr("unterminated comment") |
| 587 | return false, false |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | if ch == '-' { |
| 593 | s.pos++ |
| 594 | if s.peek() != '-' { |
| 595 | s.pos-- |
| 596 | return false, true |
| 597 | } |
| 598 | for { |
| 599 | switch s.next() { |
| 600 | case eof, '\n': |
| 601 | return true, true |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | return false, true |
| 607 | } |
| 608 | |
| 609 | // normalizeIdent takes in a function that determines if a character is a legal |