This repository was archived by the owner on Jan 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTSQueryParser.yy
More file actions
64 lines (44 loc) · 1.33 KB
/
TSQueryParser.yy
File metadata and controls
64 lines (44 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
%language "c++"
/* disable after debug %debug */
%debug
%define api.namespace { DB::TSQuery }
%define parser_class_name {TSQueryParser}
%code requires
{
#include "TSQueryExpression.h"
namespace DB{ namespace TSQuery{ class TSQueryParserDriver; } }
}
%union
{
const TSQueryAST* ast;
std::string* str;
}
%parse-param { class TSQueryParserDriver& dirver}
%token <str> TOKEN_VAL
%token TOKEN_OPEN TOKEN_CLOSE
%token TOKEN_AND TOKEN_OR
%token TOKEN_NOT
%token TOKEN_END 0
%type <ast> exp term
%left TOKEN_OR
%left TOKEN_AND
%right TOKEN_NOT
%{
#include "TSQueryScanner.h"
#include "TSQueryParserDriver.h"
#undef yylex
#define yylex dirver.scanner->getNextToken
%}
%%
tsquery:
| exp TOKEN_END { dirver.result_ast = $1; }
;
exp: term { $$ = $1; }
| exp TOKEN_AND exp { $$ = dirver.ts_context.getNewTSQueryAST( TSQueryAST::QueryOperator(TSQueryAST::QueryOperatorType::OP_AND), $1, $3 ); }
| exp TOKEN_OR exp { $$ = dirver.ts_context.getNewTSQueryAST( TSQueryAST::QueryOperator(TSQueryAST::QueryOperatorType::OP_OR), $1, $3 ); }
;
term: TOKEN_VAL { $$ = dirver.ts_context.getNewTSQueryAST( TSQueryAST::QueryOperand($1) ); }
| TOKEN_NOT term { $$ = dirver.ts_context.getNewTSQueryAST( TSQueryAST::QueryOperator(TSQueryAST::QueryOperatorType::OP_NOT), $2 ); }
| TOKEN_OPEN exp TOKEN_CLOSE { $$ = $2; }
;
%%