Drizzled Public API Documentation

lex_input_stream.h
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #pragma once
21 
36 namespace drizzled {
37 
39 {
40 public:
41  Lex_input_stream(Session *session, const char* buff, unsigned int length);
42 
50  void set_echo(bool echo)
51  {
52  m_echo= echo;
53  }
54 
59  void skip_binary(int n)
60  {
61  if (m_echo)
62  {
63  memcpy(m_cpp_ptr, m_ptr, n);
64  m_cpp_ptr += n;
65  }
66  m_ptr += n;
67  }
68 
73  char yyGet()
74  {
75  char c= *m_ptr++;
76  if (m_echo)
77  *m_cpp_ptr++ = c;
78  return c;
79  }
80 
85  char yyGetLast() const
86  {
87  return m_ptr[-1];
88  }
89 
93  char yyPeek() const
94  {
95  return m_ptr[0];
96  }
97 
102  char yyPeekn(int n) const
103  {
104  return m_ptr[n];
105  }
106 
112  void yyUnget()
113  {
114  m_ptr--;
115  if (m_echo)
116  m_cpp_ptr--;
117  }
118 
122  void yySkip()
123  {
124  if (m_echo)
125  *m_cpp_ptr++ = *m_ptr++;
126  else
127  m_ptr++;
128  }
129 
134  void yySkipn(int n)
135  {
136  if (m_echo)
137  {
138  memcpy(m_cpp_ptr, m_ptr, n);
139  m_cpp_ptr += n;
140  }
141  m_ptr += n;
142  }
143 
148  bool eof() const
149  {
150  return m_ptr >= m_end_of_query;
151  }
152 
158  bool eof(int n) const
159  {
160  return m_ptr + n >= m_end_of_query;
161  }
162 
164  const char *get_buf() const
165  {
166  return m_buf;
167  }
168 
170  const char *get_cpp_buf() const
171  {
172  return m_cpp_buf;
173  }
174 
176  const char *get_end_of_query() const
177  {
178  return m_end_of_query;
179  }
180 
182  void start_token()
183  {
186  m_tok_end= m_ptr;
187 
191  }
192 
198  {
201  }
202 
204  const char *get_tok_start() const
205  {
206  return m_tok_start;
207  }
208 
210  const char *get_cpp_tok_start() const
211  {
212  return m_cpp_tok_start;
213  }
214 
216  const char *get_tok_end() const
217  {
218  return m_tok_end;
219  }
220 
222  const char *get_cpp_tok_end() const
223  {
224  return m_cpp_tok_end;
225  }
226 
228  const char *get_tok_start_prev() const
229  {
230  return m_tok_start_prev;
231  }
232 
234  const char *get_ptr() const
235  {
236  return m_ptr;
237  }
238 
240  const char *get_cpp_ptr() const
241  {
242  return m_cpp_ptr;
243  }
244 
246  uint32_t yyLength() const
247  {
248  /*
249  The assumption is that the lexical analyser is always 1 character ahead,
250  which the -1 account for.
251  */
252  assert(m_ptr > m_tok_start);
253  return (uint32_t) ((m_ptr - m_tok_start) - 1);
254  }
255 
257  const char *get_body_utf8_str() const
258  {
259  return m_body_utf8;
260  }
261 
263  uint32_t get_body_utf8_length() const
264  {
265  return m_body_utf8_ptr - m_body_utf8;
266  }
267 
268  void body_utf8_append(const char *ptr);
269  void body_utf8_append(const char *ptr, const char *end_ptr);
270  void body_utf8_append_literal(str_ref, const char *end_ptr);
271 
274 
276  uint32_t yylineno;
277 
279  uint32_t yytoklen;
280 
282  LEX_YYSTYPE yylval;
283 
286 
288  LEX_YYSTYPE lookahead_yylval;
289 
290 private:
292  const char *m_ptr;
293 
295  const char *m_tok_start;
296 
298  const char *m_tok_end;
299 
301  const char *m_end_of_query;
302 
304  const char *m_tok_start_prev;
305 
307  const char *m_buf;
308 
310  uint32_t m_buf_length;
311 
313  bool m_echo;
314 
316  char *m_cpp_buf;
317 
319  char *m_cpp_ptr;
320 
325  const char *m_cpp_tok_start;
326 
331  const char *m_cpp_tok_start_prev;
332 
337  const char *m_cpp_tok_end;
338 
340  char *m_body_utf8;
341 
344 
350 
351 public:
352 
354  enum my_lex_states next_state;
355 
357  unsigned char tok_bitmap;
358 
361 
363  enum_comment_state in_comment;
364 
371  const char *m_cpp_text_start;
372 
379  const char *m_cpp_text_end;
380 
381 };
382 
383 } /* namespace drizzled */
384