Switch to unified view

a/src/query/wasaparse.ypp b/src/query/wasaparse.ypp
...
...
10
#include "wasaparserdriver.h"
10
#include "wasaparserdriver.h"
11
#include "wasaparse.h"
11
#include "wasaparse.h"
12
12
13
using namespace std;
13
using namespace std;
14
14
15
// #define LOG_PARSER
16
#ifdef LOG_PARSER
17
#define LOGP(X) {cerr << X;}
18
#else
19
#define LOGP(X)
20
#endif
21
15
int yylex(yy::parser::semantic_type *, yy::parser::location_type *, 
22
int yylex(yy::parser::semantic_type *, yy::parser::location_type *, 
16
        WasaParserDriver *);
23
          WasaParserDriver *);
17
void yyerror(char const *);
24
void yyerror(char const *);
18
static void qualify(Rcl::SearchDataClauseDist *, const string &);
25
static void qualify(Rcl::SearchDataClauseDist *, const string &);
19
26
20
static void addSubQuery(WasaParserDriver *d,
27
static void addSubQuery(WasaParserDriver *d,
21
                        Rcl::SearchData *sd, Rcl::SearchData *sq)
28
                        Rcl::SearchData *sd, Rcl::SearchData *sq)
...
...
44
%type <cl> fieldexpr
51
%type <cl> fieldexpr
45
%type <cl> term
52
%type <cl> term
46
%type <sd> query
53
%type <sd> query
47
%type <str> complexfieldname
54
%type <str> complexfieldname
48
55
49
 /* Non operator tokens need precedence because of the possibility of
56
                          /* Non operator tokens need precedence because of the possibility of
50
    concatenation which needs to have lower prec than OR */
57
                             concatenation which needs to have lower prec than OR */
51
%left <str> WORD
58
%left <str> WORD
52
%left <str> QUOTED
59
%left <str> QUOTED
53
%left <str> QUALIFIERS
60
%left <str> QUALIFIERS
54
%left AND UCONCAT '(' '-'
61
%left AND UCONCAT '(' '-'
55
%left OR
62
%left OR
...
...
58
65
59
%%
66
%%
60
67
61
topquery: query
68
topquery: query
62
{
69
{
70
    LOGP("END PARSING\n");
63
    d->m_result = $1;
71
    d->m_result = $1;
64
}
72
}
65
73
66
query: 
74
query: 
67
query query %prec UCONCAT
75
query query %prec UCONCAT
68
{
76
{
69
    //cerr << "q: query query" << endl;
77
    LOGP("q: query query\n");
70
    Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_AND, d->m_stemlang);
78
    Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_AND, d->m_stemlang);
71
    addSubQuery(d, sd, $1);
79
    addSubQuery(d, sd, $1);
72
    addSubQuery(d, sd, $2);
80
    addSubQuery(d, sd, $2);
73
    $$ = sd;
81
    $$ = sd;
74
}
82
}
75
| query AND query
83
| query AND query
76
{
84
{
77
    //cerr << "q: query AND query" << endl;
85
    LOGP("q: query AND query\n");
78
    Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_AND, d->m_stemlang);
86
    Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_AND, d->m_stemlang);
79
    addSubQuery(d, sd, $1);
87
    addSubQuery(d, sd, $1);
80
    addSubQuery(d, sd, $3);
88
    addSubQuery(d, sd, $3);
81
    $$ = sd;
89
    $$ = sd;
82
}
90
}
83
| query OR query
91
| query OR query
84
{
92
{
85
    //cerr << "q: query OR query" << endl;
93
    LOGP("q: query OR query\n");
86
    Rcl::SearchData *top = new Rcl::SearchData(Rcl::SCLT_AND, d->m_stemlang);
94
    Rcl::SearchData *top = new Rcl::SearchData(Rcl::SCLT_AND, d->m_stemlang);
87
    Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_OR, d->m_stemlang);
95
    Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_OR, d->m_stemlang);
88
    addSubQuery(d, sd, $1);
96
    addSubQuery(d, sd, $1);
89
    addSubQuery(d, sd, $3);
97
    addSubQuery(d, sd, $3);
90
    addSubQuery(d, top, sd);
98
    addSubQuery(d, top, sd);
91
    $$ = top;
99
    $$ = top;
