~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/execute/parser.yy

  • Committer: Mark Atwood
  • Date: 2011-06-08 19:56:57 UTC
  • mfrom: (2324.1.1 drizzle)
  • Revision ID: me@mark.atwood.name-20110608195657-vkwvn8bgd020e2nt
mergeĀ lp:~fallenpegasus/drizzle/vjsamuel-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
%error-verbose
 
41
%debug
 
42
%defines
 
43
%expect 0
 
44
%output "drizzled/execute/parser.cc"
 
45
%defines "drizzled/execute/parser.h"
 
46
%lex-param { yyscan_t *scanner }
 
47
%name-prefix="execute_"
 
48
%parse-param { ::drizzled::execute::Context *context }
 
49
%parse-param { yyscan_t *scanner }
 
50
%pure-parser
 
51
%require "2.2"
 
52
%start begin
 
53
%verbose
 
54
 
 
55
%{
 
56
 
 
57
#include <config.h>
 
58
#include <iostream>
 
59
#include <stdint.h>
 
60
#include <drizzled/execute/symbol.h>
 
61
#include <drizzled/execute/scanner.h>
 
62
#include <drizzled/execute/context.h>
 
63
#include <vector>
 
64
 
 
65
#ifndef __INTEL_COMPILER
 
66
#pragma GCC diagnostic ignored "-Wold-style-cast"
 
67
#endif
 
68
 
 
69
#define YYENABLE_NLS 0
 
70
#define YYLTYPE_IS_TRIVIAL 0
 
71
 
 
72
int execute_lex(YYSTYPE* lvalp, void* scanner);
 
73
std::vector<std::string> parsed_queries;
 
74
std::string query;
 
75
size_t pos= std::string::npos;
 
76
#define parser_abort(A, B) do { parser::abort_func((A), (B)); YYABORT; } while (0) 
 
77
 
 
78
inline void execute_error(::drizzled::execute::Context *context, yyscan_t *scanner, const char *error)
 
79
{
 
80
  if (not context->end())
 
81
  {
 
82
    /* TODO: FIX ME!!! */
 
83
    /*
 
84
    context->abort(context, error);*/
 
85
    (void)scanner; (void)error;
 
86
  }
 
87
}
 
88
 
 
89
%}
 
90
 
 
91
 
 
92
%token <string> STRING
 
93
%token <string> QUOTED_STRING
 
94
%token UNKNOWN
 
95
 
 
96
%%
 
97
 
 
98
begin:    
 
99
 
 
100
          STRING   {   
 
101
                       query.append( std::string($1.str, $1.length));
 
102
                       query.push_back(' ');
 
103
                   }
 
104
          |
 
105
                         
 
106
          begin STRING {
 
107
                         query.append(std::string($2.str, $2.length));
 
108
                         query.push_back(' ');
 
109
                       }
 
110
        ;
 
111
 
 
112
 
 
113
%% 
 
114
 
 
115
 
 
116
namespace drizzled {
 
117
namespace execute {
 
118
 
 
119
std::vector<std::string> Context::start() 
 
120
{
 
121
  execute_parse(this, (void **)scanner);
 
122
  parsed_queries.clear();
 
123
  while ((pos= query.find(';')) != std::string::npos)
 
124
  {
 
125
    parsed_queries.push_back(query.substr(0, pos));
 
126
    if (query[pos+1] == ' ')
 
127
      query= query.substr(pos + 2, query.length());
 
128
    else
 
129
      query= query.substr(pos + 1, query.length());
 
130
  }
 
131
  parsed_queries.push_back(query); 
 
132
  query.clear();
 
133
  return parsed_queries;
 
134
}
 
135
 
 
136
} // namespace execute
 
137
} // namespace drizzled