~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/execute/parser.yy

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

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::string query;
 
74
#define parser_abort(A, B) do { parser::abort_func((A), (B)); YYABORT; } while (0)
 
75
 
 
76
inline void execute_error(::drizzled::execute::Context *context, yyscan_t *scanner, const char *error)
 
77
{
 
78
  if (not context->end())
 
79
  {
 
80
    /* TODO: FIX ME!!! */
 
81
    /*
 
82
    context->abort(context, error);*/
 
83
  }
 
84
}
 
85
 
 
86
%}
 
87
 
 
88
 
 
89
%token <string> STRING
 
90
%token <string> QUOTED_STRING
 
91
%token UNKNOWN
 
92
 
 
93
%%
 
94
 
 
95
begin:
 
96
 
 
97
          STRING   {
 
98
                       query.append($1.data(), $1.size());
 
99
                       query.push_back(' ');
 
100
                   }
 
101
          |
 
102
 
 
103
          begin STRING {
 
104
                         query.append($2.data(), $2.size());
 
105
                         query.push_back(' ');
 
106
                       }
 
107
        ;
 
108
 
 
109
 
 
110
%%
 
111
 
 
112
 
 
113
namespace drizzled {
 
114
namespace execute {
 
115
 
 
116
std::vector<std::string> Context::start()
 
117
{
 
118
  execute_parse(this, (void **)scanner);
 
119
  std::vector<std::string> parsed_queries;
 
120
  size_t start_pos= 0;
 
121
  while ((pos= query.find(';', start_pos)) != std::string::npos)
 
122
  {
 
123
    if ((pos > 0) && (query[pos-1] == '\\'))
 
124
    {
 
125
      start_pos= pos + 1;
 
126
      continue;
 
127
    }
 
128
    parsed_queries.push_back(query.substr(0, pos));
 
129
    pos++;
 
130
    if (query[pos] == ' ')
 
131
    {
 
132
      pos++;
 
133
    }
 
134
    query.erase(0, pos);
 
135
  }
 
136
  parsed_queries.push_back(query);
 
137
  query.clear();
 
138
 
 
139
  return parsed_queries;
 
140
}
 
141
 
 
142
} // namespace execute
 
143
} // namespace drizzled