11/**
2- * jsql-official - v3.0.1
2+ * jsql-official - v3.0.2
33 * A persistent SQL database.
44 * @author Rob Parham
55 * @website http://pamblam.github.io/jSQL/
@@ -1076,36 +1076,26 @@ function jSQLLexer(input) {
10761076 this . token_matches = [ ] ;
10771077}
10781078
1079- jSQLLexer . prototype . getTokenMatches = function ( ) {
1080- if ( this . token_matches . length ) return this . token_matches ;
1081- this . token_matches = [ ]
1079+ jSQLLexer . prototype . getNextToken = function ( ) {
10821080 var r ;
10831081 for ( var i = 0 ; i < jSQLLexer . token_types . length ; i ++ ) {
1084- this . token_matches [ i ] = [ ] ;
10851082 while ( ( r = jSQLLexer . token_types [ i ] . pattern . exec ( this . input ) ) != null ) {
1086- this . token_matches [ i ] . push ( r ) ;
1083+ if ( r . index !== this . pos ) continue ;
1084+ var token = new jSQLToken ( this . pos , r [ 0 ] , i ) ;
1085+ this . pos += token . length ;
1086+ return token ;
10871087 }
10881088 }
1089- return this . token_matches ;
1089+ return false ;
10901090} ;
10911091
10921092jSQLLexer . prototype . getTokens = function ( ) {
10931093 if ( this . tokens . length ) return this . tokens ;
1094- this . pos = 0 ;
1095- var matches = this . getTokenMatches ( ) ,
1096- throwaway = [ "COMMENT" , "WHITESPACE" ] ;
1097- for ( var type_id = 0 ; type_id < matches . length ; type_id ++ ) {
1098- if ( this . pos >= this . input . length ) break ;
1099- for ( var match_index = 0 ; match_index < matches [ type_id ] . length ; match_index ++ ) {
1100- var r = matches [ type_id ] [ match_index ] ;
1101- if ( r . index !== this . pos ) continue ;
1102- var token = new jSQLToken ( this . pos , r [ 0 ] , type_id ) ;
1103- this . pos += token . length ;
1104- if ( throwaway . indexOf ( token . type ) === - 1 ) this . tokens . push ( token ) ;
1105- type_id = - 1 ;
1106- break ;
1107- }
1108- }
1094+ this . pos = 0 ; this . tokens = [ ] ;
1095+ var throwaway = [ "COMMENT" , "WHITESPACE" ] , token ;
1096+ while ( ( token = this . getNextToken ( ) ) != false )
1097+ if ( throwaway . indexOf ( token . type ) === - 1 )
1098+ this . tokens . push ( token ) ;
11091099 if ( this . pos !== this . input . length ) {
11101100 var pos ;
11111101 if ( this . tokens . length ) {
@@ -2686,6 +2676,10 @@ function deleteFrom(tablename){
26862676}
26872677
26882678
2679+ function tokenize ( sql ) {
2680+ return new jSQLLexer ( sql ) . getTokens ( ) ;
2681+ }
2682+
26892683function jSQLReset ( ) {
26902684 jSQL . tables = { } ;
26912685 jSQL . commit ( ) ;
@@ -2707,7 +2701,7 @@ function removeQuotes(str){
27072701}
27082702
27092703return {
2710- version : "3.0.1 " ,
2704+ version : "3.0.2 " ,
27112705 tables : { } ,
27122706 query : jSQLParseQuery ,
27132707 createTable : createTable ,
@@ -2724,7 +2718,8 @@ return {
27242718 commit : persistenceManager . commit ,
27252719 rollback : persistenceManager . rollback ,
27262720 setApiPriority : persistenceManager . setApiPriority ,
2727- getApi : persistenceManager . getApi
2721+ getApi : persistenceManager . getApi ,
2722+ tokenize : tokenize
27282723} ;
27292724
27302725} ) ( ) ;
0 commit comments