1 %{ 2 /* code here */ 3 4 #include <stdarg.h> 5 #include "sqlhist-parse.h" 6 7 extern int my_yyinput(void *extra, char *buf, int max); 8 9 #undef YY_INPUT 10 #define YY_INPUT(b, r, m) ({r = my_yyinput(yyextra, b, m);}) 11 12 #define YY_NO_INPUT 13 #define YY_NO_UNPUT 14 15 #define YY_EXTRA_TYPE struct sqlhist_bison * 16 17 #define yytext yyg->yytext_r 18 19 #define TRACE_SB ((struct sqlhist_bison *)yyextra) 20 #define HANDLE_COLUMN do { TRACE_SB->line_idx += strlen(yytext); } while (0) 21 22 %} 23 24 %option caseless 25 %option reentrant 26 %option bison-bridge 27 28 field \\?[a-z_][a-z0-9_\.]* 29 qstring \"[^\"]*\" 30 31 hexnum 0x[0-9a-f]+ 32 number [0-9a-f]+ 33 %% 34 35 select { HANDLE_COLUMN; return SELECT; } 36 as { HANDLE_COLUMN; return AS; } 37 from { HANDLE_COLUMN; return FROM; } 38 join { HANDLE_COLUMN; return JOIN; } 39 on { HANDLE_COLUMN; return ON; } 40 where { HANDLE_COLUMN; return WHERE; } 41 cast { HANDLE_COLUMN; return CAST; } 42 43 sym-offset { 44 HANDLE_COLUMN; 45 yylval->string = store_str(TRACE_SB, yyg->yytext_r); 46 return FIELD; 47 } 48 49 {qstring} { 50 HANDLE_COLUMN; 51 yylval->string = store_str(TRACE_SB, yyg->yytext_r); 52 return STRING; 53 } 54 55 {field} { 56 const char *str = yyg->yytext_r; 57 HANDLE_COLUMN; 58 if (str[0] == '\\') { str++; }; 59 yylval->string = store_str(TRACE_SB, str); 60 return FIELD; 61 } 62 63 {hexnum} { 64 HANDLE_COLUMN; 65 yylval->number = strtol(yyg->yytext_r, NULL, 0); 66 return NUMBER; 67 } 68 69 {number} { 70 HANDLE_COLUMN; 71 yylval->number = strtol(yyg->yytext_r, NULL, 0); 72 return NUMBER; 73 } 74 75 \!= { HANDLE_COLUMN; return NEQ; } 76 \<= { HANDLE_COLUMN; return LE; } 77 \>= { HANDLE_COLUMN; return GE; } 78 == { HANDLE_COLUMN; return EQ; } 79 && { HANDLE_COLUMN; return AND; } 80 "||" { HANDLE_COLUMN; return OR; } 81 [<>&~] { HANDLE_COLUMN; return yytext[0]; } 82 83 [\!()\-\+\*/,=] { HANDLE_COLUMN; return yytext[0]; } 84 85 [ \t] { HANDLE_COLUMN; } 86 \n { TRACE_SB->line_idx = 0; TRACE_SB->line_no++; } 87 88 . { HANDLE_COLUMN; return PARSE_ERROR; } 89 %% 90 91 int yywrap(void *data) 92 { 93 return 1; 94 } 95 96 void yyerror(struct sqlhist_bison *sb, char *fmt, ...) 97 { 98 struct yyguts_t * yyg = (struct yyguts_t*)sb->scanner; 99 va_list ap; 100 101 va_start(ap, fmt); 102 sql_parse_error(sb, yytext, fmt, ap); 103 va_end(ap); 104 } 105