~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/execute/scanner.l

mergeĀ lp:~vjsamuel/drizzle/final-execute-parser

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
2
 * 
 
3
 *  Drizzle Execute Parser
 
4
 *
 
5
 *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
 
6
 *  Copyright (C) 2011 Vijay Samuel, vjsamuel1990@gmail.com
 
7
 *
 
8
 *  All rights reserved.
 
9
 *
 
10
 *  Redistribution and use in source and binary forms, with or without
 
11
 *  modification, are permitted provided that the following conditions are
 
12
 *  met:
 
13
 *
 
14
 *      * Redistributions of source code must retain the above copyright
 
15
 *  notice, this list of conditions and the following disclaimer.
 
16
 *
 
17
 *      * Redistributions in binary form must reproduce the above
 
18
 *  copyright notice, this list of conditions and the following disclaimer
 
19
 *  in the documentation and/or other materials provided with the
 
20
 *  distribution.
 
21
 *
 
22
 *      * The names of its contributors may not be used to endorse or
 
23
 *  promote products derived from this software without specific prior
 
24
 *  written permission.
 
25
 *
 
26
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
27
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
28
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
29
 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
30
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
31
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
32
 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
33
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
34
 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
35
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
36
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
37
 *
 
38
 */
 
39
 
 
40
%top{
 
41
 
 
42
#include <config.h>
 
43
#include <drizzled/execute/parser.h>  
 
44
#include <drizzled/execute/context.h>
 
45
#include <drizzled/execute/symbol.h>
 
46
#include <drizzled/lex_string.h>
 
47
 
 
48
using namespace drizzled;
 
49
 
 
50
#pragma GCC diagnostic ignored "-Wold-style-cast"
 
51
#pragma GCC diagnostic ignored "-Wsign-compare"
 
52
#pragma GCC diagnostic ignored "-Wunused-parameter"
 
53
#pragma GCC diagnostic ignored "-Wmissing-declarations"
 
54
 
 
55
#define YY_EXTRA_TYPE ::drizzled::execute::Context*
 
56
 
 
57
}
 
58
 
 
59
 
 
60
%{
 
61
#include <cstdio>
 
62
#include <cstdlib>
 
63
#include <cstring>
 
64
 
 
65
#define PARAM yyget_extra(yyscanner)
 
66
 
 
67
#define get_lex_chars(buffer, result, max_size, context) \
 
68
{ \
 
69
  if (context->pos >= context->length) \
 
70
  { \
 
71
    result= YY_NULL; \
 
72
  } \
 
73
  else \
 
74
  { \
 
75
    result= (int)(context->length - context->pos); \
 
76
    (size_t)result > (size_t)max_size ? result= max_size : 0; \
 
77
    memcpy(buffer, context->buf + context->pos, result); \
 
78
    context->pos += result; \
 
79
  } \
 
80
}
 
81
 
 
82
 
 
83
#define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
 
84
 
 
85
%}
 
86
 
 
87
 
 
88
UTF8_BYTE_ORDER_MARK   [\xEF][\xBB][\xBF]
 
89
 
 
90
DIGITS    [0-9]
 
91
ASCII     [\x0-\xFF]
 
92
 
 
93
U1          [a-zA-Z_]
 
94
U2          [\xC2-\xDF][\x80-\xBF]
 
95
U3          [\xE0][\xA0-\xBF][\x80-\xBF]
 
96
U4          [\xE1-\xEC][\x80-\xBF][\x80-\xBF]
 
97
U5          [\xED][\x80-\x9F][\x80-\xBF]
 
98
U6          [\xEE-\xEF][\x80-\xBF][\x80-\xBF]
 
99
U7          [\nxF0][\x90-\xBF][\x80-\xBF][\x80-\xBF]
 
100
U8          [\xF1-\xF3][\x80-\xBF][\x80-\xBF][\x80-\xBF]
 
101
U9          [\xF4][\x80-\x8F][\x80-\xBF][\x80-\xBF]
 
102
 
 
103
LETTERS     {ASCII}|{U2}|{U3}|{U4}|{U5}|{U6}|{U7}|{U8}|{U9} 
 
104
ALNUM       {LETTERS}|{DIGITS}
 
105
 
 
106
%option nounistd
 
107
%option 8bit
 
108
%option bison-bridge
 
109
%option case-insensitive
 
110
%option debug
 
111
%option nounput
 
112
%option noyywrap
 
113
%option outfile="drizzled/execute/scanner.cc" header-file="drizzled/execute/scanner.h"
 
114
%option perf-report
 
115
%option prefix="execute_"
 
116
%option reentrant
 
117
%%
 
118
 
 
119
{UTF8_BYTE_ORDER_MARK}       {  /*  Byte Order Mark */   } 
 
120
 
 
121
[\t\r\n ] ; /* skip whitespace */
 
122
 
 
123
 
 
124
[[:punct:]]?{ALNUM}*["."{ALNUM}_-]*{ALNUM}*[[:punct:]]? {
 
125
      yylval->string.str = yytext;
 
126
      yylval->string.length = yyleng;
 
127
      return STRING;
 
128
    }
 
129
 
 
130
.   {
 
131
      yyextra->begin= yytext;
 
132
      return UNKNOWN;
 
133
    }
 
134
 
 
135
%%
 
136
namespace drizzled {
 
137
namespace execute {
 
138
 
 
139
void Context::init_scanner()
 
140
{
 
141
  yylex_init(&scanner);
 
142
  yyset_extra(this, scanner);
 
143
}
 
144
 
 
145
void Context::destroy_scanner()
 
146
{
 
147
  yylex_destroy(scanner);
 
148
}
 
149
 
 
150
} // namespace execute
 
151
} // namespace drizzled
 
152