4 // Author - Piers Haken <piersh@friskit.com>
7 // TODO: FUNCTION_CALL should be a QName, not just a NCName
8 // TODO: PROCESSING_INSTRUCTION's optional parameter
9 // TODO: flatten argument/predicate lists in place
12 using System.Xml.XPath;
15 namespace Mono.Xml.XPath
17 public class XPathParser
19 internal object yyparseDebug (Tokenizer tok)
21 return yyparse (tok, new yydebug.yyDebugSimple ());
62 %token ANCESTOR_OR_SELF
66 %token DESCENDANT_OR_SELF
68 %token FOLLOWING_SIBLING
72 %token PRECEDING_SIBLING
77 %token PROCESSING_INSTRUCTION
113 $$ = new ExprOR ((Expression) $1, (Expression) $3);
119 | AndExpr AND EqualityExpr
121 $$ = new ExprAND ((Expression) $1, (Expression) $3);
127 | EqualityExpr EQ RelationalExpr
129 $$ = new ExprEQ ((Expression) $1, (Expression) $3);
131 | EqualityExpr NE RelationalExpr
133 $$ = new ExprNE ((Expression) $1, (Expression) $3);
139 | RelationalExpr LT AdditiveExpr
141 $$ = new ExprLT ((Expression) $1, (Expression) $3);
143 | RelationalExpr GT AdditiveExpr
145 $$ = new ExprGT ((Expression) $1, (Expression) $3);
147 | RelationalExpr LE AdditiveExpr
149 $$ = new ExprLE ((Expression) $1, (Expression) $3);
151 | RelationalExpr GE AdditiveExpr
153 $$ = new ExprGE ((Expression) $1, (Expression) $3);
159 | AdditiveExpr PLUS MultiplicativeExpr
161 $$ = new ExprPLUS ((Expression) $1, (Expression) $3);
163 | AdditiveExpr MINUS MultiplicativeExpr
165 $$ = new ExprMINUS ((Expression) $1, (Expression) $3);
171 | MultiplicativeExpr ASTERISK UnaryExpr
173 $$ = new ExprMULT ((Expression) $1, (Expression) $3);
175 | MultiplicativeExpr DIV UnaryExpr
177 $$ = new ExprDIV ((Expression) $1, (Expression) $3);
179 | MultiplicativeExpr MOD UnaryExpr
181 $$ = new ExprMOD ((Expression) $1, (Expression) $3);
189 $$ = new ExprNEG ((Expression) $2);
195 | UnionExpr BAR PathExpr
197 $$ = new ExprUNION ((NodeSet) $1, (NodeSet) $3);
202 : RelativeLocationPath
205 $$ = new ExprRoot ();
207 | SLASH RelativeLocationPath
209 $$ = new ExprSLASH (new ExprRoot (), (NodeSet) $2);
211 | SLASH2 RelativeLocationPath
213 ExprStep exprStep = new ExprStep (new NodeTypeTest (Axes.DescendantOrSelf, XPathNodeType.All));
214 $$ = new ExprSLASH (new ExprSLASH (new ExprRoot (), exprStep), (NodeSet) $2);
217 | FilterExpr SLASH RelativeLocationPath
219 $$ = new ExprSLASH ((Expression) $1, (NodeSet) $3);
221 | FilterExpr SLASH2 RelativeLocationPath
223 ExprStep exprStep = new ExprStep (new NodeTypeTest (Axes.DescendantOrSelf, XPathNodeType.All));
224 $$ = new ExprSLASH (new ExprSLASH ((Expression) $1, exprStep), (NodeSet) $3);
230 | RelativeLocationPath SLASH Step
232 $$ = new ExprSLASH ((Expression) $1, (NodeSet) $3);
234 | RelativeLocationPath SLASH2 Step
236 ExprStep exprStep = new ExprStep (new NodeTypeTest (Axes.DescendantOrSelf, XPathNodeType.All));
237 $$ = new ExprSLASH (new ExprSLASH ((Expression) $1, exprStep), (NodeSet) $3);
242 : AxisSpecifier QName ZeroOrMorePredicates
244 $$ = new ExprStep (new NodeNameTest ((Axes) $1, (QName) $2), (ExprPredicates) $3);
246 | AxisSpecifier ASTERISK ZeroOrMorePredicates
248 $$ = new ExprStep (new NodeTypeTest ((Axes) $1), (ExprPredicates) $3);
250 | AxisSpecifier NodeType PAREN_OPEN OptionalLiteral PAREN_CLOSE ZeroOrMorePredicates
252 $$ = new ExprStep (new NodeTypeTest ((Axes) $1, (XPathNodeType) $2, (String) $4), (ExprPredicates) $6);
256 $$ = new ExprStep (new NodeTypeTest (Axes.Self, XPathNodeType.All));
260 $$ = new ExprStep (new NodeTypeTest (Axes.Parent, XPathNodeType.All));
280 : COMMENT { $$ = XPathNodeType.Comment; }
281 | TEXT { $$ = XPathNodeType.Text; }
282 | PROCESSING_INSTRUCTION { $$ = XPathNodeType.ProcessingInstruction; }
283 | NODE { $$ = XPathNodeType.All; }
289 | FilterExpr Predicate
291 $$ = new ExprFilter ((Expression) $1, (Expression) $2);
298 $$ = new ExprVariable ((QName) $2);
300 | PAREN_OPEN Expr PAREN_CLOSE
306 $$ = new ExprLiteral ((String) $1);
310 $$ = new ExprNumber ((double) $1);
316 : FUNCTION_NAME PAREN_OPEN OptionalArgumentList PAREN_CLOSE
318 $$ = new ExprFunctionCall ((String) $1, (FunctionArguments) $3);
324 | Expr OptionalArgumentListTail
326 $$ = new FunctionArguments ((Expression) $1, (FunctionArguments) $2);
330 OptionalArgumentListTail
332 | COMMA Expr OptionalArgumentListTail
334 $$ = new FunctionArguments ((Expression) $2, (FunctionArguments) $3);
341 | Predicate ZeroOrMorePredicates
343 $$ = new ExprPredicates ((Expression) $1, (ExprPredicates) $2);
348 : BRACKET_OPEN Expr BRACKET_CLOSE
355 : ANCESTOR { $$ = Axes.Ancestor; }
356 | ANCESTOR_OR_SELF { $$ = Axes.AncestorOrSelf; }
357 | ATTRIBUTE { $$ = Axes.Attribute; }
358 | CHILD { $$ = Axes.Child; }
359 | DESCENDANT { $$ = Axes.Descendant; }
360 | DESCENDANT_OR_SELF { $$ = Axes.DescendantOrSelf; }
361 | FOLLOWING { $$ = Axes.Following; }
362 | FOLLOWING_SIBLING { $$ = Axes.FollowingSibling; }
363 | NAMESPACE { $$ = Axes.Namespace; }
364 | PARENT { $$ = Axes.Parent; }
365 | PRECEDING { $$ = Axes.Preceding; }
366 | PRECEDING_SIBLING { $$ = Axes.PrecedingSibling; }
367 | SELF { $$ = Axes.Self; }
378 $$ = new NCName ((String) $1);
380 | NCName COLON ASTERISK
382 $$ = new QName ((String) $1, null);
384 | NCName COLON NCName
386 $$ = new QName ((String) $1, (String) $3);