Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Parser.jay « System.Xml.XPath « System.XML « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c404d9d8e5a95baeeb45b43ef8cf4146012328da (plain)
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
%{
// XPath parser
//
// Author - Piers Haken <piersh@friskit.com>
//

// TODO: FUNCTION_CALL should be a QName, not just a NCName
// TODO: PROCESSING_INSTRUCTION's optional parameter
// TODO: flatten argument/predicate lists in place

using System;

namespace System.Xml.XPath
{
	public class XPathParser
	{

%}

%token ERROR
%token EOF

%token SLASH
%token SLASH2
%token DOT
%token DOT2
%token COLON
%token COLON2
%token COMMA
%token AT

%token FUNCTION_NAME

%token BRACKET_OPEN
%token BRACKET_CLOSE
%token PAREN_OPEN
%token PAREN_CLOSE

%token AND
%token OR
%token DIV
%token MOD
%token PLUS
%token MINUS
%token ASTERISK
%token DOLLAR
%token BAR
%token EQ
%token NE
%token LE
%token GE
%token LT
%token GT

%token ANCESTOR
%token ANCESTOR_OR_SELF
%token ATTRIBUTE
%token CHILD
%token DESCENDANT
%token DESCENDANT_OR_SELF
%token FOLLOWING
%token FOLLOWING_SIBLING
%token NAMESPACE
%token PARENT
%token PRECEDING
%token PRECEDING_SIBLING
%token SELF

%token COMMENT
%token TEXT
%token PROCESSING_INSTRUCTION
%token NODE

%token NUMBER
%token LITERAL
%token NCName


%start Expr


%left AND
%left OR
%left EQ
%left NE
%left LE
%left GE
%left LT
%left GT

%left DIV
%left MOD
%left PLUS
%left MINUS

%%


Expr
	: OrExpr
	;
	
OrExpr
	: AndExpr 
	| OrExpr OR AndExpr
	{
		$$ = new ExprOR ((Expression) $1, (Expression) $3);
	}
	;

AndExpr
	: EqualityExpr 
	| AndExpr AND EqualityExpr 
	{
		$$ = new ExprAND ((Expression) $1, (Expression) $3);
	}
	;

EqualityExpr
	: RelationalExpr 
	| EqualityExpr EQ RelationalExpr 
	{
		$$ = new ExprEQ ((Expression) $1, (Expression) $3);
	}
	| EqualityExpr NE RelationalExpr 
	{
		$$ = new ExprNE ((Expression) $1, (Expression) $3);
	}
	;

RelationalExpr
	: AdditiveExpr 
	| RelationalExpr LT AdditiveExpr 
	{
		$$ = new ExprLT ((Expression) $1, (Expression) $3);
	}
	| RelationalExpr GT AdditiveExpr 
	{
		$$ = new ExprGT ((Expression) $1, (Expression) $3);
	}
	| RelationalExpr LE AdditiveExpr 
	{
		$$ = new ExprLE ((Expression) $1, (Expression) $3);
	}
	| RelationalExpr GE AdditiveExpr 
	{
		$$ = new ExprGE ((Expression) $1, (Expression) $3);
	}
	;

AdditiveExpr
	: MultiplicativeExpr 
	| AdditiveExpr PLUS MultiplicativeExpr
	{
		$$ = new ExprPLUS ((Expression) $1, (Expression) $3);
	}
	| AdditiveExpr MINUS MultiplicativeExpr
	{
		$$ = new ExprMINUS ((Expression) $1, (Expression) $3);
	}
	;

MultiplicativeExpr
	: UnaryExpr 
	| MultiplicativeExpr ASTERISK UnaryExpr 
	{
		$$ = new ExprMULT ((Expression) $1, (Expression) $3);
	}
	| MultiplicativeExpr DIV UnaryExpr
	{
		$$ = new ExprDIV ((Expression) $1, (Expression) $3);
	}
	| MultiplicativeExpr MOD UnaryExpr
	{
		$$ = new ExprMOD ((Expression) $1, (Expression) $3);
	}
	;

UnaryExpr
	: UnionExpr 
	| MINUS UnaryExpr 
	{
		$$ = new ExprNEG ((Expression) $2);
	}
	;

UnionExpr
	: PathExpr 
	| UnionExpr BAR PathExpr
	{
		$$ = new ExprUNION ((NodeSet) $1, (NodeSet) $3);
	}
	;

PathExpr
	: RelativeLocationPath
	| SLASH
	{
		$$ = new ExprRoot ();
	}
	| SLASH RelativeLocationPath
	{
		$$ = new ExprSLASH (new ExprRoot (), (NodeSet) $2);
	}
	| SLASH2 RelativeLocationPath 
	{
		ExprStep exprStep = new ExprStep (new NodeTypeTest (Axes.DescendantOrSelf, NodeTestTypes.Node));
		$$ = new ExprSLASH (new ExprSLASH (new ExprRoot (), exprStep), (NodeSet) $2);
	}
	| FilterExpr 
	| FilterExpr SLASH RelativeLocationPath
	{
		$$ = new ExprSLASH ((NodeSet) $1, (NodeSet) $3);
	}
	| FilterExpr SLASH2 RelativeLocationPath
	{
		ExprStep exprStep = new ExprStep (new NodeTypeTest (Axes.DescendantOrSelf, NodeTestTypes.Node));
		$$ = new ExprSLASH (new ExprSLASH ((NodeSet) $1, exprStep), (NodeSet) $3);
	}
	;

RelativeLocationPath
	: Step
	| RelativeLocationPath SLASH Step 
	{
		$$ = new ExprSLASH ((NodeSet) $1, (NodeSet) $3);
	}
	| RelativeLocationPath SLASH2 Step 
	{
		ExprStep exprStep = new ExprStep (new NodeTypeTest (Axes.DescendantOrSelf, NodeTestTypes.Node));
		$$ = new ExprSLASH (new ExprSLASH ((NodeSet) $1, exprStep), (NodeSet) $3);
	}
	;

Step
	: AxisSpecifier QName ZeroOrMorePredicates
	{
		$$ = new ExprStep (new NodeNameTest ((Axes) $1, (QName) $2), (ExprPredicates) $3);
	}
	| AxisSpecifier ASTERISK ZeroOrMorePredicates
	{
		$$ = new ExprStep (new NodeTypeTest ((Axes) $1, NodeTestTypes.Principal), (ExprPredicates) $3);
	}
	| AxisSpecifier NCName COLON ASTERISK ZeroOrMorePredicates
	{
		$$ = new ExprStep (new NodeNameTestAny ((Axes) $1, (NCName) $2), (ExprPredicates) $5);
	}
	| AxisSpecifier NodeType PAREN_OPEN OptionalLiteral PAREN_CLOSE ZeroOrMorePredicates
	{
		$$ = new ExprStep (new NodeTypeTest ((Axes) $1, (NodeTestTypes) $2, (String) $4), (ExprPredicates) $6);
	}
	| DOT
	{
		$$ = new ExprStep (new NodeTypeTest (Axes.Self, NodeTestTypes.Node));
	}
	| DOT2
	{
		$$ = new ExprStep (new NodeTypeTest (Axes.Parent, NodeTestTypes.Node));
	}
	;

AxisSpecifier
	: /* empty */
	{
		$$ = Axes.Child;
	}
	| AT
	{
		$$ = Axes.Attribute;
	}
	| AxisName COLON2
	{
		$$ = $1;
	}
	;

NodeType
	: COMMENT					{ $$ = NodeTestTypes.Comment; }
	| TEXT						{ $$ = NodeTestTypes.Text; }
	| PROCESSING_INSTRUCTION	{ $$ = NodeTestTypes.ProcessingInstruction; }
	| NODE						{ $$ = NodeTestTypes.Node; }
	;


FilterExpr
	: PrimaryExpr 
	| FilterExpr Predicate 
	{
		$$ = new ExprFilter ((Expression) $1, (Expression) $2);
	}
	;

PrimaryExpr
	: DOLLAR QName
	{
		$$ = new ExprVariable ((QName) $2);
	} 
	| PAREN_OPEN Expr PAREN_CLOSE
	{
		$$ = $2;
	}
	| LITERAL
	{
		$$ = new ExprLiteral ((String) $1);
	}
	| NUMBER
	{
		$$ = new ExprNumber ((double) $1);
	}
	| FunctionCall
	;

FunctionCall
	: FUNCTION_NAME PAREN_OPEN OptionalArgumentList PAREN_CLOSE
	{
		$$ = new ExprFunctionCall ((String) $1, (FunctionArguments) $3);
	}
	;

OptionalArgumentList
	: /* empty */
	| Expr OptionalArgumentListTail
	{
		$$ = new FunctionArguments ((Expression) $1, (FunctionArguments) $2);
	}
	;

OptionalArgumentListTail
	: /* empty */
	| COMMA Expr OptionalArgumentListTail
	{
		$$ = new FunctionArguments ((Expression) $2, (FunctionArguments) $3);
	}
	;


ZeroOrMorePredicates
	: /* empty */
	| Predicate ZeroOrMorePredicates
	{
		$$ = new ExprPredicates ((Expression) $1, (ExprPredicates) $2);
	}
	;

Predicate
	: BRACKET_OPEN Expr BRACKET_CLOSE
	{
		$$ = $2;
	}
	;

AxisName
	: ANCESTOR				{ $$ = Axes.Ancestor; }
	| ANCESTOR_OR_SELF		{ $$ = Axes.AncestorOrSelf; }
	| ATTRIBUTE				{ $$ = Axes.Attribute; }
	| CHILD					{ $$ = Axes.Child; }
	| DESCENDANT			{ $$ = Axes.Descendant; }
	| DESCENDANT_OR_SELF	{ $$ = Axes.DescendantOrSelf; }
	| FOLLOWING				{ $$ = Axes.Following; }
	| FOLLOWING_SIBLING		{ $$ = Axes.FollowingSibling; }
	| NAMESPACE				{ $$ = Axes.Namespace; }
	| PARENT				{ $$ = Axes.Parent; }
	| PRECEDING				{ $$ = Axes.Preceding; }
	| PRECEDING_SIBLING		{ $$ = Axes.PrecedingSibling; }
	| SELF					{ $$ = Axes.Self; }
	;

OptionalLiteral
	: /* empty */
	| LITERAL
	{
		$$ = $1;
	}
	;

QName
	: NCName
	{
		$$ = new NCName ((String) $1);
	}
	| NCName COLON NCName
	{
		$$ = new QName ((String) $1, (String) $3);
	}
	;

%%
	}