@@ -38,42 +38,52 @@ union MYSQL_YYSTYPE; // Forward declare for YY_DECL (Bison defines this in mysql
3838 " INSERT" { return TOKEN_INSERT; }
3939 " INTO" { return TOKEN_INTO; }
4040 " VALUES" { return TOKEN_VALUES; }
41-
42- " QUIT" {
43- yylval_param->str_val = new std::string (yytext);
44- return TOKEN_QUIT;
41+ " QUIT" { yylval_param->str_val = new std::string (yytext); return TOKEN_QUIT; }
42+
43+ " SET" { return TOKEN_SET; }
44+ " NAMES" { return TOKEN_NAMES; }
45+ " CHARACTER" { return TOKEN_CHARACTER; }
46+ " GLOBAL" { return TOKEN_GLOBAL; }
47+ " SESSION" { return TOKEN_SESSION; }
48+ " PERSIST" { return TOKEN_PERSIST; }
49+ " PERSIST_ONLY" { return TOKEN_PERSIST_ONLY;}
50+ " DEFAULT" { return TOKEN_DEFAULT; }
51+ " COLLATE" { return TOKEN_COLLATE; }
52+
53+ " `" { yylval_param->str_val = new std::string (); BEGIN (BTIDENT); }
54+
55+ " @@global." { return TOKEN_GLOBAL_VAR_PREFIX; }
56+ " @@session." { return TOKEN_SESSION_VAR_PREFIX; }
57+ " @@local." { return TOKEN_SESSION_VAR_PREFIX; } /* Alias for session */
58+ " @@persisted." { /* Placeholder if you add specific handling */ return TOKEN_PERSIST_VAR_PREFIX; }
59+ " @@" { return TOKEN_DOUBLESPECIAL; }
60+ " @" { return TOKEN_SPECIAL; }
61+
62+ [a-zA-Z_][a-zA-Z0-9_]* { /* Does not include hyphen for now */
63+ yylval_param->str_val = new std::string (yytext);
64+ return TOKEN_IDENTIFIER;
4565 }
4666
47- " `" {
48- yylval_param->str_val = new std::string (); /* Start empty for backticked id */
49- BEGIN (BTIDENT);
50- }
51- [a-zA-Z_][a-zA-Z0-9_]* {
52- yylval_param->str_val = new std::string (yytext);
53- return TOKEN_IDENTIFIER;
54- }
55-
56- " '" {
57- yylval_param->str_val = new std::string (" '" );
58- BEGIN (SQSTRING);
59- }
60- " \" " {
61- yylval_param->str_val = new std::string (" \" " );
62- BEGIN (DQSTRING);
63- }
67+ " '" { yylval_param->str_val = new std::string (" '" ); BEGIN (SQSTRING); }
68+ " \" " { yylval_param->str_val = new std::string (" \" " ); BEGIN (DQSTRING); }
6469
6570 " *" { return TOKEN_ASTERISK; }
6671 " (" { return TOKEN_LPAREN; }
6772 " )" { return TOKEN_RPAREN; }
6873 " ;" { return TOKEN_SEMICOLON; }
74+ " =" { return TOKEN_EQUAL; }
75+ " ." { return TOKEN_DOT; }
76+ " ," { return TOKEN_COMMA; }
77+
78+ [0 -9 ]+(" ." [0 -9 ]+)? { yylval_param->str_val = new std::string (yytext); return TOKEN_NUMBER_LITERAL;}
6979
70- . {
80+ . {
7181 char err_msg[100 ];
7282 snprintf (err_msg, sizeof (err_msg), " Lexer: Unknown character: '%s'" , yytext);
73- if (parser_context) {
83+ if (parser_context) {
7484 parser_context->internal_add_error (err_msg);
7585 } else {
76- fprintf (stderr, " %s\n " , err_msg);
86+ fprintf (stderr, " %s\n " , err_msg);
7787 }
7888 }
7989}
@@ -91,7 +101,7 @@ union MYSQL_YYSTYPE; // Forward declare for YY_DECL (Bison defines this in mysql
91101 " \\\\ " { *(yylval_param->str_val ) += " \\ " ; }
92102 " ''" { *(yylval_param->str_val ) += " '" ; }
93103 " '" { *(yylval_param->str_val ) += " '" ; BEGIN (INITIAL); return TOKEN_STRING_LITERAL; }
94- <<EOF>> { if (parser_context) parser_context->internal_add_error (" Unterminated single-quoted string" ); BEGIN (INITIAL); return YY_NULL; /* Return 0 or YY_NULL for EOF/error */ }
104+ <<EOF>> { if (parser_context) parser_context->internal_add_error (" Unterminated single-quoted string" ); BEGIN (INITIAL); return YY_NULL; }
95105}
96106
97107<DQSTRING>{
@@ -104,15 +114,12 @@ union MYSQL_YYSTYPE; // Forward declare for YY_DECL (Bison defines this in mysql
104114}
105115
106116<BTIDENT>{
107- " `" { BEGIN (INITIAL); return TOKEN_IDENTIFIER; }
117+ " `" { BEGIN (INITIAL); return TOKEN_IDENTIFIER; } // Returns the accumulated string
108118 " ``" { *(yylval_param->str_val ) += ' `' ; }
109119 [^`\n]+ { *(yylval_param->str_val ) += yytext; }
110- \n { if (parser_context) parser_context->internal_add_error (" Newline in backticked identifier" ); BEGIN (INITIAL); /* No explicit return, lexer will find next token or error */ }
120+ \n { if (parser_context) parser_context->internal_add_error (" Newline in backticked identifier" ); BEGIN (INITIAL); /* No explicit return */ }
111121 <<EOF>> { if (parser_context) parser_context->internal_add_error (" Unterminated backticked identifier" ); BEGIN (INITIAL); return YY_NULL; }
112122}
113123
114124%%
115125
116- // yywrap is not strictly needed due to %option noyywrap
117- // int mysql_yywrap(yyscan_t scanner) { return 1; }
118-
0 commit comments