1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
20
#ifndef DRIZZLED_LEX_INPUT_STREAM_H
21
#define DRIZZLED_LEX_INPUT_STREAM_H
24
@brief This class represents the character input stream consumed during
27
In addition to consuming the input stream, this class performs some
28
comment pre processing, by filtering out out of bound special text
29
from the query input stream.
30
Two buffers, with pointers inside each buffers, are maintained in
31
parallel. The 'raw' buffer is the original query text, which may
32
contain out-of-bound comments. The 'cpp' (for comments pre processor)
33
is the pre-processed buffer that contains only the query text that
34
should be seen once out-of-bound data is removed.
37
class Lex_input_stream
40
Lex_input_stream(Session *session, const char* buff, unsigned int length);
46
When echo is true, characters parsed from the raw input stream are
47
preserved. When false, characters parsed are silently ignored.
48
@param echo the echo mode.
50
void set_echo(bool echo)
56
Skip binary from the input stream.
57
@param n number of bytes to accept.
59
void skip_binary(int n)
63
memcpy(m_cpp_ptr, m_ptr, n);
70
Get a character, and advance in the stream.
71
@return the next character to parse.
82
Get the last character accepted.
83
@return the last character accepted.
91
Look at the next character to parse, but do not accept it.
99
Look ahead at some character to parse.
100
@param n offset of the character to look up
108
Cancel the effect of the last yyGet() or yySkip().
109
Note that the echo mode should not change between calls to yyGet / yySkip
110
and yyUnget. The caller is responsible for ensuring that.
120
Accept a character, by advancing the input stream.
125
*m_cpp_ptr++ = *m_ptr++;
131
Accept multiple characters at once.
132
@param n the number of characters to accept.
138
memcpy(m_cpp_ptr, m_ptr, n);
145
End of file indicator for the query text to parse.
146
@return true if there are no more characters to parse
150
return (m_ptr >= m_end_of_query);
154
End of file indicator for the query text to parse.
155
@param n number of characters expected
156
@return true if there are less than n characters to parse
160
return ((m_ptr + n) >= m_end_of_query);
163
/** Get the raw query buffer. */
164
const char *get_buf()
169
/** Get the pre-processed query buffer. */
170
const char *get_cpp_buf()
175
/** Get the end of the raw query buffer. */
176
const char *get_end_of_query()
178
return m_end_of_query;
181
/** Mark the stream position as the start of a new token. */
184
m_tok_start_prev= m_tok_start;
188
m_cpp_tok_start_prev= m_cpp_tok_start;
189
m_cpp_tok_start= m_cpp_ptr;
190
m_cpp_tok_end= m_cpp_ptr;
194
Adjust the starting position of the current token.
195
This is used to compensate for starting whitespace.
200
m_cpp_tok_start= m_cpp_ptr;
203
/** Get the token start position, in the raw buffer. */
204
const char *get_tok_start()
209
/** Get the token start position, in the pre-processed buffer. */
210
const char *get_cpp_tok_start()
212
return m_cpp_tok_start;
215
/** Get the token end position, in the raw buffer. */
216
const char *get_tok_end()
221
/** Get the token end position, in the pre-processed buffer. */
222
const char *get_cpp_tok_end()
224
return m_cpp_tok_end;
227
/** Get the previous token start position, in the raw buffer. */
228
const char *get_tok_start_prev()
230
return m_tok_start_prev;
233
/** Get the current stream pointer, in the raw buffer. */
234
const char *get_ptr()
239
/** Get the current stream pointer, in the pre-processed buffer. */
240
const char *get_cpp_ptr()
245
/** Get the length of the current token, in the raw buffer. */
249
The assumption is that the lexical analyser is always 1 character ahead,
250
which the -1 account for.
252
assert(m_ptr > m_tok_start);
253
return (uint32_t) ((m_ptr - m_tok_start) - 1);
256
/** Get the utf8-body string. */
257
const char *get_body_utf8_str()
262
/** Get the utf8-body length. */
263
uint32_t get_body_utf8_length()
265
return m_body_utf8_ptr - m_body_utf8;
268
void body_utf8_start(Session *session, const char *begin_ptr);
269
void body_utf8_append(const char *ptr);
270
void body_utf8_append(const char *ptr, const char *end_ptr);
271
void body_utf8_append_literal(Session *session,
272
const LEX_STRING *txt,
273
const CHARSET_INFO * const txt_cs,
274
const char *end_ptr);
276
/** Current thread. */
279
/** Current line number. */
282
/** Length of the last token parsed. */
285
/** Interface with bison, value of the last token parsed. */
288
/** LALR(2) resolution, look ahead token.*/
291
/** LALR(2) resolution, value of the look ahead token.*/
292
LEX_YYSTYPE lookahead_yylval;
295
/** Pointer to the current position in the raw input stream. */
298
/** Starting position of the last token parsed, in the raw buffer. */
299
const char *m_tok_start;
301
/** Ending position of the previous token parsed, in the raw buffer. */
302
const char *m_tok_end;
304
/** End of the query text in the input stream, in the raw buffer. */
305
const char *m_end_of_query;
307
/** Starting position of the previous token parsed, in the raw buffer. */
308
const char *m_tok_start_prev;
310
/** Begining of the query text in the input stream, in the raw buffer. */
313
/** Length of the raw buffer. */
314
uint32_t m_buf_length;
316
/** Echo the parsed stream to the pre-processed buffer. */
319
/** Pre-processed buffer. */
322
/** Pointer to the current position in the pre-processed input stream. */
326
Starting position of the last token parsed,
327
in the pre-processed buffer.
329
const char *m_cpp_tok_start;
332
Starting position of the previous token parsed,
333
in the pre-procedded buffer.
335
const char *m_cpp_tok_start_prev;
338
Ending position of the previous token parsed,
339
in the pre-processed buffer.
341
const char *m_cpp_tok_end;
343
/** UTF8-body buffer created during parsing. */
346
/** Pointer to the current position in the UTF8-body buffer. */
347
char *m_body_utf8_ptr;
350
Position in the pre-processed buffer. The query from m_cpp_buf to
351
m_cpp_utf_processed_ptr is converted to UTF8-body.
353
const char *m_cpp_utf8_processed_ptr;
357
/** Current state of the lexical analyser. */
358
enum my_lex_states next_state;
361
Position of ';' in the stream, to delimit multiple queries.
362
This delimiter is in the raw buffer.
364
const char *found_semicolon;
366
/** Token character bitmaps, to detect 7bit strings. */
367
unsigned char tok_bitmap;
369
/** SQL_MODE = IGNORE_SPACE. */
372
/** State of the lexical analyser for comments. */
373
enum_comment_state in_comment;
376
Starting position of the TEXT_STRING or IDENT in the pre-processed
379
NOTE: this member must be used within DRIZZLElex() function only.
381
const char *m_cpp_text_start;
384
Ending position of the TEXT_STRING or IDENT in the pre-processed
387
NOTE: this member must be used within DRIZZLElex() function only.
389
const char *m_cpp_text_end;
392
Character set specified by the character-set-introducer.
394
NOTE: this member must be used within DRIZZLElex() function only.
396
const CHARSET_INFO *m_underscore_cs;
398
#endif /* DRIZZLED_LEX_INPUT_STREAM_H */