Drizzled Public API Documentation

lex_input_stream.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00036 namespace drizzled {
00037 
00038 class Lex_input_stream
00039 {
00040 public:
00041   Lex_input_stream(Session *session, const char* buff, unsigned int length);
00042 
00050   void set_echo(bool echo)
00051   {
00052     m_echo= echo;
00053   }
00054 
00059   void skip_binary(int n)
00060   {
00061     if (m_echo)
00062     {
00063       memcpy(m_cpp_ptr, m_ptr, n);
00064       m_cpp_ptr += n;
00065     }
00066     m_ptr += n;
00067   }
00068 
00073   char yyGet()
00074   {
00075     char c= *m_ptr++;
00076     if (m_echo)
00077       *m_cpp_ptr++ = c;
00078     return c;
00079   }
00080 
00085   char yyGetLast() const
00086   {
00087     return m_ptr[-1];
00088   }
00089 
00093   char yyPeek() const
00094   {
00095     return m_ptr[0];
00096   }
00097 
00102   char yyPeekn(int n) const
00103   {
00104     return m_ptr[n];
00105   }
00106 
00112   void yyUnget()
00113   {
00114     m_ptr--;
00115     if (m_echo)
00116       m_cpp_ptr--;
00117   }
00118 
00122   void yySkip()
00123   {
00124     if (m_echo)
00125       *m_cpp_ptr++ = *m_ptr++;
00126     else
00127       m_ptr++;
00128   }
00129 
00134   void yySkipn(int n)
00135   {
00136     if (m_echo)
00137     {
00138       memcpy(m_cpp_ptr, m_ptr, n);
00139       m_cpp_ptr += n;
00140     }
00141     m_ptr += n;
00142   }
00143 
00148   bool eof() const
00149   {
00150     return m_ptr >= m_end_of_query;
00151   }
00152 
00158   bool eof(int n) const
00159   {
00160     return m_ptr + n >= m_end_of_query;
00161   }
00162 
00164   const char *get_buf() const
00165   {
00166     return m_buf;
00167   }
00168 
00170   const char *get_cpp_buf() const
00171   {
00172     return m_cpp_buf;
00173   }
00174 
00176   const char *get_end_of_query() const
00177   {
00178     return m_end_of_query;
00179   }
00180 
00182   void start_token()
00183   {
00184     m_tok_start_prev= m_tok_start;
00185     m_tok_start= m_ptr;
00186     m_tok_end= m_ptr;
00187 
00188     m_cpp_tok_start_prev= m_cpp_tok_start;
00189     m_cpp_tok_start= m_cpp_ptr;
00190     m_cpp_tok_end= m_cpp_ptr;
00191   }
00192 
00197   void restart_token()
00198   {
00199     m_tok_start= m_ptr;
00200     m_cpp_tok_start= m_cpp_ptr;
00201   }
00202 
00204   const char *get_tok_start() const
00205   {
00206     return m_tok_start;
00207   }
00208 
00210   const char *get_cpp_tok_start() const
00211   {
00212     return m_cpp_tok_start;
00213   }
00214 
00216   const char *get_tok_end() const
00217   {
00218     return m_tok_end;
00219   }
00220 
00222   const char *get_cpp_tok_end() const
00223   {
00224     return m_cpp_tok_end;
00225   }
00226 
00228   const char *get_tok_start_prev() const
00229   {
00230     return m_tok_start_prev;
00231   }
00232 
00234   const char *get_ptr() const
00235   {
00236     return m_ptr;
00237   }
00238 
00240   const char *get_cpp_ptr() const
00241   {
00242     return m_cpp_ptr;
00243   }
00244 
00246   uint32_t yyLength() const
00247   {
00248     /*
00249       The assumption is that the lexical analyser is always 1 character ahead,
00250       which the -1 account for.
00251     */
00252     assert(m_ptr > m_tok_start);
00253     return (uint32_t) ((m_ptr - m_tok_start) - 1);
00254   }
00255 
00257   const char *get_body_utf8_str() const
00258   {
00259     return m_body_utf8;
00260   }
00261 
00263   uint32_t get_body_utf8_length() const
00264   {
00265     return m_body_utf8_ptr - m_body_utf8;
00266   }
00267 
00268   void body_utf8_append(const char *ptr);
00269   void body_utf8_append(const char *ptr, const char *end_ptr);
00270   void body_utf8_append_literal(str_ref, const char *end_ptr);
00271 
00273   Session *m_session;
00274 
00276   uint32_t yylineno;
00277 
00279   uint32_t yytoklen;
00280 
00282   LEX_YYSTYPE yylval;
00283 
00285   int lookahead_token;
00286 
00288   LEX_YYSTYPE lookahead_yylval;
00289 
00290 private:
00292   const char *m_ptr;
00293 
00295   const char *m_tok_start;
00296 
00298   const char *m_tok_end;
00299 
00301   const char *m_end_of_query;
00302 
00304   const char *m_tok_start_prev;
00305 
00307   const char *m_buf;
00308 
00310   uint32_t m_buf_length;
00311 
00313   bool m_echo;
00314 
00316   char *m_cpp_buf;
00317 
00319   char *m_cpp_ptr;
00320 
00325   const char *m_cpp_tok_start;
00326 
00331   const char *m_cpp_tok_start_prev;
00332 
00337   const char *m_cpp_tok_end;
00338 
00340   char *m_body_utf8;
00341 
00343   char *m_body_utf8_ptr;
00344 
00349   const char *m_cpp_utf8_processed_ptr;
00350 
00351 public:
00352 
00354   enum my_lex_states next_state;
00355 
00357   unsigned char tok_bitmap;
00358 
00360   bool ignore_space;
00361 
00363   enum_comment_state in_comment;
00364 
00371   const char *m_cpp_text_start;
00372 
00379   const char *m_cpp_text_end;
00380 
00381 };
00382 
00383 } /* namespace drizzled */
00384