sphinxql.l 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. %{
  2. #if _WIN32
  3. #define YY_NO_UNISTD_H 1
  4. #endif
  5. #include "bissphinxql.h"
  6. #ifdef __GNUC__
  7. #pragma GCC diagnostic push
  8. #pragma GCC diagnostic ignored "-Wsign-compare"
  9. #pragma GCC diagnostic ignored "-Wpragmas"
  10. #pragma GCC diagnostic ignored "-Wunneeded-internal-declaration"
  11. #endif
  12. #if _WIN32
  13. #pragma warning(push,1)
  14. #endif
  15. // warning, lexer generator dependent!
  16. // this macro relies on that in flex yytext points to the actual location in the buffer
  17. #define YYSTOREBOUNDS \
  18. { \
  19. lvalp->m_iStart = yytext - pParser->m_pBuf; \
  20. lvalp->m_iEnd = lvalp->m_iStart + yyleng; \
  21. pParser->m_pLastTokenStart = yytext; \
  22. }
  23. #define BLOCK_START \
  24. { \
  25. pParser->m_pLastTokenStart = yytext; \
  26. lvalp->m_iStart = yytext + yyleng - pParser->m_pBuf; \
  27. }
  28. #define BLOCK_END \
  29. { \
  30. lvalp->m_iEnd = yytext + yyleng - pParser->m_pBuf; \
  31. }
  32. %}
  33. DIGIT [0-9]
  34. ALPHA [a-zA-Z_@]
  35. ALNUM [a-zA-Z_0-9]
  36. ID {ALPHA}{ALNUM}*
  37. ID_SYS {ALNUM}{ALNUM}*
  38. SPACE [ \t\n\r]
  39. SIGN [+-]?
  40. INT {DIGIT}+
  41. EXP [eE]{SIGN}{INT}
  42. FLOAT_CONSTANT {INT}\.{INT}?{EXP}?|{INT}?\.{INT}{EXP}|{INT}{EXP}
  43. %option noyywrap
  44. %option nounput
  45. %option reentrant
  46. %option case-insensitive
  47. %option batch
  48. %option align
  49. %x ccomment
  50. %x BACKTICK
  51. %%
  52. "/*" { BLOCK_START; BEGIN(ccomment); }
  53. <ccomment>"*/" { BLOCK_END; BEGIN(INITIAL); lvalp->m_iEnd-=2; pParser->AddComment(lvalp); }
  54. <ccomment>[^*\n]+
  55. <ccomment>"*"[^/]
  56. <ccomment>"\n"
  57. \.{SPACE}*` { BLOCK_START; BEGIN (BACKTICK); }
  58. <BACKTICK>[^\n\\`]+ /* eat everything except \n, \, ` */
  59. <BACKTICK>\\[^\n] /* eat one symbol after \ (aka escaping) except \n */
  60. <BACKTICK>` {
  61. BLOCK_END;
  62. BEGIN(INITIAL);
  63. return TOK_BACKTICKED_SUBKEY;
  64. }
  65. <BACKTICK>\n | /* terminate on \n or EOF inside unclosed backtick */
  66. <BACKTICK><<EOF>> {
  67. BEGIN(INITIAL);
  68. return -1;
  69. }
  70. "AGENT" { YYSTOREBOUNDS; return TOK_AGENT; }
  71. "ALL" { YYSTOREBOUNDS; return TOK_ALL; }
  72. "AND" { YYSTOREBOUNDS; return TOK_AND; }
  73. "ANY" { YYSTOREBOUNDS; return TOK_ANY; }
  74. "AS" { YYSTOREBOUNDS; return TOK_AS; }
  75. "ASC" { YYSTOREBOUNDS; return TOK_ASC; }
  76. "AVG" { YYSTOREBOUNDS; return TOK_AVG; }
  77. "BEGIN" { YYSTOREBOUNDS; return TOK_BEGIN; }
  78. "BETWEEN" { YYSTOREBOUNDS; return TOK_BETWEEN; }
  79. "BIGINT" { YYSTOREBOUNDS; return TOK_BIGINT; }
  80. "BY" { YYSTOREBOUNDS; return TOK_BY; }
  81. "CALL" { YYSTOREBOUNDS; return TOK_CALL; }
  82. "CHARACTER" { YYSTOREBOUNDS; return TOK_CHARACTER; }
  83. "CHUNK" { YYSTOREBOUNDS; return TOK_CHUNK; }
  84. "CLUSTER" { YYSTOREBOUNDS; return TOK_CLUSTER; }
  85. "COLLATE" { YYSTOREBOUNDS; return TOK_COLLATE; }
  86. "COLLATION" { YYSTOREBOUNDS; return TOK_COLLATION; }
  87. "COLUMN" { YYSTOREBOUNDS; return TOK_COLUMN; }
  88. "COLUMNARSCAN" { YYSTOREBOUNDS; return TOK_HINT_COLUMNAR; }
  89. "COMMIT" { YYSTOREBOUNDS; return TOK_COMMIT; }
  90. "COUNT" { YYSTOREBOUNDS; return TOK_COUNT; }
  91. "CREATE" { YYSTOREBOUNDS; return TOK_CREATE; }
  92. "DATABASES" { YYSTOREBOUNDS; return TOK_DATABASES; }
  93. "DATE_ADD" { YYSTOREBOUNDS; return TOK_DATE_ADD; }
  94. "DATE_SUB" { YYSTOREBOUNDS; return TOK_DATE_SUB; }
  95. "DAY" { YYSTOREBOUNDS; return TOK_DAY; }
  96. "DELETE" { YYSTOREBOUNDS; return TOK_DELETE; }
  97. "DESC" { YYSTOREBOUNDS; return TOK_DESC; }
  98. "DESCRIBE" { YYSTOREBOUNDS; return TOK_DESCRIBE; }
  99. "DISTINCT" { YYSTOREBOUNDS; return TOK_DISTINCT; }
  100. "DIV" { YYSTOREBOUNDS; return TOK_DIV; }
  101. "DOCIDINDEX" { YYSTOREBOUNDS; return TOK_HINT_DOCID; }
  102. "DOUBLE" { YYSTOREBOUNDS; return TOK_DOUBLE; }
  103. "EXPLAIN" { YYSTOREBOUNDS; return TOK_EXPLAIN; }
  104. "FACET" { YYSTOREBOUNDS; return TOK_FACET; }
  105. "FALSE" { YYSTOREBOUNDS; return TOK_FALSE; }
  106. "FLOAT" { YYSTOREBOUNDS; return TOK_FLOAT; }
  107. "FOR" { YYSTOREBOUNDS; return TOK_FOR; }
  108. "FORCE" { YYSTOREBOUNDS; return TOK_FORCE; }
  109. "FROM" { YYSTOREBOUNDS; return TOK_FROM; }
  110. "GLOBAL" { YYSTOREBOUNDS; return TOK_GLOBAL; }
  111. "GROUP" { YYSTOREBOUNDS; return TOK_GROUP; }
  112. "GROUPBY" { YYSTOREBOUNDS; return TOK_GROUPBY; }
  113. "GROUP_CONCAT" { YYSTOREBOUNDS; return TOK_GROUP_CONCAT; }
  114. "HAVING" { YYSTOREBOUNDS; return TOK_HAVING; }
  115. "HOSTNAMES" { YYSTOREBOUNDS; return TOK_HOSTNAMES; }
  116. "HOUR" { YYSTOREBOUNDS; return TOK_HOUR; }
  117. "IGNORE" { YYSTOREBOUNDS; return TOK_IGNORE; }
  118. "IN" { YYSTOREBOUNDS; return TOK_IN; }
  119. "INDEX" { YYSTOREBOUNDS; return TOK_INDEX; }
  120. "INDEXES" { YYSTOREBOUNDS; return TOK_INDEXES; }
  121. "INDEXOF" { YYSTOREBOUNDS; return TOK_INDEXOF; }
  122. "INNER" { YYSTOREBOUNDS; return TOK_INNER; }
  123. "INSERT" { YYSTOREBOUNDS; return TOK_INSERT; }
  124. "INTEGER" { YYSTOREBOUNDS; return TOK_INTEGER; }
  125. "INT" { YYSTOREBOUNDS; return TOK_INT; }
  126. "INTERVAL" { YYSTOREBOUNDS; return TOK_INTERVAL; }
  127. "INTO" { YYSTOREBOUNDS; return TOK_INTO; }
  128. "IS" { YYSTOREBOUNDS; return TOK_IS; }
  129. "JOIN" { YYSTOREBOUNDS; return TOK_JOIN; }
  130. "KILL" { YYSTOREBOUNDS; return TOK_KILL; }
  131. "KNN" { YYSTOREBOUNDS; return TOK_KNN; }
  132. "LEFT" { YYSTOREBOUNDS; return TOK_LEFT; }
  133. "LIKE" { YYSTOREBOUNDS; return TOK_LIKE; }
  134. "LOGS" { YYSTOREBOUNDS; return TOK_LOGS; }
  135. "LOCKS" { YYSTOREBOUNDS; return TOK_LOCKS; }
  136. "FREEZE" { YYSTOREBOUNDS; return TOK_FREEZE; }
  137. "LIMIT" { YYSTOREBOUNDS; return TOK_LIMIT; }
  138. "MATCH" { YYSTOREBOUNDS; return TOK_MATCH; }
  139. "MAX" { YYSTOREBOUNDS; return TOK_MAX; }
  140. "META" { YYSTOREBOUNDS; return TOK_META; }
  141. "MIN" { YYSTOREBOUNDS; return TOK_MIN; }
  142. "MINUTE" { YYSTOREBOUNDS; return TOK_MINUTE; }
  143. "MOD" { YYSTOREBOUNDS; return TOK_MOD; }
  144. "MONTH" { YYSTOREBOUNDS; return TOK_MONTH; }
  145. "MULTI" { YYSTOREBOUNDS; return TOK_MULTI; }
  146. "MULTI64" { YYSTOREBOUNDS; return TOK_MULTI64; }
  147. "NAMES" { YYSTOREBOUNDS; return TOK_NAMES; }
  148. "NO_COLUMNARSCAN" { YYSTOREBOUNDS; return TOK_HINT_NO_COLUMNAR; }
  149. "NO_DOCIDINDEX" { YYSTOREBOUNDS; return TOK_HINT_NO_DOCID; }
  150. "NO_SECONDARYINDEX" { YYSTOREBOUNDS; return TOK_HINT_NO_SECONDARY; }
  151. "NOT" { YYSTOREBOUNDS; return TOK_NOT; }
  152. "NULL" { YYSTOREBOUNDS; return TOK_NULL; }
  153. "ON" { YYSTOREBOUNDS; return TOK_ON; }
  154. "OFFSET" { YYSTOREBOUNDS; return TOK_OFFSET; }
  155. "OPTION" { YYSTOREBOUNDS; return TOK_OPTION; }
  156. "OPTIMIZE" { YYSTOREBOUNDS; return TOK_OPTIMIZE; }
  157. "OR" { YYSTOREBOUNDS; return TOK_OR; }
  158. "ORDER" { YYSTOREBOUNDS; return TOK_ORDER; }
  159. "PLAN" { YYSTOREBOUNDS; return TOK_PLAN; }
  160. "PLUGINS" { YYSTOREBOUNDS; return TOK_PLUGINS; }
  161. "PROFILE" { YYSTOREBOUNDS; return TOK_PROFILE; }
  162. "QUARTER" { YYSTOREBOUNDS; return TOK_QUARTER; }
  163. "QUERY" { YYSTOREBOUNDS; return TOK_QUERY; }
  164. "RAND" { YYSTOREBOUNDS; return TOK_RAND; }
  165. "REGEX" { YYSTOREBOUNDS; return TOK_REGEX; }
  166. "RELOAD" { YYSTOREBOUNDS; return TOK_RELOAD; }
  167. "REPLACE" { YYSTOREBOUNDS; return TOK_REPLACE; }
  168. "REMAP" { YYSTOREBOUNDS; return TOK_REMAP; }
  169. "ROLLBACK" { YYSTOREBOUNDS; return TOK_ROLLBACK; }
  170. "SCROLL" { YYSTOREBOUNDS; return TOK_SCROLL; }
  171. "SECOND" { YYSTOREBOUNDS; return TOK_SECOND; }
  172. "SECONDARYINDEX" { YYSTOREBOUNDS; return TOK_HINT_SECONDARY; }
  173. "SELECT" { YYSTOREBOUNDS; return TOK_SELECT; }
  174. "SET" { YYSTOREBOUNDS; return TOK_SET; }
  175. "SETTINGS" { YYSTOREBOUNDS; return TOK_SETTINGS; }
  176. "SESSION" { YYSTOREBOUNDS; return TOK_SESSION; }
  177. "SHOW" { YYSTOREBOUNDS; return TOK_SHOW; }
  178. "SONAME" { YYSTOREBOUNDS; return TOK_SONAME; }
  179. "START" { YYSTOREBOUNDS; return TOK_START; }
  180. "STATUS" { YYSTOREBOUNDS; return TOK_STATUS; }
  181. "STRING" { YYSTOREBOUNDS; return TOK_STRING; }
  182. "SUM" { YYSTOREBOUNDS; return TOK_SUM; }
  183. "SYSFILTERS" { YYSTOREBOUNDS; return TOK_SYSFILTERS; }
  184. "TABLE" { YYSTOREBOUNDS; return TOK_TABLE; }
  185. "TABLES" { YYSTOREBOUNDS; return TOK_TABLES; }
  186. "THREADS" { YYSTOREBOUNDS; return TOK_THREADS; }
  187. "TO" { YYSTOREBOUNDS; return TOK_TO; }
  188. "TRANSACTION" { YYSTOREBOUNDS; return TOK_TRANSACTION; }
  189. "TRUE" { YYSTOREBOUNDS; return TOK_TRUE; }
  190. "UNFREEZE" { YYSTOREBOUNDS; return TOK_UNFREEZE; }
  191. "UPDATE" { YYSTOREBOUNDS; return TOK_UPDATE; }
  192. "VALUES" { YYSTOREBOUNDS; return TOK_VALUES; }
  193. "VARIABLES" { YYSTOREBOUNDS; return TOK_VARIABLES; }
  194. "WARNINGS" { YYSTOREBOUNDS; return TOK_WARNINGS; }
  195. "WEEK" { YYSTOREBOUNDS; return TOK_WEEK; }
  196. "WEIGHT" { YYSTOREBOUNDS; return TOK_WEIGHT; }
  197. "WHERE" { YYSTOREBOUNDS; return TOK_WHERE; }
  198. "WITHIN" { YYSTOREBOUNDS; return TOK_WITHIN; }
  199. "YEAR" { YYSTOREBOUNDS; return TOK_YEAR; }
  200. "MANTICORE." |
  201. "`MANTICORE`." { YYSTOREBOUNDS; return TOK_MANTICORE_DOT; }
  202. "SYSTEM" { YYSTOREBOUNDS; return TOK_SYSTEM; } /* leading space excludes token from list of reserved words */
  203. "!=" { YYSTOREBOUNDS; return TOK_NE; }
  204. "<>" { YYSTOREBOUNDS; return TOK_NE; }
  205. "<=" { YYSTOREBOUNDS; return TOK_LTE; }
  206. ">=" { YYSTOREBOUNDS; return TOK_GTE; }
  207. ":=" { YYSTOREBOUNDS; return '='; }
  208. "/*+" { YYSTOREBOUNDS; return TOK_HINT_OPEN; }
  209. "*/" { YYSTOREBOUNDS; return TOK_HINT_CLOSE; }
  210. '([^'\\]|\\.|\\\\)*' { YYSTOREBOUNDS; pParser->m_pLastTokenStart = yytext; lvalp->SetValueInt ( ( (SphAttr_t)lvalp->m_iStart<<32 ) | ( lvalp->m_iEnd-lvalp->m_iStart ) ); return TOK_QUOTED_STRING; }
  211. {FLOAT_CONSTANT} { YYSTOREBOUNDS; lvalp->m_fValue = (float)strtod ( yytext, NULL ); return TOK_CONST_FLOAT; }
  212. "inf" { YYSTOREBOUNDS; lvalp->m_fValue = INFINITY; return TOK_CONST_FLOAT; } /* leading space excludes token from list of reserved words */
  213. "-inf" { YYSTOREBOUNDS; lvalp->m_fValue = -INFINITY; return TOK_CONST_FLOAT; } /* leading space excludes token from list of reserved words */
  214. "nan" { YYSTOREBOUNDS; lvalp->m_fValue = NAN; return TOK_CONST_FLOAT; } /* leading space excludes token from list of reserved words */
  215. \.{INT}{ID} { YYSTOREBOUNDS; return TOK_SUBKEY; }
  216. \.{INT} { YYSTOREBOUNDS; return TOK_DOT_NUMBER; }
  217. {INT} { YYSTOREBOUNDS; lvalp->SetValueInt ( strtoull ( yytext, NULL, 10 ), false ); return TOK_CONST_INT; }
  218. "@id" { YYSTOREBOUNDS; return TOK_ATIDENT; }
  219. "@weight" { YYSTOREBOUNDS; return TOK_ATIDENT; }
  220. "@count" { YYSTOREBOUNDS; return TOK_ATIDENT; }
  221. {ID} { YYSTOREBOUNDS; return TOK_IDENT; }
  222. {ALNUM}+ { YYSTOREBOUNDS; return TOK_BAD_NUMERIC; }
  223. @@{ID_SYS} { YYSTOREBOUNDS; return TOK_SYSVAR; }
  224. @@`{ID_SYS}` { YYSTOREBOUNDS; return TOK_SYSVAR; }
  225. `{ID}` { YYSTOREBOUNDS; ++lvalp->m_iStart; --lvalp->m_iEnd; return TOK_IDENT; }
  226. `{ID}:{ID}` { YYSTOREBOUNDS; ++lvalp->m_iStart; --lvalp->m_iEnd; return TOK_IDENT; }
  227. `{INT}{ID}` { YYSTOREBOUNDS; return TOK_BACKIDENT; } // allow `123xyz` column names
  228. {SPACE}+
  229. \.{SPACE}*{ID} { YYSTOREBOUNDS; return TOK_SUBKEY; }
  230. . { YYSTOREBOUNDS; return yytext[0]; }
  231. %%
  232. // warning, lexer generator dependent!
  233. // flex inserts trailing zero as needed into the buffer when lexing
  234. // but we need that rolled back when doing error reporting from yyerror
  235. void yylex_unhold ( yyscan_t yyscanner )
  236. {
  237. struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
  238. if ( YY_CURRENT_BUFFER )
  239. {
  240. *yyg->yy_c_buf_p = yyg->yy_hold_char;
  241. YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
  242. YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
  243. }
  244. }
  245. #if _WIN32
  246. #pragma warning(pop)
  247. #endif
  248. #ifdef __GNUC__
  249. #pragma GCC diagnostic pop
  250. #endif