2004-10-07 23:03:01 +04:00
|
|
|
/*
|
|
|
|
** Compile and run this standalone program in order to generate code that
|
|
|
|
** implements a function that will translate alphabetic identifiers into
|
|
|
|
** parser token codes.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2009-06-09 18:27:41 +04:00
|
|
|
#include <assert.h>
|
2004-10-07 23:03:01 +04:00
|
|
|
|
2007-02-21 19:44:33 +03:00
|
|
|
/*
|
|
|
|
** A header comment placed at the beginning of generated code.
|
|
|
|
*/
|
|
|
|
static const char zHdr[] =
|
|
|
|
"/***** This file contains automatically generated code ******\n"
|
|
|
|
"**\n"
|
|
|
|
"** The code in this file has been automatically generated by\n"
|
|
|
|
"**\n"
|
2009-11-03 16:08:16 +03:00
|
|
|
"** sqlite/tool/mkkeywordhash.c\n"
|
2007-02-21 19:44:33 +03:00
|
|
|
"**\n"
|
|
|
|
"** The code in this file implements a function that determines whether\n"
|
|
|
|
"** or not a given identifier is really an SQL keyword. The same thing\n"
|
|
|
|
"** might be implemented more directly using a hand-written hash table.\n"
|
|
|
|
"** But by using this automatically generated code, the size of the code\n"
|
|
|
|
"** is substantially reduced. This is important for embedded applications\n"
|
|
|
|
"** on platforms with limited memory.\n"
|
|
|
|
"*/\n"
|
|
|
|
;
|
|
|
|
|
2004-10-07 23:03:01 +04:00
|
|
|
/*
|
2008-12-10 23:11:01 +03:00
|
|
|
** All the keywords of the SQL language are stored in a hash
|
2004-10-07 23:03:01 +04:00
|
|
|
** table composed of instances of the following structure.
|
|
|
|
*/
|
|
|
|
typedef struct Keyword Keyword;
|
|
|
|
struct Keyword {
|
|
|
|
char *zName; /* The keyword name */
|
|
|
|
char *zTokenType; /* Token value for this keyword */
|
2004-11-03 06:59:57 +03:00
|
|
|
int mask; /* Code this keyword if non-zero */
|
2019-11-01 05:30:54 +03:00
|
|
|
int priority; /* Put higher priorities earlier in the hash chain */
|
2004-10-23 09:10:18 +04:00
|
|
|
int id; /* Unique ID for this record */
|
2004-10-07 23:03:01 +04:00
|
|
|
int hash; /* Hash on the keyword */
|
|
|
|
int offset; /* Offset to start of name string */
|
|
|
|
int len; /* Length of this keyword, not counting final \000 */
|
2004-10-23 09:10:18 +04:00
|
|
|
int prefix; /* Number of characters in prefix */
|
2007-05-04 21:07:52 +04:00
|
|
|
int longestSuffix; /* Longest suffix that is a prefix on another word */
|
2004-10-07 23:03:01 +04:00
|
|
|
int iNext; /* Index in aKeywordTable[] of next with same hash */
|
2004-10-23 09:10:18 +04:00
|
|
|
int substrId; /* Id to another keyword this keyword is embedded in */
|
|
|
|
int substrOffset; /* Offset into substrId for start of this keyword */
|
2009-06-09 18:27:41 +04:00
|
|
|
char zOrigName[20]; /* Original keyword name before processing */
|
2004-10-07 23:03:01 +04:00
|
|
|
};
|
|
|
|
|
2004-11-03 06:59:57 +03:00
|
|
|
/*
|
|
|
|
** Define masks used to determine which keywords are allowed
|
|
|
|
*/
|
2004-11-13 06:59:25 +03:00
|
|
|
#ifdef SQLITE_OMIT_ALTERTABLE
|
2004-11-03 06:59:57 +03:00
|
|
|
# define ALTER 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define ALTER 0x00000001
|
|
|
|
#endif
|
|
|
|
#define ALWAYS 0x00000002
|
|
|
|
#ifdef SQLITE_OMIT_ANALYZE
|
|
|
|
# define ANALYZE 0
|
|
|
|
#else
|
|
|
|
# define ANALYZE 0x00000004
|
2004-11-03 06:59:57 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_OMIT_ATTACH
|
|
|
|
# define ATTACH 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define ATTACH 0x00000008
|
2004-11-03 06:59:57 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_OMIT_AUTOINCREMENT
|
|
|
|
# define AUTOINCR 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define AUTOINCR 0x00000010
|
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_OMIT_CAST
|
|
|
|
# define CAST 0
|
|
|
|
#else
|
|
|
|
# define CAST 0x00000020
|
2004-11-03 06:59:57 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_OMIT_COMPOUND_SELECT
|
|
|
|
# define COMPOUND 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define COMPOUND 0x00000040
|
2004-11-03 06:59:57 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_OMIT_CONFLICT_CLAUSE
|
|
|
|
# define CONFLICT 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define CONFLICT 0x00000080
|
2004-11-03 06:59:57 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_OMIT_EXPLAIN
|
|
|
|
# define EXPLAIN 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define EXPLAIN 0x00000100
|
2004-11-03 06:59:57 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_OMIT_FOREIGN_KEY
|
|
|
|
# define FKEY 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define FKEY 0x00000200
|
2004-11-03 06:59:57 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_OMIT_PRAGMA
|
|
|
|
# define PRAGMA 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define PRAGMA 0x00000400
|
2004-11-03 06:59:57 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_OMIT_REINDEX
|
|
|
|
# define REINDEX 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define REINDEX 0x00000800
|
2004-11-03 06:59:57 +03:00
|
|
|
#endif
|
2005-01-20 16:36:19 +03:00
|
|
|
#ifdef SQLITE_OMIT_SUBQUERY
|
|
|
|
# define SUBQUERY 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define SUBQUERY 0x00001000
|
2005-01-20 16:36:19 +03:00
|
|
|
#endif
|
2004-11-03 06:59:57 +03:00
|
|
|
#ifdef SQLITE_OMIT_TRIGGER
|
|
|
|
# define TRIGGER 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define TRIGGER 0x00002000
|
2004-11-03 06:59:57 +03:00
|
|
|
#endif
|
2007-04-26 18:42:34 +04:00
|
|
|
#if defined(SQLITE_OMIT_AUTOVACUUM) && \
|
|
|
|
(defined(SQLITE_OMIT_VACUUM) || defined(SQLITE_OMIT_ATTACH))
|
2004-11-03 06:59:57 +03:00
|
|
|
# define VACUUM 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define VACUUM 0x00004000
|
2004-11-03 06:59:57 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_OMIT_VIEW
|
|
|
|
# define VIEW 0
|
|
|
|
#else
|
2005-07-08 16:13:04 +04:00
|
|
|
# define VIEW 0x00008000
|
2005-06-25 22:42:14 +04:00
|
|
|
#endif
|
2006-06-10 17:29:31 +04:00
|
|
|
#ifdef SQLITE_OMIT_VIRTUALTABLE
|
|
|
|
# define VTAB 0
|
|
|
|
#else
|
|
|
|
# define VTAB 0x00010000
|
|
|
|
#endif
|
2007-04-26 18:42:34 +04:00
|
|
|
#ifdef SQLITE_OMIT_AUTOVACUUM
|
|
|
|
# define AUTOVACUUM 0
|
|
|
|
#else
|
|
|
|
# define AUTOVACUUM 0x00020000
|
|
|
|
#endif
|
2014-01-11 17:22:17 +04:00
|
|
|
#ifdef SQLITE_OMIT_CTE
|
|
|
|
# define CTE 0
|
|
|
|
#else
|
|
|
|
# define CTE 0x00040000
|
|
|
|
#endif
|
2018-04-12 18:43:05 +03:00
|
|
|
#ifdef SQLITE_OMIT_UPSERT
|
|
|
|
# define UPSERT 0
|
|
|
|
#else
|
|
|
|
# define UPSERT 0x00080000
|
|
|
|
#endif
|
2018-06-22 23:51:35 +03:00
|
|
|
#ifdef SQLITE_OMIT_WINDOWFUNC
|
|
|
|
# define WINDOWFUNC 0
|
|
|
|
#else
|
|
|
|
# define WINDOWFUNC 0x00100000
|
|
|
|
#endif
|
2019-11-01 13:49:15 +03:00
|
|
|
#ifdef SQLITE_OMIT_GENERATED_COLUMNS
|
|
|
|
# define GENCOL 0
|
|
|
|
#else
|
|
|
|
# define GENCOL 0x00200000
|
|
|
|
#endif
|
2004-11-03 06:59:57 +03:00
|
|
|
|
2004-10-07 23:03:01 +04:00
|
|
|
/*
|
|
|
|
** These are the keywords
|
|
|
|
*/
|
|
|
|
static Keyword aKeywordTable[] = {
|
2019-11-01 05:30:54 +03:00
|
|
|
{ "ABORT", "TK_ABORT", CONFLICT|TRIGGER, 0 },
|
|
|
|
{ "ACTION", "TK_ACTION", FKEY, 0 },
|
|
|
|
{ "ADD", "TK_ADD", ALTER, 1 },
|
|
|
|
{ "AFTER", "TK_AFTER", TRIGGER, 0 },
|
|
|
|
{ "ALL", "TK_ALL", ALWAYS, 0 },
|
|
|
|
{ "ALTER", "TK_ALTER", ALTER, 0 },
|
2019-11-01 13:49:15 +03:00
|
|
|
{ "ALWAYS", "TK_ALWAYS", GENCOL, 0 },
|
2019-11-01 05:30:54 +03:00
|
|
|
{ "ANALYZE", "TK_ANALYZE", ANALYZE, 0 },
|
|
|
|
{ "AND", "TK_AND", ALWAYS, 10 },
|
|
|
|
{ "AS", "TK_AS", ALWAYS, 10 },
|
|
|
|
{ "ASC", "TK_ASC", ALWAYS, 0 },
|
|
|
|
{ "ATTACH", "TK_ATTACH", ATTACH, 1 },
|
|
|
|
{ "AUTOINCREMENT", "TK_AUTOINCR", AUTOINCR, 0 },
|
|
|
|
{ "BEFORE", "TK_BEFORE", TRIGGER, 0 },
|
|
|
|
{ "BEGIN", "TK_BEGIN", ALWAYS, 1 },
|
|
|
|
{ "BETWEEN", "TK_BETWEEN", ALWAYS, 5 },
|
|
|
|
{ "BY", "TK_BY", ALWAYS, 10 },
|
|
|
|
{ "CASCADE", "TK_CASCADE", FKEY, 1 },
|
|
|
|
{ "CASE", "TK_CASE", ALWAYS, 5 },
|
|
|
|
{ "CAST", "TK_CAST", CAST, 5 },
|
|
|
|
{ "CHECK", "TK_CHECK", ALWAYS, 1 },
|
|
|
|
{ "COLLATE", "TK_COLLATE", ALWAYS, 1 },
|
|
|
|
{ "COLUMN", "TK_COLUMNKW", ALTER, 1 },
|
|
|
|
{ "COMMIT", "TK_COMMIT", ALWAYS, 1 },
|
|
|
|
{ "CONFLICT", "TK_CONFLICT", CONFLICT, 0 },
|
|
|
|
{ "CONSTRAINT", "TK_CONSTRAINT", ALWAYS, 1 },
|
|
|
|
{ "CREATE", "TK_CREATE", ALWAYS, 2 },
|
|
|
|
{ "CROSS", "TK_JOIN_KW", ALWAYS, 3 },
|
|
|
|
{ "CURRENT", "TK_CURRENT", WINDOWFUNC, 1 },
|
|
|
|
{ "CURRENT_DATE", "TK_CTIME_KW", ALWAYS, 1 },
|
|
|
|
{ "CURRENT_TIME", "TK_CTIME_KW", ALWAYS, 1 },
|
|
|
|
{ "CURRENT_TIMESTAMP","TK_CTIME_KW", ALWAYS, 1 },
|
|
|
|
{ "DATABASE", "TK_DATABASE", ATTACH, 0 },
|
|
|
|
{ "DEFAULT", "TK_DEFAULT", ALWAYS, 1 },
|
|
|
|
{ "DEFERRED", "TK_DEFERRED", ALWAYS, 1 },
|
|
|
|
{ "DEFERRABLE", "TK_DEFERRABLE", FKEY, 1 },
|
|
|
|
{ "DELETE", "TK_DELETE", ALWAYS, 10 },
|
|
|
|
{ "DESC", "TK_DESC", ALWAYS, 3 },
|
|
|
|
{ "DETACH", "TK_DETACH", ATTACH, 0 },
|
|
|
|
{ "DISTINCT", "TK_DISTINCT", ALWAYS, 5 },
|
|
|
|
{ "DO", "TK_DO", UPSERT, 2 },
|
|
|
|
{ "DROP", "TK_DROP", ALWAYS, 1 },
|
|
|
|
{ "END", "TK_END", ALWAYS, 1 },
|
|
|
|
{ "EACH", "TK_EACH", TRIGGER, 1 },
|
|
|
|
{ "ELSE", "TK_ELSE", ALWAYS, 2 },
|
|
|
|
{ "ESCAPE", "TK_ESCAPE", ALWAYS, 4 },
|
|
|
|
{ "EXCEPT", "TK_EXCEPT", COMPOUND, 4 },
|
|
|
|
{ "EXCLUSIVE", "TK_EXCLUSIVE", ALWAYS, 1 },
|
|
|
|
{ "EXCLUDE", "TK_EXCLUDE", WINDOWFUNC, 1 },
|
|
|
|
{ "EXISTS", "TK_EXISTS", ALWAYS, 4 },
|
|
|
|
{ "EXPLAIN", "TK_EXPLAIN", EXPLAIN, 1 },
|
|
|
|
{ "FAIL", "TK_FAIL", CONFLICT|TRIGGER, 1 },
|
|
|
|
{ "FILTER", "TK_FILTER", WINDOWFUNC, 4 },
|
|
|
|
{ "FIRST", "TK_FIRST", ALWAYS, 4 },
|
|
|
|
{ "FOLLOWING", "TK_FOLLOWING", WINDOWFUNC, 4 },
|
|
|
|
{ "FOR", "TK_FOR", TRIGGER, 2 },
|
|
|
|
{ "FOREIGN", "TK_FOREIGN", FKEY, 1 },
|
|
|
|
{ "FROM", "TK_FROM", ALWAYS, 10 },
|
|
|
|
{ "FULL", "TK_JOIN_KW", ALWAYS, 3 },
|
2019-11-01 13:49:15 +03:00
|
|
|
{ "GENERATED", "TK_GENERATED", GENCOL, 1 },
|
2019-11-01 05:30:54 +03:00
|
|
|
{ "GLOB", "TK_LIKE_KW", ALWAYS, 3 },
|
|
|
|
{ "GROUP", "TK_GROUP", ALWAYS, 5 },
|
|
|
|
{ "GROUPS", "TK_GROUPS", WINDOWFUNC, 2 },
|
|
|
|
{ "HAVING", "TK_HAVING", ALWAYS, 5 },
|
|
|
|
{ "IF", "TK_IF", ALWAYS, 2 },
|
|
|
|
{ "IGNORE", "TK_IGNORE", CONFLICT|TRIGGER, 1 },
|
|
|
|
{ "IMMEDIATE", "TK_IMMEDIATE", ALWAYS, 1 },
|
|
|
|
{ "IN", "TK_IN", ALWAYS, 10 },
|
|
|
|
{ "INDEX", "TK_INDEX", ALWAYS, 1 },
|
|
|
|
{ "INDEXED", "TK_INDEXED", ALWAYS, 0 },
|
|
|
|
{ "INITIALLY", "TK_INITIALLY", FKEY, 1 },
|
|
|
|
{ "INNER", "TK_JOIN_KW", ALWAYS, 1 },
|
|
|
|
{ "INSERT", "TK_INSERT", ALWAYS, 10 },
|
|
|
|
{ "INSTEAD", "TK_INSTEAD", TRIGGER, 1 },
|
|
|
|
{ "INTERSECT", "TK_INTERSECT", COMPOUND, 5 },
|
|
|
|
{ "INTO", "TK_INTO", ALWAYS, 10 },
|
|
|
|
{ "IS", "TK_IS", ALWAYS, 5 },
|
|
|
|
{ "ISNULL", "TK_ISNULL", ALWAYS, 5 },
|
|
|
|
{ "JOIN", "TK_JOIN", ALWAYS, 5 },
|
|
|
|
{ "KEY", "TK_KEY", ALWAYS, 1 },
|
|
|
|
{ "LAST", "TK_LAST", ALWAYS, 4 },
|
|
|
|
{ "LEFT", "TK_JOIN_KW", ALWAYS, 5 },
|
|
|
|
{ "LIKE", "TK_LIKE_KW", ALWAYS, 5 },
|
|
|
|
{ "LIMIT", "TK_LIMIT", ALWAYS, 3 },
|
|
|
|
{ "MATCH", "TK_MATCH", ALWAYS, 2 },
|
|
|
|
{ "NATURAL", "TK_JOIN_KW", ALWAYS, 3 },
|
|
|
|
{ "NO", "TK_NO", FKEY|WINDOWFUNC, 2 },
|
|
|
|
{ "NOT", "TK_NOT", ALWAYS, 10 },
|
|
|
|
{ "NOTHING", "TK_NOTHING", UPSERT, 1 },
|
|
|
|
{ "NOTNULL", "TK_NOTNULL", ALWAYS, 3 },
|
|
|
|
{ "NULL", "TK_NULL", ALWAYS, 10 },
|
|
|
|
{ "NULLS", "TK_NULLS", ALWAYS, 3 },
|
|
|
|
{ "OF", "TK_OF", ALWAYS, 3 },
|
|
|
|
{ "OFFSET", "TK_OFFSET", ALWAYS, 1 },
|
|
|
|
{ "ON", "TK_ON", ALWAYS, 1 },
|
|
|
|
{ "OR", "TK_OR", ALWAYS, 9 },
|
|
|
|
{ "ORDER", "TK_ORDER", ALWAYS, 10 },
|
|
|
|
{ "OTHERS", "TK_OTHERS", WINDOWFUNC, 3 },
|
|
|
|
{ "OUTER", "TK_JOIN_KW", ALWAYS, 5 },
|
|
|
|
{ "OVER", "TK_OVER", WINDOWFUNC, 3 },
|
|
|
|
{ "PARTITION", "TK_PARTITION", WINDOWFUNC, 3 },
|
|
|
|
{ "PLAN", "TK_PLAN", EXPLAIN, 0 },
|
|
|
|
{ "PRAGMA", "TK_PRAGMA", PRAGMA, 0 },
|
|
|
|
{ "PRECEDING", "TK_PRECEDING", WINDOWFUNC, 3 },
|
|
|
|
{ "PRIMARY", "TK_PRIMARY", ALWAYS, 1 },
|
|
|
|
{ "QUERY", "TK_QUERY", EXPLAIN, 0 },
|
|
|
|
{ "RAISE", "TK_RAISE", TRIGGER, 1 },
|
|
|
|
{ "RANGE", "TK_RANGE", WINDOWFUNC, 3 },
|
|
|
|
{ "RECURSIVE", "TK_RECURSIVE", CTE, 3 },
|
|
|
|
{ "REFERENCES", "TK_REFERENCES", FKEY, 1 },
|
|
|
|
{ "REGEXP", "TK_LIKE_KW", ALWAYS, 3 },
|
|
|
|
{ "REINDEX", "TK_REINDEX", REINDEX, 1 },
|
|
|
|
{ "RELEASE", "TK_RELEASE", ALWAYS, 1 },
|
|
|
|
{ "RENAME", "TK_RENAME", ALTER, 1 },
|
|
|
|
{ "REPLACE", "TK_REPLACE", CONFLICT, 10 },
|
|
|
|
{ "RESTRICT", "TK_RESTRICT", FKEY, 1 },
|
|
|
|
{ "RIGHT", "TK_JOIN_KW", ALWAYS, 0 },
|
|
|
|
{ "ROLLBACK", "TK_ROLLBACK", ALWAYS, 1 },
|
|
|
|
{ "ROW", "TK_ROW", TRIGGER, 1 },
|
|
|
|
{ "ROWS", "TK_ROWS", ALWAYS, 1 },
|
|
|
|
{ "SAVEPOINT", "TK_SAVEPOINT", ALWAYS, 1 },
|
|
|
|
{ "SELECT", "TK_SELECT", ALWAYS, 10 },
|
|
|
|
{ "SET", "TK_SET", ALWAYS, 10 },
|
|
|
|
{ "TABLE", "TK_TABLE", ALWAYS, 1 },
|
|
|
|
{ "TEMP", "TK_TEMP", ALWAYS, 1 },
|
|
|
|
{ "TEMPORARY", "TK_TEMP", ALWAYS, 1 },
|
|
|
|
{ "THEN", "TK_THEN", ALWAYS, 3 },
|
|
|
|
{ "TIES", "TK_TIES", WINDOWFUNC, 3 },
|
|
|
|
{ "TO", "TK_TO", ALWAYS, 3 },
|
|
|
|
{ "TRANSACTION", "TK_TRANSACTION", ALWAYS, 1 },
|
|
|
|
{ "TRIGGER", "TK_TRIGGER", TRIGGER, 1 },
|
|
|
|
{ "UNBOUNDED", "TK_UNBOUNDED", WINDOWFUNC, 3 },
|
|
|
|
{ "UNION", "TK_UNION", COMPOUND, 3 },
|
|
|
|
{ "UNIQUE", "TK_UNIQUE", ALWAYS, 1 },
|
|
|
|
{ "UPDATE", "TK_UPDATE", ALWAYS, 10 },
|
|
|
|
{ "USING", "TK_USING", ALWAYS, 8 },
|
|
|
|
{ "VACUUM", "TK_VACUUM", VACUUM, 1 },
|
|
|
|
{ "VALUES", "TK_VALUES", ALWAYS, 10 },
|
|
|
|
{ "VIEW", "TK_VIEW", VIEW, 1 },
|
|
|
|
{ "VIRTUAL", "TK_VIRTUAL", VTAB, 1 },
|
|
|
|
{ "WHEN", "TK_WHEN", ALWAYS, 1 },
|
|
|
|
{ "WHERE", "TK_WHERE", ALWAYS, 10 },
|
|
|
|
{ "WINDOW", "TK_WINDOW", WINDOWFUNC, 3 },
|
|
|
|
{ "WITH", "TK_WITH", CTE, 4 },
|
|
|
|
{ "WITHOUT", "TK_WITHOUT", ALWAYS, 1 },
|
2004-10-07 23:03:01 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Number of keywords */
|
2007-05-04 21:07:52 +04:00
|
|
|
static int nKeyword = (sizeof(aKeywordTable)/sizeof(aKeywordTable[0]));
|
2004-10-07 23:03:01 +04:00
|
|
|
|
2016-02-08 22:15:48 +03:00
|
|
|
/* Map all alphabetic characters into lower-case for hashing. This is
|
|
|
|
** only valid for alphabetics. In particular it does not work for '_'
|
|
|
|
** and so the hash cannot be on a keyword position that might be an '_'.
|
|
|
|
*/
|
2015-11-10 06:30:51 +03:00
|
|
|
#define charMap(X) (0x20|(X))
|
2004-10-07 23:03:01 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Comparision function for two Keyword records
|
|
|
|
*/
|
2004-10-23 09:10:18 +04:00
|
|
|
static int keywordCompare1(const void *a, const void *b){
|
2004-10-07 23:03:01 +04:00
|
|
|
const Keyword *pA = (Keyword*)a;
|
|
|
|
const Keyword *pB = (Keyword*)b;
|
2004-10-23 09:10:18 +04:00
|
|
|
int n = pA->len - pB->len;
|
|
|
|
if( n==0 ){
|
|
|
|
n = strcmp(pA->zName, pB->zName);
|
|
|
|
}
|
2009-11-03 16:08:16 +03:00
|
|
|
assert( n!=0 );
|
2004-10-23 09:10:18 +04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
static int keywordCompare2(const void *a, const void *b){
|
|
|
|
const Keyword *pA = (Keyword*)a;
|
|
|
|
const Keyword *pB = (Keyword*)b;
|
2007-05-04 21:07:52 +04:00
|
|
|
int n = pB->longestSuffix - pA->longestSuffix;
|
|
|
|
if( n==0 ){
|
|
|
|
n = strcmp(pA->zName, pB->zName);
|
|
|
|
}
|
2009-11-03 16:08:16 +03:00
|
|
|
assert( n!=0 );
|
2004-10-23 09:10:18 +04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
static int keywordCompare3(const void *a, const void *b){
|
|
|
|
const Keyword *pA = (Keyword*)a;
|
|
|
|
const Keyword *pB = (Keyword*)b;
|
|
|
|
int n = pA->offset - pB->offset;
|
2009-11-03 16:08:16 +03:00
|
|
|
if( n==0 ) n = pB->id - pA->id;
|
|
|
|
assert( n!=0 );
|
2004-10-23 09:10:18 +04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Return a KeywordTable entry with the given id
|
|
|
|
*/
|
|
|
|
static Keyword *findById(int id){
|
|
|
|
int i;
|
2007-05-04 21:07:52 +04:00
|
|
|
for(i=0; i<nKeyword; i++){
|
2004-10-23 09:10:18 +04:00
|
|
|
if( aKeywordTable[i].id==id ) break;
|
|
|
|
}
|
|
|
|
return &aKeywordTable[i];
|
2004-10-07 23:03:01 +04:00
|
|
|
}
|
|
|
|
|
2019-11-01 05:30:54 +03:00
|
|
|
/*
|
|
|
|
** If aKeyword[*pFrom-1].iNext has a higher priority that aKeyword[*pFrom-1]
|
|
|
|
** itself, then swap them.
|
|
|
|
*/
|
|
|
|
static void reorder(int *pFrom){
|
|
|
|
int i = *pFrom - 1;
|
2019-11-01 13:49:15 +03:00
|
|
|
int j;
|
|
|
|
if( i<0 ) return;
|
|
|
|
j = aKeywordTable[i].iNext;
|
2019-11-01 05:30:54 +03:00
|
|
|
if( j==0 ) return;
|
|
|
|
j--;
|
|
|
|
if( aKeywordTable[i].priority >= aKeywordTable[j].priority ) return;
|
|
|
|
aKeywordTable[i].iNext = aKeywordTable[j].iNext;
|
|
|
|
aKeywordTable[j].iNext = i+1;
|
|
|
|
*pFrom = j+1;
|
|
|
|
reorder(&aKeywordTable[i].iNext);
|
|
|
|
}
|
|
|
|
|
2004-10-07 23:03:01 +04:00
|
|
|
/*
|
|
|
|
** This routine does the work. The generated code is printed on standard
|
|
|
|
** output.
|
|
|
|
*/
|
|
|
|
int main(int argc, char **argv){
|
2015-11-17 22:16:39 +03:00
|
|
|
int i, j, k, h;
|
2004-10-07 23:03:01 +04:00
|
|
|
int bestSize, bestCount;
|
|
|
|
int count;
|
|
|
|
int nChar;
|
2007-05-04 21:07:52 +04:00
|
|
|
int totalLen = 0;
|
2017-07-06 19:33:14 +03:00
|
|
|
int aKWHash[1000]; /* 1000 is much bigger than nKeyword */
|
|
|
|
char zKWText[2000];
|
2004-10-07 23:03:01 +04:00
|
|
|
|
2004-11-03 06:59:57 +03:00
|
|
|
/* Remove entries from the list of keywords that have mask==0 */
|
2007-05-04 21:07:52 +04:00
|
|
|
for(i=j=0; i<nKeyword; i++){
|
2004-11-03 06:59:57 +03:00
|
|
|
if( aKeywordTable[i].mask==0 ) continue;
|
|
|
|
if( j<i ){
|
|
|
|
aKeywordTable[j] = aKeywordTable[i];
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
}
|
2007-05-04 21:07:52 +04:00
|
|
|
nKeyword = j;
|
2004-11-03 06:59:57 +03:00
|
|
|
|
2004-10-23 09:10:18 +04:00
|
|
|
/* Fill in the lengths of strings and hashes for all entries. */
|
2007-05-04 21:07:52 +04:00
|
|
|
for(i=0; i<nKeyword; i++){
|
2004-10-07 23:03:01 +04:00
|
|
|
Keyword *p = &aKeywordTable[i];
|
2012-04-18 14:13:20 +04:00
|
|
|
p->len = (int)strlen(p->zName);
|
2009-06-09 18:27:41 +04:00
|
|
|
assert( p->len<sizeof(p->zOrigName) );
|
2014-05-31 19:39:53 +04:00
|
|
|
memcpy(p->zOrigName, p->zName, p->len+1);
|
2007-05-04 21:07:52 +04:00
|
|
|
totalLen += p->len;
|
2015-11-10 06:30:51 +03:00
|
|
|
p->hash = (charMap(p->zName[0])*4) ^
|
|
|
|
(charMap(p->zName[p->len-1])*3) ^ (p->len*1);
|
2004-10-23 09:10:18 +04:00
|
|
|
p->id = i+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort the table from shortest to longest keyword */
|
2007-05-04 21:07:52 +04:00
|
|
|
qsort(aKeywordTable, nKeyword, sizeof(aKeywordTable[0]), keywordCompare1);
|
2004-10-23 09:10:18 +04:00
|
|
|
|
|
|
|
/* Look for short keywords embedded in longer keywords */
|
2007-05-04 21:07:52 +04:00
|
|
|
for(i=nKeyword-2; i>=0; i--){
|
2004-10-23 09:10:18 +04:00
|
|
|
Keyword *p = &aKeywordTable[i];
|
2007-05-04 21:07:52 +04:00
|
|
|
for(j=nKeyword-1; j>i && p->substrId==0; j--){
|
2004-10-23 09:10:18 +04:00
|
|
|
Keyword *pOther = &aKeywordTable[j];
|
|
|
|
if( pOther->substrId ) continue;
|
|
|
|
if( pOther->len<=p->len ) continue;
|
|
|
|
for(k=0; k<=pOther->len-p->len; k++){
|
|
|
|
if( memcmp(p->zName, &pOther->zName[k], p->len)==0 ){
|
|
|
|
p->substrId = pOther->id;
|
|
|
|
p->substrOffset = k;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-04 21:07:52 +04:00
|
|
|
/* Compute the longestSuffix value for every word */
|
|
|
|
for(i=0; i<nKeyword; i++){
|
|
|
|
Keyword *p = &aKeywordTable[i];
|
|
|
|
if( p->substrId ) continue;
|
|
|
|
for(j=0; j<nKeyword; j++){
|
|
|
|
Keyword *pOther;
|
|
|
|
if( j==i ) continue;
|
|
|
|
pOther = &aKeywordTable[j];
|
|
|
|
if( pOther->substrId ) continue;
|
|
|
|
for(k=p->longestSuffix+1; k<p->len && k<pOther->len; k++){
|
|
|
|
if( memcmp(&p->zName[p->len-k], pOther->zName, k)==0 ){
|
|
|
|
p->longestSuffix = k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort the table into reverse order by length */
|
|
|
|
qsort(aKeywordTable, nKeyword, sizeof(aKeywordTable[0]), keywordCompare2);
|
2004-10-23 09:10:18 +04:00
|
|
|
|
|
|
|
/* Fill in the offset for all entries */
|
|
|
|
nChar = 0;
|
2007-05-04 21:07:52 +04:00
|
|
|
for(i=0; i<nKeyword; i++){
|
2004-10-23 09:10:18 +04:00
|
|
|
Keyword *p = &aKeywordTable[i];
|
|
|
|
if( p->offset>0 || p->substrId ) continue;
|
2004-10-07 23:03:01 +04:00
|
|
|
p->offset = nChar;
|
2004-10-23 09:10:18 +04:00
|
|
|
nChar += p->len;
|
|
|
|
for(k=p->len-1; k>=1; k--){
|
2007-05-04 21:07:52 +04:00
|
|
|
for(j=i+1; j<nKeyword; j++){
|
2004-10-23 09:10:18 +04:00
|
|
|
Keyword *pOther = &aKeywordTable[j];
|
|
|
|
if( pOther->offset>0 || pOther->substrId ) continue;
|
|
|
|
if( pOther->len<=k ) continue;
|
|
|
|
if( memcmp(&p->zName[p->len-k], pOther->zName, k)==0 ){
|
|
|
|
p = pOther;
|
|
|
|
p->offset = nChar - k;
|
|
|
|
nChar = p->offset + p->len;
|
|
|
|
p->zName += k;
|
|
|
|
p->len -= k;
|
|
|
|
p->prefix = k;
|
|
|
|
j = i;
|
|
|
|
k = p->len;
|
|
|
|
}
|
|
|
|
}
|
2004-10-07 23:03:01 +04:00
|
|
|
}
|
|
|
|
}
|
2007-05-04 21:07:52 +04:00
|
|
|
for(i=0; i<nKeyword; i++){
|
2004-10-23 09:10:18 +04:00
|
|
|
Keyword *p = &aKeywordTable[i];
|
|
|
|
if( p->substrId ){
|
|
|
|
p->offset = findById(p->substrId)->offset + p->substrOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort the table by offset */
|
2007-05-04 21:07:52 +04:00
|
|
|
qsort(aKeywordTable, nKeyword, sizeof(aKeywordTable[0]), keywordCompare3);
|
2004-10-07 23:03:01 +04:00
|
|
|
|
|
|
|
/* Figure out how big to make the hash table in order to minimize the
|
|
|
|
** number of collisions */
|
2007-05-04 21:07:52 +04:00
|
|
|
bestSize = nKeyword;
|
|
|
|
bestCount = nKeyword*nKeyword;
|
|
|
|
for(i=nKeyword/2; i<=2*nKeyword; i++){
|
2017-07-06 19:33:14 +03:00
|
|
|
for(j=0; j<i; j++) aKWHash[j] = 0;
|
2007-05-04 21:07:52 +04:00
|
|
|
for(j=0; j<nKeyword; j++){
|
2004-10-07 23:03:01 +04:00
|
|
|
h = aKeywordTable[j].hash % i;
|
2017-07-06 19:33:14 +03:00
|
|
|
aKWHash[h] *= 2;
|
|
|
|
aKWHash[h]++;
|
2004-10-07 23:03:01 +04:00
|
|
|
}
|
2017-07-06 19:33:14 +03:00
|
|
|
for(j=count=0; j<i; j++) count += aKWHash[j];
|
2004-10-07 23:03:01 +04:00
|
|
|
if( count<bestCount ){
|
|
|
|
bestCount = count;
|
|
|
|
bestSize = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute the hash */
|
2017-07-06 19:33:14 +03:00
|
|
|
for(i=0; i<bestSize; i++) aKWHash[i] = 0;
|
2007-05-04 21:07:52 +04:00
|
|
|
for(i=0; i<nKeyword; i++){
|
2004-10-07 23:03:01 +04:00
|
|
|
h = aKeywordTable[i].hash % bestSize;
|
2017-07-06 19:33:14 +03:00
|
|
|
aKeywordTable[i].iNext = aKWHash[h];
|
|
|
|
aKWHash[h] = i+1;
|
2019-11-01 05:30:54 +03:00
|
|
|
reorder(&aKWHash[h]);
|
2004-10-07 23:03:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Begin generating code */
|
2007-02-21 19:44:33 +03:00
|
|
|
printf("%s", zHdr);
|
2005-02-01 04:40:44 +03:00
|
|
|
printf("/* Hash score: %d */\n", bestCount);
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("/* zKWText[] encodes %d bytes of keyword text in %d bytes */\n",
|
2007-05-04 21:07:52 +04:00
|
|
|
totalLen + nKeyword, nChar+1 );
|
2008-12-08 21:19:17 +03:00
|
|
|
for(i=j=k=0; i<nKeyword; i++){
|
2004-10-07 23:03:01 +04:00
|
|
|
Keyword *p = &aKeywordTable[i];
|
2004-10-23 09:10:18 +04:00
|
|
|
if( p->substrId ) continue;
|
2017-07-06 19:33:14 +03:00
|
|
|
memcpy(&zKWText[k], p->zName, p->len);
|
2008-12-08 21:19:17 +03:00
|
|
|
k += p->len;
|
|
|
|
if( j+p->len>70 ){
|
|
|
|
printf("%*s */\n", 74-j, "");
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
if( j==0 ){
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("/* ");
|
2008-12-08 21:19:17 +03:00
|
|
|
j = 8;
|
|
|
|
}
|
2004-10-07 23:03:01 +04:00
|
|
|
printf("%s", p->zName);
|
|
|
|
j += p->len;
|
2008-12-08 21:19:17 +03:00
|
|
|
}
|
|
|
|
if( j>0 ){
|
|
|
|
printf("%*s */\n", 74-j, "");
|
|
|
|
}
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("static const char zKWText[%d] = {\n", nChar);
|
|
|
|
zKWText[nChar] = 0;
|
2009-01-01 00:52:40 +03:00
|
|
|
for(i=j=0; i<k; i++){
|
2008-12-08 21:19:17 +03:00
|
|
|
if( j==0 ){
|
2017-07-06 19:33:14 +03:00
|
|
|
printf(" ");
|
2008-12-08 21:19:17 +03:00
|
|
|
}
|
2017-07-06 19:33:14 +03:00
|
|
|
if( zKWText[i]==0 ){
|
2008-12-08 21:19:17 +03:00
|
|
|
printf("0");
|
|
|
|
}else{
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("'%c',", zKWText[i]);
|
2008-12-08 21:19:17 +03:00
|
|
|
}
|
|
|
|
j += 4;
|
|
|
|
if( j>68 ){
|
|
|
|
printf("\n");
|
2004-10-07 23:03:01 +04:00
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
2008-12-08 21:19:17 +03:00
|
|
|
if( j>0 ) printf("\n");
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("};\n");
|
2004-10-07 23:03:01 +04:00
|
|
|
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("/* aKWHash[i] is the hash value for the i-th keyword */\n");
|
|
|
|
printf("static const unsigned char aKWHash[%d] = {\n", bestSize);
|
2004-10-07 23:03:01 +04:00
|
|
|
for(i=j=0; i<bestSize; i++){
|
2017-07-06 19:33:14 +03:00
|
|
|
if( j==0 ) printf(" ");
|
|
|
|
printf(" %3d,", aKWHash[i]);
|
2004-10-07 23:03:01 +04:00
|
|
|
j++;
|
|
|
|
if( j>12 ){
|
|
|
|
printf("\n");
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("%s};\n", j==0 ? "" : "\n");
|
2004-10-07 23:03:01 +04:00
|
|
|
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("/* aKWNext[] forms the hash collision chain. If aKWHash[i]==0\n");
|
|
|
|
printf("** then the i-th keyword has no more hash collisions. Otherwise,\n");
|
|
|
|
printf("** the next keyword with the same hash is aKWHash[i]-1. */\n");
|
|
|
|
printf("static const unsigned char aKWNext[%d] = {\n", nKeyword);
|
2007-05-04 21:07:52 +04:00
|
|
|
for(i=j=0; i<nKeyword; i++){
|
2017-07-06 19:33:14 +03:00
|
|
|
if( j==0 ) printf(" ");
|
2004-10-07 23:03:01 +04:00
|
|
|
printf(" %3d,", aKeywordTable[i].iNext);
|
|
|
|
j++;
|
|
|
|
if( j>12 ){
|
|
|
|
printf("\n");
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("%s};\n", j==0 ? "" : "\n");
|
2004-10-07 23:03:01 +04:00
|
|
|
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("/* aKWLen[i] is the length (in bytes) of the i-th keyword */\n");
|
|
|
|
printf("static const unsigned char aKWLen[%d] = {\n", nKeyword);
|
2007-05-04 21:07:52 +04:00
|
|
|
for(i=j=0; i<nKeyword; i++){
|
2017-07-06 19:33:14 +03:00
|
|
|
if( j==0 ) printf(" ");
|
2004-10-23 09:10:18 +04:00
|
|
|
printf(" %3d,", aKeywordTable[i].len+aKeywordTable[i].prefix);
|
2004-10-07 23:03:01 +04:00
|
|
|
j++;
|
|
|
|
if( j>12 ){
|
|
|
|
printf("\n");
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("%s};\n", j==0 ? "" : "\n");
|
2004-10-07 23:03:01 +04:00
|
|
|
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("/* aKWOffset[i] is the index into zKWText[] of the start of\n");
|
|
|
|
printf("** the text for the i-th keyword. */\n");
|
|
|
|
printf("static const unsigned short int aKWOffset[%d] = {\n", nKeyword);
|
2007-05-04 21:07:52 +04:00
|
|
|
for(i=j=0; i<nKeyword; i++){
|
2017-07-06 19:33:14 +03:00
|
|
|
if( j==0 ) printf(" ");
|
2004-10-07 23:03:01 +04:00
|
|
|
printf(" %3d,", aKeywordTable[i].offset);
|
|
|
|
j++;
|
|
|
|
if( j>12 ){
|
|
|
|
printf("\n");
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("%s};\n", j==0 ? "" : "\n");
|
2004-10-07 23:03:01 +04:00
|
|
|
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("/* aKWCode[i] is the parser symbol code for the i-th keyword */\n");
|
|
|
|
printf("static const unsigned char aKWCode[%d] = {\n", nKeyword);
|
2007-05-04 21:07:52 +04:00
|
|
|
for(i=j=0; i<nKeyword; i++){
|
2004-10-07 23:03:01 +04:00
|
|
|
char *zToken = aKeywordTable[i].zTokenType;
|
2017-07-06 19:33:14 +03:00
|
|
|
if( j==0 ) printf(" ");
|
2004-10-07 23:03:01 +04:00
|
|
|
printf("%s,%*s", zToken, (int)(14-strlen(zToken)), "");
|
|
|
|
j++;
|
|
|
|
if( j>=5 ){
|
|
|
|
printf("\n");
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("%s};\n", j==0 ? "" : "\n");
|
2019-11-01 05:30:54 +03:00
|
|
|
printf("/* Hash table decoded:\n");
|
|
|
|
for(i=0; i<bestSize; i++){
|
|
|
|
j = aKWHash[i];
|
|
|
|
printf("** %3d:", i);
|
|
|
|
while( j ){
|
|
|
|
printf(" %s", aKeywordTable[j-1].zOrigName);
|
|
|
|
j = aKeywordTable[j-1].iNext;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
printf("*/\n");
|
2017-07-06 19:33:14 +03:00
|
|
|
printf("/* Check to see if z[0..n-1] is a keyword. If it is, write the\n");
|
|
|
|
printf("** parser symbol code for that keyword into *pType. Always\n");
|
|
|
|
printf("** return the integer n (the length of the token). */\n");
|
|
|
|
printf("static int keywordCode(const char *z, int n, int *pType){\n");
|
2016-02-08 22:15:48 +03:00
|
|
|
printf(" int i, j;\n");
|
2016-02-08 06:23:46 +03:00
|
|
|
printf(" const char *zKW;\n");
|
2015-11-10 06:30:51 +03:00
|
|
|
printf(" if( n>=2 ){\n");
|
2016-02-08 22:15:48 +03:00
|
|
|
printf(" i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n) %% %d;\n",
|
2015-11-10 06:30:51 +03:00
|
|
|
bestSize);
|
2017-07-06 19:33:14 +03:00
|
|
|
printf(" for(i=((int)aKWHash[i])-1; i>=0; i=((int)aKWNext[i])-1){\n");
|
|
|
|
printf(" if( aKWLen[i]!=n ) continue;\n");
|
|
|
|
printf(" zKW = &zKWText[aKWOffset[i]];\n");
|
2016-02-08 22:15:48 +03:00
|
|
|
printf("#ifdef SQLITE_ASCII\n");
|
2020-02-06 18:38:43 +03:00
|
|
|
printf(" if( (z[0]&~0x20)!=zKW[0] ) continue;\n");
|
|
|
|
printf(" if( (z[1]&~0x20)!=zKW[1] ) continue;\n");
|
|
|
|
printf(" j = 2;\n");
|
2016-02-08 06:23:46 +03:00
|
|
|
printf(" while( j<n && (z[j]&~0x20)==zKW[j] ){ j++; }\n");
|
2016-02-08 22:15:48 +03:00
|
|
|
printf("#endif\n");
|
|
|
|
printf("#ifdef SQLITE_EBCDIC\n");
|
2020-02-06 18:38:43 +03:00
|
|
|
printf(" if( toupper(z[0])!=zKW[0] ) continue;\n");
|
|
|
|
printf(" if( toupper(z[1])!=zKW[1] ) continue;\n");
|
|
|
|
printf(" j = 2;\n");
|
2016-02-08 22:15:48 +03:00
|
|
|
printf(" while( j<n && toupper(z[j])==zKW[j] ){ j++; }\n");
|
|
|
|
printf("#endif\n");
|
2016-02-08 06:23:46 +03:00
|
|
|
printf(" if( j<n ) continue;\n");
|
2009-01-01 00:52:40 +03:00
|
|
|
for(i=0; i<nKeyword; i++){
|
2016-02-08 06:23:46 +03:00
|
|
|
printf(" testcase( i==%d ); /* %s */\n",
|
2009-06-09 18:27:41 +04:00
|
|
|
i, aKeywordTable[i].zOrigName);
|
2009-01-01 00:52:40 +03:00
|
|
|
}
|
2017-07-06 19:33:14 +03:00
|
|
|
printf(" *pType = aKWCode[i];\n");
|
2016-02-08 06:23:46 +03:00
|
|
|
printf(" break;\n");
|
2004-10-07 23:03:01 +04:00
|
|
|
printf(" }\n");
|
|
|
|
printf(" }\n");
|
2015-11-10 06:30:51 +03:00
|
|
|
printf(" return n;\n");
|
2004-10-07 23:03:01 +04:00
|
|
|
printf("}\n");
|
2005-12-09 23:02:05 +03:00
|
|
|
printf("int sqlite3KeywordCode(const unsigned char *z, int n){\n");
|
2015-11-10 06:30:51 +03:00
|
|
|
printf(" int id = TK_ID;\n");
|
|
|
|
printf(" keywordCode((char*)z, n, &id);\n");
|
|
|
|
printf(" return id;\n");
|
2005-01-31 15:42:29 +03:00
|
|
|
printf("}\n");
|
2010-01-02 06:21:35 +03:00
|
|
|
printf("#define SQLITE_N_KEYWORD %d\n", nKeyword);
|
2018-04-25 22:02:48 +03:00
|
|
|
printf("int sqlite3_keyword_name(int i,const char **pzName,int *pnName){\n");
|
|
|
|
printf(" if( i<0 || i>=SQLITE_N_KEYWORD ) return SQLITE_ERROR;\n");
|
|
|
|
printf(" *pzName = zKWText + aKWOffset[i];\n");
|
|
|
|
printf(" *pnName = aKWLen[i];\n");
|
|
|
|
printf(" return SQLITE_OK;\n");
|
|
|
|
printf("}\n");
|
|
|
|
printf("int sqlite3_keyword_count(void){ return SQLITE_N_KEYWORD; }\n");
|
|
|
|
printf("int sqlite3_keyword_check(const char *zName, int nName){\n");
|
|
|
|
printf(" return TK_ID!=sqlite3KeywordCode((const u8*)zName, nName);\n");
|
|
|
|
printf("}\n");
|
2004-10-07 23:03:01 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|