PostgreSQL Source Code: src/backend/utils/adt/tsvector_parser.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
38{
44 bool oprisdelim;
45 bool is_tsquery;
48};
49
50
51
52
53
54
55
58{
60
70 state->escontext = escontext;
71
73}
74
75
76
77
78
79
80void
82{
84}
85
86
87
88
89void
91{
94}
95
96
97#define RESIZEPRSBUF \
98do { \
99 int clen = curpos - state->word; \
100 if ( clen + state->eml >= state->len ) \
101 { \
102 state->len *= 2; \
103 state->word = (char *) repalloc(state->word, state->len); \
104 curpos = state->word + clen; \
105 } \
106} while (0)
107
108
109#define RETURN_TOKEN \
110do { \
111 if (pos_ptr != NULL) \
112 { \
113 *pos_ptr = pos; \
114 *poslen = npos; \
115 } \
116 else if (pos != NULL) \
117 pfree(pos); \
118 \
119 if (strval != NULL) \
120 *strval = state->word; \
121 if (lenval != NULL) \
122 *lenval = curpos - state->word; \
123 if (endptr != NULL) \
124 *endptr = state->prsbuf; \
125 return true; \
126} while(0)
127
128
129
130#define WAITWORD 1
131#define WAITENDWORD 2
132#define WAITNEXTCHAR 3
133#define WAITENDCMPLX 4
134#define WAITPOSINFO 5
135#define INPOSINFO 6
136#define WAITPOSDELIM 7
137#define WAITCHARCMPLX 8
138
139#define PRSSYNTAXERROR return prssyntaxerror(state)
140
141static bool
143{
145 (errcode(ERRCODE_SYNTAX_ERROR),
146 state->is_tsquery ?
147 errmsg("syntax error in tsquery: \"%s\"", state->bufstart) :
148 errmsg("syntax error in tsvector: \"%s\"", state->bufstart)));
149
150 return false;
151}
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175bool
177 char **strval, int *lenval,
179 char **endptr)
180{
181 int oldstate = 0;
182 char *curpos = state->word;
184
185
186
187
188
190 int npos = 0;
191 int posalen = 0;
192
193 while (1)
194 {
196 {
197 if (*(state->prsbuf) == '\0')
198 return false;
202 {
205 }
209 else if (!isspace((unsigned char) *state->prsbuf))
210 {
214 }
215 }
217 {
218 if (*(state->prsbuf) == '\0')
220 (errcode(ERRCODE_SYNTAX_ERROR),
221 errmsg("there is no escaped character: \"%s\"",
222 state->bufstart)));
223 else
224 {
228 Assert(oldstate != 0);
229 statecode = oldstate;
230 }
231 }
233 {
235 {
238 }
239 else if (isspace((unsigned char) *state->prsbuf) || *(state->prsbuf) == '\0' ||
242 {
244 if (curpos == state->word)
246 *(curpos) = '\0';
248 }
250 {
251 if (curpos == state->word)
253 *(curpos) = '\0';
254 if (state->oprisdelim)
256 else
258 }
259 else
260 {
264 }
265 }
267 {
269 {
271 }
273 {
276 }
277 else if (*(state->prsbuf) == '\0')
279 else
280 {
284 }
285 }
287 {
289 {
294 }
295 else
296 {
298 *(curpos) = '\0';
299 if (curpos == state->word)
301 if (state->oprisdelim)
302 {
303
305 }
306 else
308 continue;
309 }
310 }
312 {
315 else
317 }
319 {
320 if (isdigit((unsigned char) *state->prsbuf))
321 {
322 if (posalen == 0)
323 {
324 posalen = 4;
326 npos = 0;
327 }
328 else if (npos + 1 >= posalen)
329 {
330 posalen *= 2;
332 }
333 npos++;
335
338 (errcode(ERRCODE_SYNTAX_ERROR),
339 errmsg("wrong position info in tsvector: \"%s\"",
340 state->bufstart)));
343 }
344 else
346 }
348 {
352 {
356 }
358 {
362 }
364 {
368 }
370 {
374 }
375 else if (isspace((unsigned char) *state->prsbuf) ||
376 *(state->prsbuf) == '\0')
378 else if (!isdigit((unsigned char) *state->prsbuf))
380 }
381 else
382 elog(ERROR, "unrecognized state in gettoken_tsvector: %d",
383 statecode);
384
385
387 }
388}
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define errsave(context,...)
#define palloc_object(type)
#define repalloc_array(pointer, type, count)
#define palloc_array(type, count)
Assert(PointerIsAligned(start, uint64))
int pg_database_encoding_max_length(void)
int pg_mblen(const char *mbstr)
void pfree(void *pointer)
#define WEP_SETWEIGHT(x, v)
#define P_TSV_OPR_IS_DELIM
void reset_tsvector_parser(TSVectorParseState state, char *input)
void close_tsvector_parser(TSVectorParseState state)
static bool prssyntaxerror(TSVectorParseState state)
bool gettoken_tsvector(TSVectorParseState state, char **strval, int *lenval, WordEntryPos **pos_ptr, int *poslen, char **endptr)
TSVectorParseState init_tsvector_parser(char *input, int flags, Node *escontext)