1/* -*- c-basic-offset: 2 -*- */
2/*
3 Copyright(C) 2017 Kouhei Sutou <kou@clear-code.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library 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 GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#pragma once
21
22#include <mrn_mysql.h>
23#include <mrn_mysql_compat.h>
24
25#include <groonga.h>
26
27namespace mrn {
28 class QueryParser {
29 public:
30 QueryParser(grn_ctx *ctx,
31 THD *thd,
32 grn_obj *expression,
33 grn_obj *default_column,
34 uint n_sections,
35 grn_obj *match_columns=NULL);
36 ~QueryParser();
37
38 grn_rc parse(const char *query, size_t query_length);
39 void parse_pragma(const char *query,
40 size_t query_length,
41 const char **raw_query,
42 size_t *raw_query_length,
43 grn_operator *default_operator,
44 grn_expr_flags *flags);
45
46 private:
47 grn_ctx *ctx_;
48 THD *thd_;
49 grn_obj *expression_;
50 grn_obj *default_column_;
51 uint n_sections_;
52 grn_obj *match_columns_;
53
54 bool parse_pragma_w(const char *query,
55 size_t query_length,
56 size_t *consumed_query_length);
57 void append_section(uint section,
58 grn_obj *section_value_buffer,
59 int weight,
60 uint n_weights);
61 bool parse_pragma_d(const char *query,
62 size_t query_length,
63 grn_operator *default_operator,
64 size_t *consumed_query_length);
65 grn_expr_flags default_expression_flags();
66 };
67}
68