msi: Remove redundant null checks before MSI_EvaluateCondition.
[wine] / dlls / msi / tokenize.c
1 /*
2 ** 2001 September 15
3 **
4 ** The author disclaims copyright to this source code.  In place of
5 ** a legal notice, here is a blessing:
6 **
7 **    May you do good and not evil.
8 **    May you find forgiveness for yourself and forgive others.
9 **    May you share freely, never taking more than you give.
10 **
11 *************************************************************************
12 ** An tokenizer for SQL
13 **
14 ** This file contains C code that splits an SQL input string up into
15 ** individual tokens and sends those tokens one-by-one over to the
16 ** parser for analysis.
17 */
18
19 #include <ctype.h>
20 #include <stdarg.h>
21 #include <stdlib.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wine/unicode.h"
26 #include "query.h"
27 #include "sql.tab.h"
28
29 /*
30 ** All the keywords of the SQL language are stored as in a hash
31 ** table composed of instances of the following structure.
32 */
33 typedef struct Keyword Keyword;
34 struct Keyword {
35   const WCHAR *zName;             /* The keyword name */
36   int tokenType;           /* The token value for this keyword */
37 };
38
39 #define MAX_TOKEN_LEN 11
40
41 static const WCHAR ABORT_W[] = { 'A','B','O','R','T',0 };
42 static const WCHAR AFTER_W[] = { 'A','F','T','E','R',0 };
43 static const WCHAR ALTER_W[] = { 'A','L','T','E','R',0 };
44 static const WCHAR ALL_W[] = { 'A','L','L',0 };
45 static const WCHAR AND_W[] = { 'A','N','D',0 };
46 static const WCHAR AS_W[] = { 'A','S',0 };
47 static const WCHAR ASC_W[] = { 'A','S','C',0 };
48 static const WCHAR BEFORE_W[] = { 'B','E','F','O','R','E',0 };
49 static const WCHAR BEGIN_W[] = { 'B','E','G','I','N','W',0 };
50 static const WCHAR BETWEEN_W[] = { 'B','E','T','W','E','E','N',0 };
51 static const WCHAR BY_W[] = { 'B','Y',0 };
52 static const WCHAR CASCADE_W[] = { 'C','A','S','C','A','D','E',0 };
53 static const WCHAR CASE_W[] = { 'C','A','S','E',0 };
54 static const WCHAR CHAR_W[] = { 'C','H','A','R',0 };
55 static const WCHAR CHARACTER_W[] = { 'C','H','A','R','A','C','T','E','R',0 };
56 static const WCHAR CHECK_W[] = { 'C','H','E','C','K',0 };
57 static const WCHAR CLUSTER_W[] = { 'C','L','U','S','T','E','R',0 };
58 static const WCHAR COLLATE_W[] = { 'C','O','L','L','A','T','E',0 };
59 static const WCHAR COMMIT_W[] = { 'C','O','M','M','I','T',0 };
60 static const WCHAR CONFLICT_W[] = { 'C','O','N','F','L','I','C','T',0 };
61 static const WCHAR CONSTRAINT_W[] = { 'C','O','N','S','T','R','A','I','N','T',0 };
62 static const WCHAR COPY_W[] = { 'C','O','P','Y',0 };
63 static const WCHAR CREATE_W[] = { 'C','R','E','A','T','E',0 };
64 static const WCHAR CROSS_W[] = { 'C','R','O','S','S',0 };
65 static const WCHAR DEFAULT_W[] = { 'D','E','F','A','U','L','T',0 };
66 static const WCHAR DEFERRED_W[] = { 'D','E','F','E','R','R','E','D',0 };
67 static const WCHAR DEFERRABLE_W[] = { 'D','E','F','E','R','R','A','B','L','E',0 };
68 static const WCHAR DELETE_W[] = { 'D','E','L','E','T','E',0 };
69 static const WCHAR DELIMITERS_W[] = { 'D','E','L','I','M','I','T','E','R','S',0 };
70 static const WCHAR DESC_W[] = { 'D','E','S','C',0 };
71 static const WCHAR DISTINCT_W[] = { 'D','I','S','T','I','N','C','T',0 };
72 static const WCHAR DROP_W[] = { 'D','R','O','P',0 };
73 static const WCHAR END_W[] = { 'E','N','D',0 };
74 static const WCHAR EACH_W[] = { 'E','A','C','H',0 };
75 static const WCHAR ELSE_W[] = { 'E','L','S','E',0 };
76 static const WCHAR EXCEPT_W[] = { 'E','X','C','E','P','T',0 };
77 static const WCHAR EXPLAIN_W[] = { 'E','X','P','L','A','I','N',0 };
78 static const WCHAR FAIL_W[] = { 'F','A','I','L',0 };
79 static const WCHAR FOR_W[] = { 'F','O','R',0 };
80 static const WCHAR FOREIGN_W[] = { 'F','O','R','E','I','G','N',0 };
81 static const WCHAR FREE_W[] = { 'F','R','E','E',0 };
82 static const WCHAR FROM_W[] = { 'F','R','O','M',0 };
83 static const WCHAR FULL_W[] = { 'F','U','L','L',0 };
84 static const WCHAR GLOB_W[] = { 'G','L','O','B',0 };
85 static const WCHAR GROUP_W[] = { 'G','R','O','U','P',0 };
86 static const WCHAR HAVING_W[] = { 'H','A','V','I','N','G',0 };
87 static const WCHAR HOLD_W[] = { 'H','O','L','D',0 };
88 static const WCHAR IGNORE_W[] = { 'I','G','N','O','R','E',0 };
89 static const WCHAR IMMEDIATE_W[] = { 'I','M','M','E','D','I','A','T','E',0 };
90 static const WCHAR IN_W[] = { 'I','N',0 };
91 static const WCHAR INDEX_W[] = { 'I','N','D','E','X',0 };
92 static const WCHAR INITIALLY_W[] = { 'I','N','I','T','I','A','L','L','Y',0 };
93 static const WCHAR INNER_W[] = { 'I','N','N','E','R',0 };
94 static const WCHAR INSERT_W[] = { 'I','N','S','E','R','T',0 };
95 static const WCHAR INSTEAD_W[] = { 'I','N','S','T','E','A','D',0 };
96 static const WCHAR INT_W[] = { 'I','N','T',0 };
97 static const WCHAR INTEGER_W[] = { 'I','N','T','E','G','E','R',0 };
98 static const WCHAR INTERSECT_W[] = { 'I','N','T','E','R','S','E','C','T',0 };
99 static const WCHAR INTO_W[] = { 'I','N','T','O',0 };
100 static const WCHAR IS_W[] = { 'I','S',0 };
101 static const WCHAR ISNULL_W[] = { 'I','S','N','U','L','L',0 };
102 static const WCHAR JOIN_W[] = { 'J','O','I','N',0 };
103 static const WCHAR KEY_W[] = { 'K','E','Y',0 };
104 static const WCHAR LEFT_W[] = { 'L','E','F','T',0 };
105 static const WCHAR LIKE_W[] = { 'L','I','K','E',0 };
106 static const WCHAR LIMIT_W[] = { 'L','I','M','I','T',0 };
107 static const WCHAR LOCALIZABLE_W[] = { 'L','O','C','A','L','I','Z','A','B','L','E',0 };
108 static const WCHAR LONG_W[] = { 'L','O','N','G',0 };
109 static const WCHAR LONGCHAR_W[] = { 'L','O','N','G','C','H','A','R',0 };
110 static const WCHAR MATCH_W[] = { 'M','A','T','C','H',0 };
111 static const WCHAR NATURAL_W[] = { 'N','A','T','U','R','A','L',0 };
112 static const WCHAR NOT_W[] = { 'N','O','T',0 };
113 static const WCHAR NOTNULL_W[] = { 'N','O','T','N','U','L','L',0 };
114 static const WCHAR NULL_W[] = { 'N','U','L','L',0 };
115 static const WCHAR OBJECT_W[] = { 'O','B','J','E','C','T',0 };
116 static const WCHAR OF_W[] = { 'O','F',0 };
117 static const WCHAR OFFSET_W[] = { 'O','F','F','S','E','T',0 };
118 static const WCHAR ON_W[] = { 'O','N',0 };
119 static const WCHAR OR_W[] = { 'O','R',0 };
120 static const WCHAR ORDER_W[] = { 'O','R','D','E','R',0 };
121 static const WCHAR OUTER_W[] = { 'O','U','T','E','R',0 };
122 static const WCHAR PRAGMA_W[] = { 'P','R','A','G','M','A',0 };
123 static const WCHAR PRIMARY_W[] = { 'P','R','I','M','A','R','Y',0 };
124 static const WCHAR RAISE_W[] = { 'R','A','I','S','E',0 };
125 static const WCHAR REFERENCES_W[] = { 'R','E','F','E','R','E','N','C','E','S',0 };
126 static const WCHAR REPLACE_W[] = { 'R','E','P','L','A','C','E',0 };
127 static const WCHAR RESTRICT_W[] = { 'R','E','S','T','R','I','C','T',0 };
128 static const WCHAR RIGHT_W[] = { 'R','I','G','H','T',0 };
129 static const WCHAR ROLLBACK_W[] = { 'R','O','L','L','B','A','C','K',0 };
130 static const WCHAR ROW_W[] = { 'R','O','W',0 };
131 static const WCHAR SELECT_W[] = { 'S','E','L','E','C','T',0 };
132 static const WCHAR SET_W[] = { 'S','E','T',0 };
133 static const WCHAR SHORT_W[] = { 'S','H','O','R','T',0 };
134 static const WCHAR STATEMENT_W[] = { 'S','T','A','T','E','M','E','N','T',0 };
135 static const WCHAR TABLE_W[] = { 'T','A','B','L','E',0 };
136 static const WCHAR TEMP_W[] = { 'T','E','M','P',0 };
137 static const WCHAR TEMPORARY_W[] = { 'T','E','M','P','O','R','A','R','Y',0 };
138 static const WCHAR THEN_W[] = { 'T','H','E','N',0 };
139 static const WCHAR TRANSACTION_W[] = { 'T','R','A','N','S','A','C','T','I','O','N',0 };
140 static const WCHAR TRIGGER_W[] = { 'T','R','I','G','G','E','R',0 };
141 static const WCHAR UNION_W[] = { 'U','N','I','O','N',0 };
142 static const WCHAR UNIQUE_W[] = { 'U','N','I','Q','U','E',0 };
143 static const WCHAR UPDATE_W[] = { 'U','P','D','A','T','E',0 };
144 static const WCHAR USING_W[] = { 'U','S','I','N','G',0 };
145 static const WCHAR VACUUM_W[] = { 'V','A','C','U','U','M',0 };
146 static const WCHAR VALUES_W[] = { 'V','A','L','U','E','S',0 };
147 static const WCHAR VIEW_W[] = { 'V','I','E','W',0 };
148 static const WCHAR WHEN_W[] = { 'W','H','E','N',0 };
149 static const WCHAR WHERE_W[] = { 'W','H','E','R','E',0 };
150
151 /*
152 ** These are the keywords
153 */
154 static const Keyword aKeywordTable[] = {
155   { ABORT_W, TK_ABORT },
156   { AFTER_W, TK_AFTER },
157   { ALTER_W, TK_ALTER },
158   { ALL_W, TK_ALL },
159   { AND_W, TK_AND },
160   { AS_W, TK_AS },
161   { ASC_W, TK_ASC },
162   { BEFORE_W, TK_BEFORE },
163   { BEGIN_W, TK_BEGIN },
164   { BETWEEN_W, TK_BETWEEN },
165   { BY_W, TK_BY },
166   { CASCADE_W, TK_CASCADE },
167   { CASE_W, TK_CASE },
168   { CHAR_W, TK_CHAR },
169   { CHARACTER_W, TK_CHAR },
170   { CHECK_W, TK_CHECK },
171   { CLUSTER_W, TK_CLUSTER },
172   { COLLATE_W, TK_COLLATE },
173   { COMMIT_W, TK_COMMIT },
174   { CONFLICT_W, TK_CONFLICT },
175   { CONSTRAINT_W, TK_CONSTRAINT },
176   { COPY_W, TK_COPY },
177   { CREATE_W, TK_CREATE },
178   { CROSS_W, TK_JOIN_KW },
179   { DEFAULT_W, TK_DEFAULT },
180   { DEFERRED_W, TK_DEFERRED },
181   { DEFERRABLE_W, TK_DEFERRABLE },
182   { DELETE_W, TK_DELETE },
183   { DELIMITERS_W, TK_DELIMITERS },
184   { DESC_W, TK_DESC },
185   { DISTINCT_W, TK_DISTINCT },
186   { DROP_W, TK_DROP },
187   { END_W, TK_END },
188   { EACH_W, TK_EACH },
189   { ELSE_W, TK_ELSE },
190   { EXCEPT_W, TK_EXCEPT },
191   { EXPLAIN_W, TK_EXPLAIN },
192   { FAIL_W, TK_FAIL },
193   { FOR_W, TK_FOR },
194   { FOREIGN_W, TK_FOREIGN },
195   { FROM_W, TK_FROM },
196   { FULL_W, TK_JOIN_KW },
197   { GLOB_W, TK_GLOB },
198   { GROUP_W, TK_GROUP },
199   { HAVING_W, TK_HAVING },
200   { HOLD_W, TK_HOLD },
201   { IGNORE_W, TK_IGNORE },
202   { IMMEDIATE_W, TK_IMMEDIATE },
203   { IN_W, TK_IN },
204   { INDEX_W, TK_INDEX },
205   { INITIALLY_W, TK_INITIALLY },
206   { INNER_W, TK_JOIN_KW },
207   { INSERT_W, TK_INSERT },
208   { INSTEAD_W, TK_INSTEAD },
209   { INT_W, TK_INT },
210   { INTEGER_W, TK_INT },
211   { INTERSECT_W, TK_INTERSECT },
212   { INTO_W, TK_INTO },
213   { IS_W, TK_IS },
214   { ISNULL_W, TK_ISNULL },
215   { JOIN_W, TK_JOIN },
216   { KEY_W, TK_KEY },
217   { LEFT_W, TK_JOIN_KW },
218   { LIKE_W, TK_LIKE },
219   { LIMIT_W, TK_LIMIT },
220   { LOCALIZABLE_W, TK_LOCALIZABLE },
221   { LONG_W, TK_LONG },
222   { LONGCHAR_W, TK_LONGCHAR },
223   { MATCH_W, TK_MATCH },
224   { NATURAL_W, TK_JOIN_KW },
225   { NOT_W, TK_NOT },
226   { NOTNULL_W, TK_NOTNULL },
227   { NULL_W, TK_NULL },
228   { OBJECT_W, TK_OBJECT },
229   { OF_W, TK_OF },
230   { OFFSET_W, TK_OFFSET },
231   { ON_W, TK_ON },
232   { OR_W, TK_OR },
233   { ORDER_W, TK_ORDER },
234   { OUTER_W, TK_JOIN_KW },
235   { PRAGMA_W, TK_PRAGMA },
236   { PRIMARY_W, TK_PRIMARY },
237   { RAISE_W, TK_RAISE },
238   { REFERENCES_W, TK_REFERENCES },
239   { REPLACE_W, TK_REPLACE },
240   { RESTRICT_W, TK_RESTRICT },
241   { RIGHT_W, TK_JOIN_KW },
242   { ROLLBACK_W, TK_ROLLBACK },
243   { ROW_W, TK_ROW },
244   { SELECT_W, TK_SELECT },
245   { SET_W, TK_SET },
246   { SHORT_W, TK_SHORT },
247   { STATEMENT_W, TK_STATEMENT },
248   { TABLE_W, TK_TABLE },
249   { TEMPORARY_W, TK_TEMPORARY },
250   { THEN_W, TK_THEN },
251   { TRANSACTION_W, TK_TRANSACTION },
252   { TRIGGER_W, TK_TRIGGER },
253   { UNION_W, TK_UNION },
254   { UNIQUE_W, TK_UNIQUE },
255   { UPDATE_W, TK_UPDATE },
256   { USING_W, TK_USING },
257   { VACUUM_W, TK_VACUUM },
258   { VALUES_W, TK_VALUES },
259   { VIEW_W, TK_VIEW },
260   { WHEN_W, TK_WHEN },
261   { WHERE_W, TK_WHERE },
262 };
263
264 #define KEYWORD_COUNT ( sizeof aKeywordTable/sizeof (Keyword) )
265
266 /*
267 ** Comparison function for binary search.
268 */
269 static int compKeyword(const void *m1, const void *m2){
270   const Keyword *k1 = m1, *k2 = m2;
271
272   return strcmpiW( k1->zName, k2->zName );
273 }
274
275 /*
276 ** This function looks up an identifier to determine if it is a
277 ** keyword.  If it is a keyword, the token code of that keyword is 
278 ** returned.  If the input is not a keyword, TK_ID is returned.
279 */
280 static int sqliteKeywordCode(const WCHAR *z, int n){
281   WCHAR str[MAX_TOKEN_LEN+1];
282   Keyword key, *r;
283
284   if( n>MAX_TOKEN_LEN )
285     return TK_ID;
286
287   memcpy( str, z, n*sizeof (WCHAR) );
288   str[n] = 0;
289   key.tokenType = 0;
290   key.zName = str;
291   r = bsearch( &key, aKeywordTable, KEYWORD_COUNT, sizeof (Keyword), compKeyword );
292   if( r )
293     return r->tokenType;
294   return TK_ID;
295 }
296
297
298 /*
299 ** If X is a character that can be used in an identifier then
300 ** isIdChar[X] will be 1.  Otherwise isIdChar[X] will be 0.
301 **
302 ** In this implementation, an identifier can be a string of
303 ** alphabetic characters, digits, and "_" plus any character
304 ** with the high-order bit set.  The latter rule means that
305 ** any sequence of UTF-8 characters or characters taken from
306 ** an extended ISO8859 character set can form an identifier.
307 */
308 static const char isIdChar[] = {
309 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
310     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 0x */
311     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 1x */
312     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 2x */
313     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,  /* 3x */
314     0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 4x */
315     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,  /* 5x */
316     0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 6x */
317     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,  /* 7x */
318     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 8x */
319     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* 9x */
320     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Ax */
321     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Bx */
322     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Cx */
323     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Dx */
324     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Ex */
325     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* Fx */
326 };
327
328
329 /*
330 ** Return the length of the token that begins at z[0].  Return
331 ** -1 if the token is (or might be) incomplete.  Store the token
332 ** type in *tokenType before returning.
333 */
334 int sqliteGetToken(const WCHAR *z, int *tokenType){
335   int i;
336   switch( *z ){
337     case ' ': case '\t': case '\n': case '\f': case '\r': {
338       for(i=1; isspace(z[i]); i++){}
339       *tokenType = TK_SPACE;
340       return i;
341     }
342     case '-': {
343       if( z[1]==0 ) return -1;
344       if( z[1]=='-' ){
345         for(i=2; z[i] && z[i]!='\n'; i++){}
346         *tokenType = TK_COMMENT;
347         return i;
348       }
349       *tokenType = TK_MINUS;
350       return 1;
351     }
352     case '(': {
353       if( z[1]=='+' && z[2]==')' ){
354         *tokenType = TK_ORACLE_OUTER_JOIN;
355         return 3;
356       }else{
357         *tokenType = TK_LP;
358         return 1;
359       }
360     }
361     case ')': {
362       *tokenType = TK_RP;
363       return 1;
364     }
365     case ';': {
366       *tokenType = TK_SEMI;
367       return 1;
368     }
369     case '+': {
370       *tokenType = TK_PLUS;
371       return 1;
372     }
373     case '*': {
374       *tokenType = TK_STAR;
375       return 1;
376     }
377     case '/': {
378       if( z[1]!='*' || z[2]==0 ){
379         *tokenType = TK_SLASH;
380         return 1;
381       }
382       for(i=3; z[i] && (z[i]!='/' || z[i-1]!='*'); i++){}
383       if( z[i] ) i++;
384       *tokenType = TK_COMMENT;
385       return i;
386     }
387     case '%': {
388       *tokenType = TK_REM;
389       return 1;
390     }
391     case '=': {
392       *tokenType = TK_EQ;
393       return 1 + (z[1]=='=');
394     }
395     case '<': {
396       if( z[1]=='=' ){
397         *tokenType = TK_LE;
398         return 2;
399       }else if( z[1]=='>' ){
400         *tokenType = TK_NE;
401         return 2;
402       }else if( z[1]=='<' ){
403         *tokenType = TK_LSHIFT;
404         return 2;
405       }else{
406         *tokenType = TK_LT;
407         return 1;
408       }
409     }
410     case '>': {
411       if( z[1]=='=' ){
412         *tokenType = TK_GE;
413         return 2;
414       }else if( z[1]=='>' ){
415         *tokenType = TK_RSHIFT;
416         return 2;
417       }else{
418         *tokenType = TK_GT;
419         return 1;
420       }
421     }
422     case '!': {
423       if( z[1]!='=' ){
424         *tokenType = TK_ILLEGAL;
425         return 2;
426       }else{
427         *tokenType = TK_NE;
428         return 2;
429       }
430     }
431     case '|': {
432       if( z[1]!='|' ){
433         *tokenType = TK_BITOR;
434         return 1;
435       }else{
436         *tokenType = TK_CONCAT;
437         return 2;
438       }
439     }
440     case '?': {
441       *tokenType = TK_WILDCARD;
442       return 1;
443     }
444     case ',': {
445       *tokenType = TK_COMMA;
446       return 1;
447     }
448     case '&': {
449       *tokenType = TK_BITAND;
450       return 1;
451     }
452     case '~': {
453       *tokenType = TK_BITNOT;
454       return 1;
455     }
456     case '`': case '\'': case '"': {
457       int delim = z[0];
458       for(i=1; z[i]; i++){
459         if( z[i]==delim ){
460           if( z[i+1]==delim ){
461             i++;
462           }else{
463             break;
464           }
465         }
466       }
467       if( z[i] ) i++;
468       if( delim == '`' )
469         *tokenType = TK_ID;
470       else
471         *tokenType = TK_STRING;
472       return i;
473     }
474     case '.': {
475       if( !isdigit(z[1]) ){
476         *tokenType = TK_DOT;
477         return 1;
478       }
479       /* Fall thru into the next case */
480     }
481     case '0': case '1': case '2': case '3': case '4':
482     case '5': case '6': case '7': case '8': case '9': {
483       *tokenType = TK_INTEGER;
484       for(i=1; isdigit(z[i]); i++){}
485       if( z[i]=='.' ){
486         i++;
487         while( isdigit(z[i]) ){ i++; }
488         *tokenType = TK_FLOAT;
489       }
490       if( (z[i]=='e' || z[i]=='E') &&
491            ( isdigit(z[i+1]) 
492             || ((z[i+1]=='+' || z[i+1]=='-') && isdigit(z[i+2]))
493            )
494       ){
495         i += 2;
496         while( isdigit(z[i]) ){ i++; }
497         *tokenType = TK_FLOAT;
498       }else if( z[0]=='.' ){
499         *tokenType = TK_FLOAT;
500       }
501       return i;
502     }
503     case '[': {
504       for(i=1; z[i] && z[i-1]!=']'; i++){}
505       *tokenType = TK_ID;
506       return i;
507     }
508     default: {
509       if( !isIdChar[*z] ){
510         break;
511       }
512       for(i=1; isIdChar[z[i]]; i++){}
513       *tokenType = sqliteKeywordCode(z, i);
514       return i;
515     }
516   }
517   *tokenType = TK_ILLEGAL;
518   return 1;
519 }