⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sql.c

📁 ctags的最新版5.7,可以比较5.6版看看,免费下载
💻 C
📖 第 1 页 / 共 3 页
字号:
			makeSqlTag (name, SQLTAG_PACKAGE);		parseBlock (token, FALSE);	}	findCmdTerm (token, FALSE);	deleteToken (name);}static void parseTable (tokenInfo *const token){	tokenInfo *const name = newToken ();	/*	 * This deals with these formats:	 *	   create table t1 (c1 int);	 *	   create global tempoary table t2 (c1 int);	 *	   create table "t3" (c1 int);	 *	   create table bob.t4 (c1 int);	 *	   create table bob."t5" (c1 int);	 *	   create table "bob"."t6" (c1 int);	 *	   create table bob."t7" (c1 int);	 * Proxy tables use this format:	 *	   create existing table bob."t7" AT '...';	 */	readToken (name);	readToken (token);	if (isType (token, TOKEN_PERIOD))	{		readToken (name);		readToken (token);	}	if (isType (token, TOKEN_OPEN_PAREN))	{		if (isType (name, TOKEN_IDENTIFIER) ||				isType (name, TOKEN_STRING))		{			makeSqlTag (name, SQLTAG_TABLE);			vStringCopy(token->scope, name->string);			parseRecord (token);			vStringClear (token->scope);		}	} 	else if (isKeyword (token, KEYWORD_at))	{		if (isType (name, TOKEN_IDENTIFIER))		{			makeSqlTag (name, SQLTAG_TABLE);		}	}	findCmdTerm (token, FALSE);	deleteToken (name);}static void parseIndex (tokenInfo *const token){	tokenInfo *const name  = newToken ();	tokenInfo *const owner = newToken ();	/*	 * This deals with these formats	 *	   create index i1 on t1(c1) create index "i2" on t1(c1) 	 *	   create virtual unique clustered index "i3" on t1(c1) 	 *	   create unique clustered index "i4" on t1(c1) 	 *	   create clustered index "i5" on t1(c1) 	 *	   create bitmap index "i6" on t1(c1)	 */	readToken (name);	readToken (token);	if (isType (token, TOKEN_PERIOD))	{		readToken (name);		readToken (token);	}	if ( isKeyword (token, KEYWORD_on) &&			(isType (name, TOKEN_IDENTIFIER) || isType (name, TOKEN_STRING) ) )	{		readToken (owner);		readToken (token);		if (isType (token, TOKEN_PERIOD))		{			readToken (owner);			readToken (token);		}		addToScope(name, owner->string);		makeSqlTag (name, SQLTAG_INDEX);	}	findCmdTerm (token, FALSE);	deleteToken (name);	deleteToken (owner);}static void parseEvent (tokenInfo *const token){	tokenInfo *const name = newToken ();	/*	 * This deals with these formats	 *	   create event e1 handler begin end;	 *	   create event "e2" handler begin end;	 *	   create event dba."e3" handler begin end;	 *	   create event "dba"."e4" handler begin end;	 */	readToken (name);	readToken (token);	if (isType (token, TOKEN_PERIOD))	{		readToken (name);	}	while (! (isKeyword (token, KEYWORD_handler) ||				(isType (token, TOKEN_SEMICOLON)))	  )	{		readToken (token);	}	if ( isKeyword (token, KEYWORD_handler) ||			isType (token, TOKEN_SEMICOLON)   )	{		makeSqlTag (name, SQLTAG_EVENT);	}	if (isKeyword (token, KEYWORD_handler))	{		readToken (token);		if ( isKeyword (token, KEYWORD_begin) )		{			parseBlock (token, TRUE);		}		findCmdTerm (token, FALSE);	}	deleteToken (name);}static void parseTrigger (tokenInfo *const token){	tokenInfo *const name  = newToken ();	tokenInfo *const table = newToken ();	/*	 * This deals with these formats	 *	   create or replace trigger tr1 begin end;	 *	   create trigger "tr2" begin end;	 *	   drop trigger "droptr1";	 *	   create trigger "tr3" CALL sp_something();	 *	   create trigger "owner"."tr4" begin end;	 *	   create trigger "tr5" not valid;	 *	   create trigger "tr6" begin end;	 */	readToken (name);	readToken (token);	if (isType (token, TOKEN_PERIOD))	{		readToken (name);		readToken (token);	}	while ( !isKeyword (token, KEYWORD_on) &&			!isCmdTerm (token)		)	{		readToken (token);	}	/*if (! isType (token, TOKEN_SEMICOLON) ) */	if (! isCmdTerm (token) )	{		readToken (table);		readToken (token);		if (isType (token, TOKEN_PERIOD))		{			readToken (table);			readToken (token);		}		while (! (isKeyword (token, KEYWORD_begin) ||					(isKeyword (token, KEYWORD_call)) ||					(	isCmdTerm (token)))    )		{			readToken (token);			if ( isKeyword (token, KEYWORD_declare) )			{				addToScope(token, name->string);				parseDeclare(token, TRUE);				vStringClear(token->scope);			}		}		if ( isKeyword (token, KEYWORD_begin) || 				isKeyword (token, KEYWORD_call)   )		{			addToScope(name, table->string);			makeSqlTag (name, SQLTAG_TRIGGER);			addToScope(token, table->string);			if ( isKeyword (token, KEYWORD_begin) )			{				parseBlock (token, TRUE);			}			vStringClear(token->scope);		}	}	findCmdTerm (token, TRUE);	deleteToken (name);	deleteToken (table);}static void parsePublication (tokenInfo *const token){	tokenInfo *const name = newToken ();	/*	 * This deals with these formats	 *	   create or replace publication pu1 ()	 *	   create publication "pu2" ()	 *	   create publication dba."pu3" ()	 *	   create publication "dba"."pu4" ()	 */	readToken (name);	readToken (token);	if (isType (token, TOKEN_PERIOD))	{		readToken (name);		readToken (token);	}	if (isType (token, TOKEN_OPEN_PAREN))	{		if (isType (name, TOKEN_IDENTIFIER) ||				isType (name, TOKEN_STRING))		{			makeSqlTag (name, SQLTAG_PUBLICATION);		}	}	findCmdTerm (token, FALSE);	deleteToken (name);}static void parseService (tokenInfo *const token){	tokenInfo *const name = newToken ();	/*	 * This deals with these formats	 *	   CREATE SERVICE s1 TYPE 'HTML' 	 *		   AUTHORIZATION OFF USER DBA AS 	 *		   SELECT * 	 *			 FROM SYS.SYSTABLE;	 *	   CREATE SERVICE "s2" TYPE 'HTML'	 *		   AUTHORIZATION OFF USER DBA AS 	 *		   CALL sp_Something();	 */	readToken (name);	readToken (token);	if (isKeyword (token, KEYWORD_type))	{		if (isType (name, TOKEN_IDENTIFIER) ||				isType (name, TOKEN_STRING))		{			makeSqlTag (name, SQLTAG_SERVICE);		}	}	findCmdTerm (token, FALSE);	deleteToken (name);}static void parseDomain (tokenInfo *const token){	tokenInfo *const name = newToken ();	/*	 * This deals with these formats	 *	   CREATE DOMAIN|DATATYPE [AS] your_name ...;	 */	readToken (name);	if (isKeyword (name, KEYWORD_is))	{		readToken (name);	}	readToken (token);	if (isType (name, TOKEN_IDENTIFIER) ||			isType (name, TOKEN_STRING))	{		makeSqlTag (name, SQLTAG_DOMAIN);	}	findCmdTerm (token, FALSE);	deleteToken (name);}static void parseDrop (tokenInfo *const token){	/*	 * This deals with these formats	 *	   DROP TABLE|PROCEDURE|DOMAIN|DATATYPE name;	 *	 * Just simply skip over these statements.	 * They are often confused with PROCEDURE prototypes	 * since the syntax is similar, this effectively deals with	 * the issue for all types.	 */	findCmdTerm (token, FALSE);}static void parseVariable (tokenInfo *const token){	tokenInfo *const name = newToken ();	/*	 * This deals with these formats	 *	   create variable varname1 integer;	 *	   create variable @varname2 integer;	 *	   create variable "varname3" integer;	 *	   drop   variable @varname3;	 */	readToken (name);	readToken (token);	if ( (isType (name, TOKEN_IDENTIFIER) || isType (name, TOKEN_STRING))			&& !isType (token, TOKEN_SEMICOLON) )	{		makeSqlTag (name, SQLTAG_VARIABLE);	}	findCmdTerm (token, TRUE);	deleteToken (name);}static void parseSynonym (tokenInfo *const token){	tokenInfo *const name = newToken ();	/*	 * This deals with these formats	 *	   create variable varname1 integer;	 *	   create variable @varname2 integer;	 *	   create variable "varname3" integer;	 *	   drop   variable @varname3;	 */	readToken (name);	readToken (token);	if ( (isType (name, TOKEN_IDENTIFIER) || isType (name, TOKEN_STRING))			&& isKeyword (token, KEYWORD_for) )	{		makeSqlTag (name, SQLTAG_SYNONYM);	}	findCmdTerm (token, TRUE);	deleteToken (name);}static void parseView (tokenInfo *const token){	tokenInfo *const name = newToken ();	/*	 * This deals with these formats	 *	   create variable varname1 integer;	 *	   create variable @varname2 integer;	 *	   create variable "varname3" integer;	 *	   drop   variable @varname3;	 */	readToken (name);	readToken (token);	if (isType (token, TOKEN_PERIOD))	{		readToken (name);		readToken (token);	}	if ( isType (token, TOKEN_OPEN_PAREN) )	{		skipArgumentList(token);	}	while (!(isKeyword (token, KEYWORD_is) ||				isType (token, TOKEN_SEMICOLON)			))	{		readToken (token);	}	if ( (isType (name, TOKEN_IDENTIFIER) || isType (name, TOKEN_STRING))			&& isKeyword (token, KEYWORD_is) )	{		makeSqlTag (name, SQLTAG_VIEW);	}	findCmdTerm (token, TRUE);	deleteToken (name);}static void parseMLTable (tokenInfo *const token){	tokenInfo *const version = newToken ();	tokenInfo *const table	 = newToken ();	tokenInfo *const event	 = newToken ();	/*	 * This deals with these formats	 *	  call dbo.ml_add_table_script( 'version', 'table_name', 'event',	 *		   'some SQL statement'	 *		   );	 */	readToken (token);	if ( isType (token, TOKEN_OPEN_PAREN) )	{		readToken (version);		readToken (token);		while (!(isType (token, TOKEN_COMMA) ||					isType (token, TOKEN_CLOSE_PAREN)				))		{			readToken (token);		}		if (isType (token, TOKEN_COMMA))		{			readToken (table);			readToken (token);			while (!(isType (token, TOKEN_COMMA) ||						isType (token, TOKEN_CLOSE_PAREN)					))			{				readToken (token);			}			if (isType (token, TOKEN_COMMA))			{				readToken (event);				if (isType (version, TOKEN_STRING) && 						isType (table, TOKEN_STRING) && 						isType (event, TOKEN_STRING) )				{					addToScope(version, table->string);					addToScope(version, event->string);					makeSqlTag (version, SQLTAG_MLTABLE);				}			} 			if( !isType (token, TOKEN_CLOSE_PAREN) )				findToken (token, TOKEN_CLOSE_PAREN);		} 	}	findCmdTerm (token, TRUE);	deleteToken (version);	deleteToken (table);	deleteToken (event);}static void parseMLConn (tokenInfo *const token){	tokenInfo *const version = newToken ();	tokenInfo *const event	 = newToken ();	/*	 * This deals with these formats	 *	  call ml_add_connection_script( 'version', 'event',	 *		   'some SQL statement'	 *		   );	 */	readToken (token);	if ( isType (token, TOKEN_OPEN_PAREN) )	{		readToken (version);		readToken (token);		while (!(isType (token, TOKEN_COMMA) ||					isType (token, TOKEN_CLOSE_PAREN)				))		{			readToken (token);		}		if (isType (token, TOKEN_COMMA))		{			readToken (event);			if (isType (version, TOKEN_STRING) && 					isType (event, TOKEN_STRING) )			{				addToScope(version, event->string);				makeSqlTag (version, SQLTAG_MLCONN);			}		} 		if( !isType (token, TOKEN_CLOSE_PAREN) )			findToken (token, TOKEN_CLOSE_PAREN);	}	findCmdTerm (token, TRUE);	deleteToken (version);	deleteToken (event);}static void parseComment (tokenInfo *const token){	/*	 * This deals with this statement:	 *	   COMMENT TO PRESERVE FORMAT ON PROCEDURE "DBA"."test" IS 	 *	   {create PROCEDURE DBA."test"()	 *	   BEGIN	 *		signal dave;	 *	   END	 *	   }	 *	   ;	 * The comment can contain anything between the CURLY	 * braces	 *	   COMMENT ON USER "admin" IS	 *			'Administration Group'	 *			;	 * Or it could be a simple string with no curly braces	 */	while (! isKeyword (token, KEYWORD_is))	{		readToken (token);	}	readToken (token);	if ( isType(token, TOKEN_OPEN_CURLY) )	{		findToken (token, TOKEN_CLOSE_CURLY);	}	findCmdTerm (token, TRUE);}static void parseSqlFile (tokenInfo *const token){	do	{		readToken (token);		if (isType (token, TOKEN_BLOCK_LABEL_BEGIN))			parseLabel (token);		else switch (token->keyword)		{			case KEYWORD_begin:			parseBlock (token, FALSE); break;			case KEYWORD_comment:		parseComment (token); break;			case KEYWORD_cursor:		parseSimple (token, SQLTAG_CURSOR); break;			case KEYWORD_datatype:		parseDomain (token); break;			case KEYWORD_declare:		parseBlock (token, FALSE); break;			case KEYWORD_domain:		parseDomain (token); break;			case KEYWORD_drop:			parseDrop (token); break;			case KEYWORD_event:			parseEvent (token); break;			case KEYWORD_function:		parseSubProgram (token); break;			case KEYWORD_index:			parseIndex (token); break;			case KEYWORD_ml_table:		parseMLTable (token); break;			case KEYWORD_ml_table_lang: parseMLTable (token); break;			case KEYWORD_ml_table_dnet: parseMLTable (token); break;			case KEYWORD_ml_table_java: parseMLTable (token); break;			case KEYWORD_ml_table_chk:  parseMLTable (token); break;			case KEYWORD_ml_conn:		parseMLConn (token); break;			case KEYWORD_ml_conn_lang:	parseMLConn (token); break;			case KEYWORD_ml_conn_dnet:	parseMLConn (token); break;			case KEYWORD_ml_conn_java:	parseMLConn (token); break;			case KEYWORD_ml_conn_chk:	parseMLConn (token); break;			case KEYWORD_package:		parsePackage (token); break;			case KEYWORD_procedure:		parseSubProgram (token); break;			case KEYWORD_publication:	parsePublication (token); break;			case KEYWORD_service:		parseService (token); break;			case KEYWORD_subtype:		parseSimple (token, SQLTAG_SUBTYPE); break;			case KEYWORD_synonym:		parseSynonym (token); break;			case KEYWORD_table:			parseTable (token); break;			case KEYWORD_trigger:		parseTrigger (token); break;			case KEYWORD_type:			parseType (token); break;			case KEYWORD_variable:		parseVariable (token); break;			case KEYWORD_view:			parseView (token); break;			default:				    break;		}	} while (! isKeyword (token, KEYWORD_end));}static void initialize (const langType language){	Assert (sizeof (SqlKinds) / sizeof (SqlKinds [0]) == SQLTAG_COUNT);	Lang_sql = language;	buildSqlKeywordHash ();}static void findSqlTags (void){	tokenInfo *const token = newToken ();	exception_t exception = (exception_t) (setjmp (Exception));	while (exception == ExceptionNone)		parseSqlFile (token);	deleteToken (token);}extern parserDefinition* SqlParser (void){	static const char *const extensions [] = { "sql", NULL };	parserDefinition* def = parserNew ("SQL");	def->kinds		= SqlKinds;	def->kindCount	= KIND_COUNT (SqlKinds);	def->extensions = extensions;	def->parser		= findSqlTags;	def->initialize = initialize;	return def;}/* vi:set tabstop=4 shiftwidth=4 noexpandtab: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -