annotate sqlite/tokenize.c @ 1571:0b69bc0eb2d2 trunk

[svn] - if uri == NULL, then continue looking for URIs in the XSPF playlist
author nenolod
date Fri, 11 Aug 2006 01:17:05 -0700
parents b6b61becdf4e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1434
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2 ** 2001 September 15
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4 ** The author disclaims copyright to this source code. In place of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
5 ** a legal notice, here is a blessing:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
6 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
7 ** May you do good and not evil.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
8 ** May you find forgiveness for yourself and forgive others.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
9 ** May you share freely, never taking more than you give.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
10 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
11 *************************************************************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
12 ** An tokenizer for SQL
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
13 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
14 ** This file contains C code that splits an SQL input string up into
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
15 ** individual tokens and sends those tokens one-by-one over to the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
16 ** parser for analysis.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
17 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
18 ** $Id: tokenize.c,v 1.118 2006/04/04 01:54:55 drh Exp $
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
19 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
20 #include "sqliteInt.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
21 #include "os.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
22 #include <ctype.h>
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
23 #include <stdlib.h>
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
24
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
25 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
26 ** The charMap() macro maps alphabetic characters into their
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
27 ** lower-case ASCII equivalent. On ASCII machines, this is just
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
28 ** an upper-to-lower case map. On EBCDIC machines we also need
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
29 ** to adjust the encoding. Only alphabetic characters and underscores
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
30 ** need to be translated.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
31 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
32 #ifdef SQLITE_ASCII
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
33 # define charMap(X) sqlite3UpperToLower[(unsigned char)X]
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
34 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
35 #ifdef SQLITE_EBCDIC
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
36 # define charMap(X) ebcdicToAscii[(unsigned char)X]
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
37 const unsigned char ebcdicToAscii[] = {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
38 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 5x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 95, 0, 0, /* 6x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 7x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
47 0, 97, 98, 99,100,101,102,103,104,105, 0, 0, 0, 0, 0, 0, /* 8x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
48 0,106,107,108,109,110,111,112,113,114, 0, 0, 0, 0, 0, 0, /* 9x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
49 0, 0,115,116,117,118,119,120,121,122, 0, 0, 0, 0, 0, 0, /* Ax */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
51 0, 97, 98, 99,100,101,102,103,104,105, 0, 0, 0, 0, 0, 0, /* Cx */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
52 0,106,107,108,109,110,111,112,113,114, 0, 0, 0, 0, 0, 0, /* Dx */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
53 0, 0,115,116,117,118,119,120,121,122, 0, 0, 0, 0, 0, 0, /* Ex */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Fx */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
55 };
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
56 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
57
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
58 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
59 ** The sqlite3KeywordCode function looks up an identifier to determine if
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
60 ** it is a keyword. If it is a keyword, the token code of that keyword is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
61 ** returned. If the input is not a keyword, TK_ID is returned.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
62 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
63 ** The implementation of this routine was generated by a program,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
64 ** mkkeywordhash.h, located in the tool subdirectory of the distribution.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
65 ** The output of the mkkeywordhash.c program is written into a file
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
66 ** named keywordhash.h and then included into this source file by
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
67 ** the #include below.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
68 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
69 #include "keywordhash.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
70
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
71
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
72 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
73 ** If X is a character that can be used in an identifier then
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
74 ** IdChar(X) will be true. Otherwise it is false.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
75 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
76 ** For ASCII, any character with the high-order bit set is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
77 ** allowed in an identifier. For 7-bit characters,
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
78 ** sqlite3IsIdChar[X] must be 1.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
79 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
80 ** For EBCDIC, the rules are more complex but have the same
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
81 ** end result.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
82 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
83 ** Ticket #1066. the SQL standard does not allow '$' in the
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
84 ** middle of identfiers. But many SQL implementations do.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
85 ** SQLite will allow '$' in identifiers for compatibility.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
86 ** But the feature is undocumented.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
87 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
88 #ifdef SQLITE_ASCII
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
89 const char sqlite3IsIdChar[] = {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
90 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
91 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
92 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
93 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
94 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
95 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
96 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
97 };
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
98 #define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20]))
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
99 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
100 #ifdef SQLITE_EBCDIC
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
101 const char sqlite3IsIdChar[] = {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
102 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
103 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 4x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
104 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, /* 5x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
105 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, /* 6x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
106 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, /* 7x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
107 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, /* 8x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
108 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, /* 9x */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
109 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, /* Ax */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
111 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Cx */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
112 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Dx */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
113 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Ex */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
114 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* Fx */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
115 };
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
116 #define IdChar(C) (((c=C)>=0x42 && sqlite3IsIdChar[c-0x40]))
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
117 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
118
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
119
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
120 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
121 ** Return the length of the token that begins at z[0].
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
122 ** Store the token type in *tokenType before returning.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
123 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
124 static int getToken(const unsigned char *z, int *tokenType){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
125 int i, c;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
126 switch( *z ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
127 case ' ': case '\t': case '\n': case '\f': case '\r': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
128 for(i=1; isspace(z[i]); i++){}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
129 *tokenType = TK_SPACE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
130 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
131 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
132 case '-': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
133 if( z[1]=='-' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
134 for(i=2; (c=z[i])!=0 && c!='\n'; i++){}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
135 *tokenType = TK_COMMENT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
136 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
137 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
138 *tokenType = TK_MINUS;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
139 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
140 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
141 case '(': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
142 *tokenType = TK_LP;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
143 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
144 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
145 case ')': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
146 *tokenType = TK_RP;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
147 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
148 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
149 case ';': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
150 *tokenType = TK_SEMI;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
151 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
152 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
153 case '+': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
154 *tokenType = TK_PLUS;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
155 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
156 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
157 case '*': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
158 *tokenType = TK_STAR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
159 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
160 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
161 case '/': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
162 if( z[1]!='*' || z[2]==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
163 *tokenType = TK_SLASH;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
164 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
165 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
166 for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
167 if( c ) i++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
168 *tokenType = TK_COMMENT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
169 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
170 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
171 case '%': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
172 *tokenType = TK_REM;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
173 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
174 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
175 case '=': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
176 *tokenType = TK_EQ;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
177 return 1 + (z[1]=='=');
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
178 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
179 case '<': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
180 if( (c=z[1])=='=' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
181 *tokenType = TK_LE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
182 return 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
183 }else if( c=='>' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
184 *tokenType = TK_NE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
185 return 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
186 }else if( c=='<' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
187 *tokenType = TK_LSHIFT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
188 return 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
189 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
190 *tokenType = TK_LT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
191 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
192 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
193 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
194 case '>': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
195 if( (c=z[1])=='=' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
196 *tokenType = TK_GE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
197 return 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
198 }else if( c=='>' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
199 *tokenType = TK_RSHIFT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
200 return 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
201 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
202 *tokenType = TK_GT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
203 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
204 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
205 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
206 case '!': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
207 if( z[1]!='=' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
208 *tokenType = TK_ILLEGAL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
209 return 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
210 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
211 *tokenType = TK_NE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
212 return 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
213 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
214 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
215 case '|': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
216 if( z[1]!='|' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
217 *tokenType = TK_BITOR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
218 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
219 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
220 *tokenType = TK_CONCAT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
221 return 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
222 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
223 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
224 case ',': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
225 *tokenType = TK_COMMA;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
226 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
227 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
228 case '&': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
229 *tokenType = TK_BITAND;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
230 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
231 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
232 case '~': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
233 *tokenType = TK_BITNOT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
234 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
235 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
236 case '`':
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
237 case '\'':
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
238 case '"': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
239 int delim = z[0];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
240 for(i=1; (c=z[i])!=0; i++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
241 if( c==delim ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
242 if( z[i+1]==delim ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
243 i++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
244 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
245 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
246 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
247 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
248 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
249 if( c ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
250 *tokenType = TK_STRING;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
251 return i+1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
252 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
253 *tokenType = TK_ILLEGAL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
254 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
255 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
256 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
257 case '.': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
258 #ifndef SQLITE_OMIT_FLOATING_POINT
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
259 if( !isdigit(z[1]) )
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
260 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
261 {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
262 *tokenType = TK_DOT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
263 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
264 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
265 /* If the next character is a digit, this is a floating point
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
266 ** number that begins with ".". Fall thru into the next case */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
267 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
268 case '0': case '1': case '2': case '3': case '4':
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
269 case '5': case '6': case '7': case '8': case '9': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
270 *tokenType = TK_INTEGER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
271 for(i=0; isdigit(z[i]); i++){}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
272 #ifndef SQLITE_OMIT_FLOATING_POINT
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
273 if( z[i]=='.' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
274 i++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
275 while( isdigit(z[i]) ){ i++; }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
276 *tokenType = TK_FLOAT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
277 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
278 if( (z[i]=='e' || z[i]=='E') &&
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
279 ( isdigit(z[i+1])
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
280 || ((z[i+1]=='+' || z[i+1]=='-') && isdigit(z[i+2]))
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
281 )
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
282 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
283 i += 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
284 while( isdigit(z[i]) ){ i++; }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
285 *tokenType = TK_FLOAT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
286 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
287 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
288 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
289 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
290 case '[': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
291 for(i=1, c=z[0]; c!=']' && (c=z[i])!=0; i++){}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
292 *tokenType = TK_ID;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
293 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
294 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
295 case '?': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
296 *tokenType = TK_VARIABLE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
297 for(i=1; isdigit(z[i]); i++){}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
298 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
299 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
300 case '#': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
301 for(i=1; isdigit(z[i]); i++){}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
302 if( i>1 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
303 /* Parameters of the form #NNN (where NNN is a number) are used
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
304 ** internally by sqlite3NestedParse. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
305 *tokenType = TK_REGISTER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
306 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
307 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
308 /* Fall through into the next case if the '#' is not followed by
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
309 ** a digit. Try to match #AAAA where AAAA is a parameter name. */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
310 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
311 #ifndef SQLITE_OMIT_TCL_VARIABLE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
312 case '$':
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
313 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
314 case '@': /* For compatibility with MS SQL Server */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
315 case ':': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
316 int n = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
317 *tokenType = TK_VARIABLE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
318 for(i=1; (c=z[i])!=0; i++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
319 if( IdChar(c) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
320 n++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
321 #ifndef SQLITE_OMIT_TCL_VARIABLE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
322 }else if( c=='(' && n>0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
323 do{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
324 i++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
325 }while( (c=z[i])!=0 && !isspace(c) && c!=')' );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
326 if( c==')' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
327 i++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
328 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
329 *tokenType = TK_ILLEGAL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
330 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
331 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
332 }else if( c==':' && z[i+1]==':' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
333 i++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
334 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
335 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
336 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
337 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
338 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
339 if( n==0 ) *tokenType = TK_ILLEGAL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
340 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
341 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
342 #ifndef SQLITE_OMIT_BLOB_LITERAL
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
343 case 'x': case 'X': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
344 if( (c=z[1])=='\'' || c=='"' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
345 int delim = c;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
346 *tokenType = TK_BLOB;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
347 for(i=2; (c=z[i])!=0; i++){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
348 if( c==delim ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
349 if( i%2 ) *tokenType = TK_ILLEGAL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
350 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
351 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
352 if( !isxdigit(c) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
353 *tokenType = TK_ILLEGAL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
354 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
355 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
356 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
357 if( c ) i++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
358 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
359 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
360 /* Otherwise fall through to the next case */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
361 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
362 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
363 default: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
364 if( !IdChar(*z) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
365 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
366 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
367 for(i=1; IdChar(z[i]); i++){}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
368 *tokenType = keywordCode((char*)z, i);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
369 return i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
370 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
371 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
372 *tokenType = TK_ILLEGAL;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
373 return 1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
374 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
375 int sqlite3GetToken(const unsigned char *z, int *tokenType){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
376 return getToken(z, tokenType);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
377 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
378
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
379 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
380 ** Run the parser on the given SQL string. The parser structure is
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
381 ** passed in. An SQLITE_ status code is returned. If an error occurs
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
382 ** and pzErrMsg!=NULL then an error message might be written into
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
383 ** memory obtained from malloc() and *pzErrMsg made to point to that
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
384 ** error message. Or maybe not.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
385 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
386 int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
387 int nErr = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
388 int i;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
389 void *pEngine;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
390 int tokenType;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
391 int lastTokenParsed = -1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
392 sqlite3 *db = pParse->db;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
393 extern void *sqlite3ParserAlloc(void*(*)(int));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
394 extern void sqlite3ParserFree(void*, void(*)(void*));
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
395 extern int sqlite3Parser(void*, int, Token, Parse*);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
396
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
397 db->flags &= ~SQLITE_Interrupt;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
398 pParse->rc = SQLITE_OK;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
399 i = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
400 pEngine = sqlite3ParserAlloc((void*(*)(int))sqlite3MallocX);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
401 if( pEngine==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
402 return SQLITE_NOMEM;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
403 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
404 assert( pParse->sLastToken.dyn==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
405 assert( pParse->pNewTable==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
406 assert( pParse->pNewTrigger==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
407 assert( pParse->nVar==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
408 assert( pParse->nVarExpr==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
409 assert( pParse->nVarExprAlloc==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
410 assert( pParse->apVarExpr==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
411 pParse->zTail = pParse->zSql = zSql;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
412 while( !sqlite3MallocFailed() && zSql[i]!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
413 assert( i>=0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
414 pParse->sLastToken.z = (u8*)&zSql[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
415 assert( pParse->sLastToken.dyn==0 );
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
416 pParse->sLastToken.n = getToken((unsigned char*)&zSql[i],&tokenType);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
417 i += pParse->sLastToken.n;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
418 switch( tokenType ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
419 case TK_SPACE:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
420 case TK_COMMENT: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
421 if( (db->flags & SQLITE_Interrupt)!=0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
422 pParse->rc = SQLITE_INTERRUPT;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
423 sqlite3SetString(pzErrMsg, "interrupt", (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
424 goto abort_parse;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
425 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
426 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
427 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
428 case TK_ILLEGAL: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
429 if( pzErrMsg ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
430 sqliteFree(*pzErrMsg);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
431 *pzErrMsg = sqlite3MPrintf("unrecognized token: \"%T\"",
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
432 &pParse->sLastToken);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
433 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
434 nErr++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
435 goto abort_parse;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
436 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
437 case TK_SEMI: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
438 pParse->zTail = &zSql[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
439 /* Fall thru into the default case */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
440 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
441 default: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
442 sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
443 lastTokenParsed = tokenType;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
444 if( pParse->rc!=SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
445 goto abort_parse;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
446 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
447 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
448 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
449 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
450 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
451 abort_parse:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
452 if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
453 if( lastTokenParsed!=TK_SEMI ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
454 sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
455 pParse->zTail = &zSql[i];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
456 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
457 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
458 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
459 sqlite3ParserFree(pEngine, sqlite3FreeX);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
460 if( sqlite3MallocFailed() ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
461 pParse->rc = SQLITE_NOMEM;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
462 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
463 if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
464 sqlite3SetString(&pParse->zErrMsg, sqlite3ErrStr(pParse->rc), (char*)0);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
465 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
466 if( pParse->zErrMsg ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
467 if( pzErrMsg && *pzErrMsg==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
468 *pzErrMsg = pParse->zErrMsg;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
469 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
470 sqliteFree(pParse->zErrMsg);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
471 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
472 pParse->zErrMsg = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
473 if( !nErr ) nErr++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
474 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
475 if( pParse->pVdbe && pParse->nErr>0 && pParse->nested==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
476 sqlite3VdbeDelete(pParse->pVdbe);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
477 pParse->pVdbe = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
478 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
479 #ifndef SQLITE_OMIT_SHARED_CACHE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
480 if( pParse->nested==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
481 sqliteFree(pParse->aTableLock);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
482 pParse->aTableLock = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
483 pParse->nTableLock = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
484 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
485 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
486 sqlite3DeleteTable(pParse->db, pParse->pNewTable);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
487 sqlite3DeleteTrigger(pParse->pNewTrigger);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
488 sqliteFree(pParse->apVarExpr);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
489 if( nErr>0 && (pParse->rc==SQLITE_OK || pParse->rc==SQLITE_DONE) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
490 pParse->rc = SQLITE_ERROR;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
491 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
492 return nErr;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
493 }