MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / lex_one_token

Function lex_one_token

sql/sql_lex.cc:961–1683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

959}
960
961static int lex_one_token(YYSTYPE *yylval, THD *thd)
962{
963 reg1 uchar c= 0;
964 bool comment_closed;
965 int tokval, result_state;
966 uint length;
967 enum my_lex_states state;
968 Lex_input_stream *lip= & thd->m_parser_state->m_lip;
969 LEX *lex= thd->lex;
970 const CHARSET_INFO *cs= thd->charset();
971 uchar *state_map= cs->state_map;
972 uchar *ident_map= cs->ident_map;
973
974 lip->yylval=yylval; // The global state
975
976 lip->start_token();
977 state=lip->next_state;
978 lip->next_state=MY_LEX_OPERATOR_OR_IDENT;
979 for (;;)
980 {
981 switch (state) {
982 case MY_LEX_OPERATOR_OR_IDENT: // Next is operator or keyword
983 case MY_LEX_START: // Start of token
984 // Skip starting whitespace
985 while(state_map[c= lip->yyPeek()] == MY_LEX_SKIP)
986 {
987 if (c == '\n')
988 lip->yylineno++;
989
990 lip->yySkip();
991 }
992
993 /* Start of real token */
994 lip->restart_token();
995 c= lip->yyGet();
996 state= (enum my_lex_states) state_map[c];
997 break;
998 case MY_LEX_ESCAPE:
999 if (lip->yyGet() == 'N')
1000 { // Allow \N as shortcut for NULL
1001 yylval->lex_str.str=(char*) "\\N";
1002 yylval->lex_str.length=2;
1003 return NULL_SYM;
1004 }
1005 case MY_LEX_CHAR: // Unknown or single char token
1006 case MY_LEX_SKIP: // This should not happen
1007 if (c == '-' && lip->yyPeek() == '-' &&
1008 (my_isspace(cs,lip->yyPeekn(1)) ||
1009 my_iscntrl(cs,lip->yyPeekn(1))))
1010 {
1011 state=MY_LEX_COMMENT;
1012 break;
1013 }
1014
1015 if (c != ')')
1016 lip->next_state= MY_LEX_START; // Allow signed numbers
1017
1018 if (c == ',')

Callers 1

MYSQLlexFunction · 0.85

Calls 15

get_textFunction · 0.85
find_keywordFunction · 0.85
get_tokenFunction · 0.85
get_charset_by_csnameFunction · 0.85
get_quoted_tokenFunction · 0.85
int_tokenFunction · 0.85
consume_commentFunction · 0.85
start_tokenMethod · 0.80
yyPeekMethod · 0.80
yySkipMethod · 0.80
restart_tokenMethod · 0.80
yyGetMethod · 0.80

Tested by

no test coverage detected