@@ -8,21 +8,21 @@ import { TokenSource, Token, CharStream, TokenFactory, CommonToken } from "antlr
88 *
99 * It is designed to be used to find the correct token index at
1010 * any string location, regardless of the validity of the SQL string.
11- * See SQLSurveyer .getTokenIndexAt for usage.
11+ * See SQLAutocomplete .getTokenIndexAt for usage.
1212 */
1313export class SimpleSQLTokenizer implements TokenSource {
1414
1515 value : string ;
16- currentIndex : number ;
17- insideQuote : boolean ;
16+ _currentIndex : number ;
17+ _insideQuote : boolean ;
1818
1919 specialCharacters : string [ ] = [ ';' , '.' , '(' , ')' ] ;
2020 whitespaceCharacters : string [ ] = [ ' ' , '\f' , '\n' , '\r' , '\t' , '\v' , '\u00A0' , '\u2028' , '\u2029' ] ;
2121
2222 constructor ( value : string , tokenizeWhitespace : boolean ) {
2323 this . value = value ;
24- this . currentIndex = 0 ;
25- this . insideQuote = false ;
24+ this . _currentIndex = 0 ;
25+ this . _insideQuote = false ;
2626 if ( tokenizeWhitespace ) {
2727 this . specialCharacters . push ( ...this . whitespaceCharacters ) ;
2828 }
@@ -32,35 +32,35 @@ export class SimpleSQLTokenizer implements TokenSource {
3232 let start = null ;
3333 let stop = null ;
3434 const notWhitespaceRegex = / [ ^ \s ] / ;
35- while ( this . currentIndex < this . value . length ) {
36- const currentChar = this . value [ this . currentIndex ] ;
37- if ( currentChar === "'" && this . value [ this . currentIndex - 1 ] !== '\\' ) {
38- this . insideQuote = ! this . insideQuote ;
35+ while ( this . _currentIndex < this . value . length ) {
36+ const currentChar = this . value [ this . _currentIndex ] ;
37+ if ( currentChar === "'" && this . value [ this . _currentIndex - 1 ] !== '\\' ) {
38+ this . _insideQuote = ! this . _insideQuote ;
3939 }
40- if ( ( notWhitespaceRegex . test ( currentChar ) && ! this . specialCharacters . includes ( currentChar ) ) || this . insideQuote ) {
40+ if ( ( notWhitespaceRegex . test ( currentChar ) && ! this . specialCharacters . includes ( currentChar ) ) || this . _insideQuote ) {
4141 if ( start === null ) {
42- start = this . currentIndex ;
42+ start = this . _currentIndex ;
4343 }
44- if ( this . currentIndex === this . value . length - 1 ) {
45- stop = this . currentIndex ;
44+ if ( this . _currentIndex === this . value . length - 1 ) {
45+ stop = this . _currentIndex ;
4646 }
4747 } else if ( start !== null ) {
48- stop = this . currentIndex - 1 ;
48+ stop = this . _currentIndex - 1 ;
4949 if ( this . specialCharacters . includes ( currentChar ) ) {
5050 // The next block will iterate past the current special character
5151 // Need to back up so that on the next call to nextToken, the special character will be identified again
52- this . currentIndex -- ;
52+ this . _currentIndex -- ;
5353 }
5454 }
5555 if ( start !== null && stop !== null ) {
56- this . currentIndex ++ ;
56+ this . _currentIndex ++ ;
5757 return new CommonToken ( Token . DEFAULT_CHANNEL , this . value . substring ( start , stop + 1 ) , { } , null , start , stop ) ;
5858 }
59- if ( this . specialCharacters . includes ( currentChar ) && ! this . insideQuote ) {
60- this . currentIndex ++ ;
61- return new CommonToken ( Token . DEFAULT_CHANNEL , currentChar , { } , null , this . currentIndex - 1 , this . currentIndex - 1 ) ;
59+ if ( this . specialCharacters . includes ( currentChar ) && ! this . _insideQuote ) {
60+ this . _currentIndex ++ ;
61+ return new CommonToken ( Token . DEFAULT_CHANNEL , currentChar , { } , null , this . _currentIndex - 1 , this . _currentIndex - 1 ) ;
6262 }
63- this . currentIndex ++ ;
63+ this . _currentIndex ++ ;
6464 }
6565 return new CommonToken ( Token . EOF ) ;
6666 }
0 commit comments