92
}
100
}
93
| '(' query ')' 
101
| '(' query ')' 
94
{
102
{
95
    //cerr << "q: ( query )" << endl;
103
    LOGP("q: ( query )\n");
96
    $$ = $2;
104
    $$ = $2;
97
}
105
}
98
|
106
|
99
fieldexpr %prec UCONCAT
107
fieldexpr %prec UCONCAT
100
{
108
{
101
    //cerr << "q: fieldexpr" << endl;
109
    LOGP("q: fieldexpr\n");
102
    Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_AND, d->m_stemlang);
110
    Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_AND, d->m_stemlang);
103
    d->addClause(sd, $1);
111
    d->addClause(sd, $1);
104
    $$ = sd;
112
    $$ = sd;
105
}
113
}
106
;
114
;
107
115
108
fieldexpr: term 
116
fieldexpr: term 
109
{
117
{
110
    // cerr << "fe: simple fieldexpr: " << $1->gettext() << endl;
118
    LOGP("fe: simple fieldexpr: " << $1->gettext() << endl);
111
    $$ = $1;
119
    $$ = $1;
112
}
120
}
113
| complexfieldname EQUALS term 
121
| complexfieldname EQUALS term 
114
{
122
{
115
    // cerr << "fe: " << *$1 << " = " << $3->gettext() << endl;
123
    LOGP("fe: " << *$1 << " = " << $3->gettext() << endl);
116
    $3->setfield(*$1);
124
    $3->setfield(*$1);
117
    $3->setrel(Rcl::SearchDataClause::REL_EQUALS);
125
    $3->setrel(Rcl::SearchDataClause::REL_EQUALS);
118
    $$ = $3;
126
    $$ = $3;
119
    delete $1;
127
    delete $1;
120
}
128
}
121
| complexfieldname CONTAINS term 
129
| complexfieldname CONTAINS term 
122
{
130
{
123
    // cerr << "fe: " << *$1 << " : " << $3->gettext() << endl;
131
    LOGP("fe: " << *$1 << " : " << $3->gettext() << endl);
124
    $3->setfield(*$1);
132
    $3->setfield(*$1);
125
    $3->setrel(Rcl::SearchDataClause::REL_CONTAINS);
133
    $3->setrel(Rcl::SearchDataClause::REL_CONTAINS);
126
    $$ = $3;
134
    $$ = $3;
127
    delete $1;
135
    delete $1;
128
}
136
}
129
| complexfieldname SMALLER term 
137
| complexfieldname SMALLER term 
130
{
138
{
131
    // cerr << "fe: " << *$1 << " < " << $3->gettext() << endl;
139
    LOGP(cerr << "fe: " << *$1 << " < " << $3->gettext() << endl);
132
    $3->setfield(*$1);
140
    $3->setfield(*$1);
133
    $3->setrel(Rcl::SearchDataClause::REL_LT);
141
    $3->setrel(Rcl::SearchDataClause::REL_LT);
134
    $$ = $3;
142
    $$ = $3;
135
    delete $1;
143
    delete $1;
136
}
144
}
137
| complexfieldname SMALLEREQ term 
145
| complexfieldname SMALLEREQ term 
138
{
146
{
139
    // cerr << "fe: " << *$1 << " <= " << $3->gettext() << endl;
147
    LOGP("fe: " << *$1 << " <= " << $3->gettext() << endl);
140
    $3->setfield(*$1);
148
    $3->setfield(*$1);
141
    $3->setrel(Rcl::SearchDataClause::REL_LTE);
149
    $3->setrel(Rcl::SearchDataClause::REL_LTE);
142
    $$ = $3;
150
    $$ = $3;
143
    delete $1;
151
    delete $1;
144
}
152
}
145
| complexfieldname GREATER term 
153
| complexfieldname GREATER term 
146
{
154
{
147
    // cerr << "fe: "  << *$1 << " > " << $3->gettext() << endl;
155
    LOGP("fe: "  << *$1 << " > " << $3->gettext() << endl);
148
    $3->setfield(*$1);
156
    $3->setfield(*$1);
149
    $3->setrel(Rcl::SearchDataClause::REL_GT);
157
    $3->setrel(Rcl::SearchDataClause::REL_GT);
150
    $$ = $3;
158
    $$ = $3;
151
    delete $1;
159
    delete $1;
152
}
160
}
153
| complexfieldname GREATEREQ term 
161
| complexfieldname GREATEREQ term 
154
{
162
{
155
    // cerr << "fe: " << *$1 << " >= " << $3->gettext() << endl;
163
    LOGP("fe: " << *$1 << " >= " << $3->gettext() << endl);
156
    $3->setfield(*$1);
164
    $3->setfield(*$1);
157
    $3->setrel(Rcl::SearchDataClause::REL_GTE);
165
    $3->setrel(Rcl::SearchDataClause::REL_GTE);
158
    $$ = $3;
166
    $$ = $3;
159
    delete $1;
167
    delete $1;
160
}
168
}
161
| '-' fieldexpr 
169
| '-' fieldexpr 
162
{
170
{
163
    // cerr << "fe: - fieldexpr[" << $2->gettext() << "]" << endl;
171
    LOGP("fe: - fieldexpr[" << $2->gettext() << "]" << endl);
164
    $2->setexclude(true);
172
    $2->setexclude(true);
165
    $$ = $2;
173
    $$ = $2;
166
}
174
}
167
;
175
;
168
176
169
/* Deal with field names like dc:title */
177
/* Deal with field names like dc:title */
170
complexfieldname: 
178
complexfieldname: 
171
WORD
179
WORD
172
{
180
{
173
    // cerr << "cfn: WORD" << endl;
181
    LOGP("cfn: WORD" << endl);
174
    $$ = $1;
182
    $$ = $1;
175
}
183
}
176
|
184
|
177
complexfieldname CONTAINS WORD
185
complexfieldname CONTAINS WORD
178
{
186
{
179
    // cerr << "cfn: complexfieldname ':' WORD" << endl;
187
    LOGP("cfn: complexfieldname ':' WORD" << endl);
180
    $$ = new string(*$1 + string(":") + *$3);
188
    $$ = new string(*$1 + string(":") + *$3);
181
    delete $1;
189
    delete $1;
182
    delete $3;
190
    delete $3;
183
}
191
}
184
192
185
term: 
193
term: 
186
WORD
194
WORD
187
{
195
{
188
    //cerr << "term[" << *$1 << "]" << endl;
196
    LOGP("term[" << *$1 << "]" << endl);
189
    $$ = new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND, *$1);
197
    $$ = new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND, *$1);
