1 %{
2 #include "yysphinxql.h"
3 
4 #if USE_WINDOWS
5 #pragma warning(push,1)
6 #endif
7 
8 // warning, lexer generator dependent!
9 // this macro relies on that in flex yytext points to the actual location in the buffer
10 #define YYSTOREBOUNDS \
11 	{ \
12 		lvalp->m_iStart = yytext - pParser->m_pBuf; \
13 		lvalp->m_iEnd = lvalp->m_iStart + yyleng; \
14 		pParser->m_pLastTokenStart = yytext; \
15 	}
16 
17 %}
18 
19 DIGIT				[0-9]
20 ID					[a-zA-Z_][a-zA-Z_0-9]*
21 SPACE				[ \t\n\r]
22 
23 %option noyywrap
24 %option nounput
25 %option reentrant
26 
27 %x ccomment
28 
29 %%
30 
31 "/*"         		{ BEGIN(ccomment); }
32 <ccomment>.			{ }
33 <ccomment>"*/"		{ BEGIN(INITIAL); }
34 
35 "AND"				{ YYSTOREBOUNDS; return TOK_AND; }
36 "AS"				{ YYSTOREBOUNDS; return TOK_AS; }
37 "ASC"				{ YYSTOREBOUNDS; return TOK_ASC; }
38 "ATTACH"			{ YYSTOREBOUNDS; return TOK_ATTACH; }
39 "AVG"				{ YYSTOREBOUNDS; return TOK_AVG; }
40 "BEGIN"				{ YYSTOREBOUNDS; return TOK_BEGIN; }
41 "BETWEEN"			{ YYSTOREBOUNDS; return TOK_BETWEEN; }
42 "BIGINT"			{ YYSTOREBOUNDS; return TOK_BIGINT; }
43 "BY"				{ YYSTOREBOUNDS; return TOK_BY; }
44 "CALL"				{ YYSTOREBOUNDS; return TOK_CALL; }
45 "COLLATION"			{ YYSTOREBOUNDS; return TOK_COLLATION; }
46 "COMMIT"			{ YYSTOREBOUNDS; return TOK_COMMIT; }
47 "COMMITTED"			{ YYSTOREBOUNDS; return TOK_COMMITTED; }
48 "COUNT"				{ YYSTOREBOUNDS; return TOK_COUNT; }
49 "CREATE"			{ YYSTOREBOUNDS; return TOK_CREATE; }
50 "DELETE"			{ YYSTOREBOUNDS; return TOK_DELETE; }
51 "DESC"				{ YYSTOREBOUNDS; return TOK_DESC; }
52 "DESCRIBE"			{ YYSTOREBOUNDS; return TOK_DESCRIBE; }
53 "DISTINCT"			{ YYSTOREBOUNDS; return TOK_DISTINCT; }
54 "DIV"				{ YYSTOREBOUNDS; return TOK_DIV; }
55 "DROP"				{ YYSTOREBOUNDS; return TOK_DROP; }
56 "FALSE"				{ YYSTOREBOUNDS; return TOK_FALSE; }
57 "FLOAT"				{ YYSTOREBOUNDS; return TOK_FLOAT; }
58 "FLUSH"				{ YYSTOREBOUNDS; return TOK_FLUSH; }
59 "FROM"				{ YYSTOREBOUNDS; return TOK_FROM; }
60 "FUNCTION"			{ YYSTOREBOUNDS; return TOK_FUNCTION; }
61 "GLOBAL"			{ YYSTOREBOUNDS; return TOK_GLOBAL; }
62 "GROUP"				{ YYSTOREBOUNDS; return TOK_GROUP; }
63 "ID"				{ YYSTOREBOUNDS; return TOK_ID; }
64 "IN"				{ YYSTOREBOUNDS; return TOK_IN; }
65 "INDEX"				{ YYSTOREBOUNDS; return TOK_INDEX; }
66 "INSERT"			{ YYSTOREBOUNDS; return TOK_INSERT; }
67 "INT"				{ YYSTOREBOUNDS; return TOK_INT; }
68 "INTO"				{ YYSTOREBOUNDS; return TOK_INTO; }
69 "ISOLATION"			{ YYSTOREBOUNDS; return TOK_ISOLATION; }
70 "LEVEL"				{ YYSTOREBOUNDS; return TOK_LEVEL; }
71 "LIMIT"				{ YYSTOREBOUNDS; return TOK_LIMIT; }
72 "MATCH"				{ YYSTOREBOUNDS; return TOK_MATCH; }
73 "MAX"				{ YYSTOREBOUNDS; return TOK_MAX; }
74 "META"				{ YYSTOREBOUNDS; return TOK_META; }
75 "MIN"				{ YYSTOREBOUNDS; return TOK_MIN; }
76 "MOD"				{ YYSTOREBOUNDS; return TOK_MOD; }
77 "NAMES"				{ YYSTOREBOUNDS; return TOK_NAMES; }
78 "NOT"				{ YYSTOREBOUNDS; return TOK_NOT; }
79 "NULL"				{ YYSTOREBOUNDS; return TOK_NULL; }
80 "OPTION"			{ YYSTOREBOUNDS; return TOK_OPTION; }
81 "OR"				{ YYSTOREBOUNDS; return TOK_OR; }
82 "ORDER"				{ YYSTOREBOUNDS; return TOK_ORDER; }
83 "RAND"				{ YYSTOREBOUNDS; return TOK_RAND; }
84 "READ"				{ YYSTOREBOUNDS; return TOK_READ; }
85 "REPEATABLE"		{ YYSTOREBOUNDS; return TOK_REPEATABLE; }
86 "REPLACE"			{ YYSTOREBOUNDS; return TOK_REPLACE; }
87 "RETURNS"			{ YYSTOREBOUNDS; return TOK_RETURNS; }
88 "ROLLBACK"			{ YYSTOREBOUNDS; return TOK_ROLLBACK; }
89 "RTINDEX"			{ YYSTOREBOUNDS; return TOK_RTINDEX; }
90 "SELECT"			{ YYSTOREBOUNDS; return TOK_SELECT; }
91 "SERIALIZABLE"		{ YYSTOREBOUNDS; return TOK_SERIALIZABLE; }
92 "SET"				{ YYSTOREBOUNDS; return TOK_SET; }
93 "SESSION"			{ YYSTOREBOUNDS; return TOK_SESSION; }
94 "SHOW"				{ YYSTOREBOUNDS; return TOK_SHOW; }
95 "SONAME"			{ YYSTOREBOUNDS; return TOK_SONAME; }
96 "START"				{ YYSTOREBOUNDS; return TOK_START; }
97 "STATUS"			{ YYSTOREBOUNDS; return TOK_STATUS; }
98 "SUM"				{ YYSTOREBOUNDS; return TOK_SUM; }
99 "TABLES"			{ YYSTOREBOUNDS; return TOK_TABLES; }
100 "TO"				{ YYSTOREBOUNDS; return TOK_TO; }
101 "TRANSACTION"		{ YYSTOREBOUNDS; return TOK_TRANSACTION; }
102 "TRUE"				{ YYSTOREBOUNDS; return TOK_TRUE; }
103 "UNCOMMITTED"		{ YYSTOREBOUNDS; return TOK_UNCOMMITTED; }
104 "UPDATE"			{ YYSTOREBOUNDS; return TOK_UPDATE; }
105 "VALUES"			{ YYSTOREBOUNDS; return TOK_VALUES; }
106 "VARIABLES"			{ YYSTOREBOUNDS; return TOK_VARIABLES; }
107 "WARNINGS"			{ YYSTOREBOUNDS; return TOK_WARNINGS; }
108 "WEIGHT"			{ YYSTOREBOUNDS; return TOK_WEIGHT; }
109 "WHERE"				{ YYSTOREBOUNDS; return TOK_WHERE; }
110 "WITHIN"			{ YYSTOREBOUNDS; return TOK_WITHIN; }
111 
112 "!="				{ YYSTOREBOUNDS; return TOK_NE; }
113 "<>"				{ YYSTOREBOUNDS; return TOK_NE; }
114 "<="				{ YYSTOREBOUNDS; return TOK_LTE; }
115 ">="				{ YYSTOREBOUNDS; return TOK_GTE; }
116 ":="				{ YYSTOREBOUNDS; return '='; }
117 
118 '([^'\\]|\\.|\\\\)*'	{ YYSTOREBOUNDS; SqlUnescape ( lvalp->m_sValue, yytext, yyleng ); return TOK_QUOTED_STRING; }
119 
120 {DIGIT}*\.{DIGIT}*	{ YYSTOREBOUNDS; lvalp->m_sValue = yytext; lvalp->m_fValue = (float)strtod ( yytext, NULL ); return TOK_CONST_FLOAT; }
121 {DIGIT}+			{ YYSTOREBOUNDS; lvalp->m_sValue = yytext; lvalp->m_iValue = (int64_t)strtoull ( yytext, NULL, 10 ); return TOK_CONST_INT; }
122 
123 "@id"				{ YYSTOREBOUNDS; lvalp->m_sValue = yytext; return TOK_ATIDENT; }
124 "@weight"			{ YYSTOREBOUNDS; lvalp->m_sValue = yytext; return TOK_ATIDENT; }
125 "@count"			{ YYSTOREBOUNDS; lvalp->m_sValue = yytext; return TOK_ATIDENT; }
126 {ID}				{ YYSTOREBOUNDS; lvalp->m_sValue = yytext; return TOK_IDENT; }
127 [a-zA-Z_0-9]+		{ YYSTOREBOUNDS; return TOK_BAD_NUMERIC; }
128 @{ID}				{ YYSTOREBOUNDS; lvalp->m_sValue = yytext; return TOK_USERVAR; }
129 @@{ID}				{ YYSTOREBOUNDS; lvalp->m_sValue = yytext; return TOK_SYSVAR; }
130 "`ID`"				{ YYSTOREBOUNDS; lvalp->m_iStart++; lvalp->m_iEnd--; lvalp->m_sValue.SetBinary ( yytext+1, strlen(yytext)-2 ); return TOK_ID; }
131 `{ID}`				{ YYSTOREBOUNDS; lvalp->m_iStart++; lvalp->m_iEnd--; lvalp->m_sValue.SetBinary ( yytext+1, strlen(yytext)-2 ); return TOK_IDENT; }
132 
133 {SPACE}+			{ ; }
134 .					{ YYSTOREBOUNDS; return yytext[0]; }
135 
136 %%
137 
138 // warning, lexer generator dependent!
139 // flex inserts trailing zero as needed into the buffer when lexing
140 // but we need that rolled back when doing error reporting from yyerror
141 void yylex_unhold ( yyscan_t yyscanner )
142 {
143 	struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
144 	if ( YY_CURRENT_BUFFER )
145 	{
146 		*yyg->yy_c_buf_p = yyg->yy_hold_char;
147 		YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
148 		YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
149 	}
150 }
151 
152 #if USE_WINDOWS
153 #pragma warning(pop)
154 #endif
155