Scan scans the tokenizer for the next token and returns the token type and an optional value.
()
| 723 | // Scan scans the tokenizer for the next token and returns |
| 724 | // the token type and an optional value. |
| 725 | func (tkn *Tokenizer) Scan() (int, string) { |
| 726 | if tkn.specialComment != nil { |
| 727 | // Enter specialComment scan mode. |
| 728 | // for scanning such kind of comment: /*! MySQL-specific code */ |
| 729 | specialComment := tkn.specialComment |
| 730 | tok, val := specialComment.Scan() |
| 731 | if tok != 0 { |
| 732 | // return the specialComment scan result as the result |
| 733 | return tok, val |
| 734 | } |
| 735 | // leave specialComment scan mode after all stream consumed. |
| 736 | tkn.specialComment = nil |
| 737 | } |
| 738 | if tkn.lastChar == 0 { |
| 739 | tkn.next() |
| 740 | } |
| 741 | |
| 742 | tkn.skipBlank() |
| 743 | switch ch := tkn.lastChar; { |
| 744 | case isIdentifierFirstChar(ch): |
| 745 | tkn.next() |
| 746 | if ch == 'X' || ch == 'x' { |
| 747 | if tkn.lastChar == '\'' { |
| 748 | tkn.next() |
| 749 | return tkn.scanHex() |
| 750 | } |
| 751 | } |
| 752 | if ch == 'B' || ch == 'b' { |
| 753 | if tkn.lastChar == '\'' { |
| 754 | tkn.next() |
| 755 | return tkn.scanBitLiteral() |
| 756 | } |
| 757 | } |
| 758 | if ch == 'N' { |
| 759 | if tkn.lastChar == '\'' { |
| 760 | if tkn.mode == ParserModeMssql { |
| 761 | tkn.next() |
| 762 | return tkn.scanString('\'', UNICODE_STRING) |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | isDbSystemVariable := false |
| 767 | if ch == '@' && tkn.lastChar == '@' { |
| 768 | isDbSystemVariable = true |
| 769 | } |
| 770 | return tkn.scanIdentifier(ch, isDbSystemVariable) |
| 771 | case isAsciiDigit(ch): |
| 772 | return tkn.scanNumber(false) |
| 773 | case ch == ':': |
| 774 | return tkn.scanBindVar() |
| 775 | case ch == ';' && tkn.multi: |
| 776 | return 0, "" |
| 777 | default: |
| 778 | tkn.next() |
| 779 | switch ch { |
| 780 | case eofChar: |
| 781 | return 0, "" |
| 782 | case '=', ',', ';', '(', ')', '[', ']', '+', '*', '%', '^', '~': |