190
    delete $1;
198
    delete $1;
191
}
199
}
192
| qualquote 
200
| qualquote 
193
{
201
{
...
...
195
}
203
}
196
204
197
qualquote: 
205
qualquote: 
198
QUOTED
206
QUOTED
199
{
207
{
200
    // cerr << "QUOTED[" << *$1 << "]" << endl;
208
    LOGP("QUOTED[" << *$1 << "]" << endl);
201
    $$ = new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE, *$1, 0);
209
    $$ = new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE, *$1, 0);
202
    delete $1;
210
    delete $1;
203
}
211
}
204
| QUOTED QUALIFIERS 
212
| QUOTED QUALIFIERS 
205
{
213
{
206
    // cerr << "QUOTED[" << *$1 << "] QUALIFIERS[" << *$2 << "]" << endl;
214
    LOGP("QUOTED[" << *$1 << "] QUALIFIERS[" << *$2 << "]" << endl);
207
    Rcl::SearchDataClauseDist *cl = 
215
    Rcl::SearchDataClauseDist *cl = 
208
        new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE, *$1, 0);
216
        new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE, *$1, 0);
209
    qualify(cl, *$2);
217
    qualify(cl, *$2);
210
    $$ = cl;
218
    $$ = cl;
211
    delete $1;
219
    delete $1;
...
...
316
            }
324
            }
317
            value->push_back(c);
325
            value->push_back(c);
318
            break;
326
            break;
319
        case '"':
327
        case '"':
320
            /* End of string. Look for qualifiers */
328
            /* End of string. Look for qualifiers */
321
            while ((c = d->GETCHAR()) && !isspace(c))
329
            while ((c = d->GETCHAR()) && (isalnum(c) || c == '.'))
322
                d->qualifiers().push_back(c);
330
                d->qualifiers().push_back(c);
331
            d->UNGETCHAR(c);
323
            goto out;
332
            goto out;
324
        default:
333
        default:
325
            value->push_back(c);
334
            value->push_back(c);
326
        }
335
        }
327
    }
336
    }