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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef AXIOM_XPATH_INTERNALS_PARSER_H
#define AXIOM_XPATH_INTERNALS_PARSER_H
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @defgroup axiom_xpath_parser parser
* @ingroup axiom_xpath
* @{
*/
/* Macros */
/** Get the current character in the expression */
#define AXIOM_XPATH_CURRENT (expr->expr_ptr < expr->expr_len ? \
expr->expr_str[expr->expr_ptr] : -1)
/** Get a character after the current */
#define AXIOM_XPATH_NEXT(ind) (expr->expr_ptr + ind < expr->expr_len ? \
expr->expr_str[expr->expr_ptr + ind] : -1)
/** Increment the pointer to the expression */
#define AXIOM_XPATH_READ(n) (expr->expr_ptr += n)
/** Check if expression has finished parsing */
#define AXIOM_XPATH_HAS_MORE (expr->expr_ptr < expr->expr_len)
/** Skip white spaces */
#define AXIOM_XPATH_SKIP_WHITESPACES \
{ while(AXIOM_XPATH_CURRENT == ' ') \
AXIOM_XPATH_READ(1); \
}
/** Wrape an operation in a self_or_descendent step; used to handle '//' */
#define AXIOM_XPATH_WRAP_SELF_DESCENDANT(_op2) \
axiom_xpath_add_operation(env, expr, AXIOM_XPATH_OPERATION_STEP, \
axiom_xpath_add_operation(env, expr, AXIOM_XPATH_OPERATION_NODE_TEST, \
AXIOM_XPATH_PARSE_END, AXIOM_XPATH_PARSE_END, \
axiom_xpath_create_node_test_node(env), \
axiom_xpath_create_axis(env, AXIOM_XPATH_AXIS_DESCENDANT_OR_SELF)), \
_op2, NULL, NULL)
/** Adds an operation */
#define AXIOM_XPATH_PUSH(_opr, _op1, _op2) axiom_xpath_add_operation( \
env, expr, _opr, _op1, _op2, NULL, NULL)
/** Adds an operation with parameters */
#define AXIOM_XPATH_PUSH_PAR(_opr, _par1, _par2, _op1) axiom_xpath_add_operation( \
env, expr, _opr, _op1, AXIOM_XPATH_PARSE_END, (void *)_par1, (void *)_par2)
/* Functions */
/**
* Add an operation to the operations array
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @param op_type Type of the operation
* @param op1 First operand
* @param op2 Second operand
* @param par1 First parameter
* @param par2 Second parameter
* @return Index of the operation in the array
*/
int axiom_xpath_add_operation(
const axutil_env_t *env,
axiom_xpath_expression_t* expr,
axiom_xpath_operation_type_t op_type,
int op1,
int op2,
void *par1,
void *par2);
/**
* Compile a XPath expression
*
* [14] Expr ::= OrExpr
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the main operation in the array
*/
int axiom_xpath_compile(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile an equals expression
*
* ***Not completed***
* [23] EqualityExpr ::= UnionExpr '=' UnionExpr
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_equalexpr(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile an union
*
* [18] UnionExpr ::= PathExpr
* | UnionExpr '|' PathExpr
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_union(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile a path expression
*
* [19] PathExpr ::= LocationPath
* | FilterExpr
* | FilterExpr '/' RelativeLocationPath
* | FilterExpr '//' RelativeLocationPath
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_path_expression(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile a path expression with a filter
*
* [19] PathExpr ::= FilterExpr
* | FilterExpr '/' RelativeLocationPath
* | FilterExpr '//' RelativeLocationPath
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_path_compile_path_expression_filter(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile a filter expression
*
* 20] FilterExpr ::= PrimaryExpr
* | FilterExpr Predicate
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_filter(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile a location path
*
* [1] LocationPath ::= RelativeLocationPath
* | AbsoluteLocationPath
* [2] AbsoluteLocationPath ::= '/' RelativeLocationPath?
* | AbbreviatedAbsoluteLocationPath
*
* [10] AbbreviatedAbsoluteLocationPath ::= '//' RelativeLocationPath
* [11] AbbreviatedRelativeLocationPath ::= RelativeLocationPath '//' Step
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_location_path(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile a relative location
*
* [3] RelativeLocationPath ::= Step
* | RelativeLocationPath '/' Step
* | AbbreviatedRelativeLocationPath
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_relative_location(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile a step
*
* [4] Step ::= AxisSpecifier NodeTest Predicate*
* | AbbreviatedStep
* [5] AxisSpecifier ::= AxisName '::'
* | AbbreviatedAxisSpecifier
*
* [12] AbbreviatedStep ::= '.' | '..'
* [13] AbbreviatedAxisSpecifier ::= '@'?
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_step(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compiles an OrExpr.
*
* [21] OrExpr ::= AndExpr
* | OrExpr 'or' AndExpr
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_orexpr(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compiles an AndExpr.
*
* [22] AndExpr ::= EqualityExpr
* | AndExpr 'and' EqualityExpr
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_andexpr(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compiles a FunctionCall
*
* [16] FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument )* )? ')'
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_function_call(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compiles an Argument.
*
* [17] Argument ::= Expr
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_argument(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile a node test
*
* [7] NodeTest ::= NameTest
* | NodeType '(' ')'
* | 'processing-instruction' '(' Literal ')'
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
axiom_xpath_node_test_t* axiom_xpath_compile_node_test(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile a predicate(s)
*
* [8] Predicate ::= '[' PredicateExpr ']'
* [9] PredicateExpr ::= Expr
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return Index of the operation in the array
*/
int axiom_xpath_compile_predicate(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile a literal
*
* [29] Literal ::= '"' [^"]* '"'
* | "'" [^']* "'"
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return The literal parsed
*/
axis2_char_t* axiom_xpath_compile_literal(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile a number
*
* [30] Number ::= Digits ('.' Digits?)?
* | '.' Digits
* [31] Digits ::= [0-9]+
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return The number parsed
*/
double* axiom_xpath_compile_number(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Compile a ncname
*
* @param env Environment must not be null
* @param expr A pointer to the XPath expression
* @return The ncname parsed
*/
axis2_char_t* axiom_xpath_compile_ncname(
const axutil_env_t *env,
axiom_xpath_expression_t* expr);
/**
* Get the XPath axis by axis name
*
* [6] AxisName ::= 'ancestor'
* | 'ancestor-or-self'
* | 'attribute'
* | 'child'
* | 'descendant'
* | 'descendant-or-self'
* | 'following'
* | 'following-sibling'
* | 'namespace'
* | 'parent'
* | 'preceding'
* | 'preceding-sibling'
* | 'self'
*
* @param env Environment must not be null
* @param name Name of the axis
* @return XPath axis; returns AXIOM_XPATH_AXIS_NONE if invalid name
*/
axiom_xpath_axis_t axiom_xpath_get_axis(
const axutil_env_t *env,
axis2_char_t* name);
/**
* Create a node test which matches all nodes (*)
*
* @param env Environment must not be null
* @return Node test
*/
axiom_xpath_node_test_t* axiom_xpath_create_node_test_all(
const axutil_env_t *env);
/**
* Create a node test which matches all nodes (nodes())
*
* @param env Environment must not be null
* @return Node test
*/
axiom_xpath_node_test_t* axiom_xpath_create_node_test_node(
const axutil_env_t *env);
/**
* Create a pointer to an axis; allocate memory using the allocator
*
* @param env Environment must not be null
* @param axis XPath axis
* @return Pointer to the axis created
*/
axiom_xpath_axis_t *axiom_xpath_create_axis(
const axutil_env_t *env,
axiom_xpath_axis_t axis);
/** @} */
#ifdef __cplusplus
}
#endif
#endif
|