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 yyparseSafe (Tokenizer tok)
21 return yyparseSafe (tok, null);
24 internal object yyparseSafe (Tokenizer tok, object yyDebug)
28 return yyparse (tok, yyDebug);
30 catch (XPathException e)
36 throw new XPathException ("Error during parse", e);
40 internal object yyparseDebug (Tokenizer tok)
42 return yyparseSafe (tok, new yydebug.yyDebugSimple ());
83 %token ANCESTOR_OR_SELF
87 %token DESCENDANT_OR_SELF
89 %token FOLLOWING_SIBLING
93 %token PRECEDING_SIBLING
98 %token PROCESSING_INSTRUCTION
134 $$ = new ExprOR ((Expression) $1, (Expression) $3);
140 | AndExpr AND EqualityExpr
142 $$ = new ExprAND ((Expression) $1, (Expression) $3);
148 | EqualityExpr EQ RelationalExpr
150 $$ = new ExprEQ ((Expression) $1, (Expression) $3);
152 | EqualityExpr NE RelationalExpr
154 $$ = new ExprNE ((Expression) $1, (Expression) $3);
160 | RelationalExpr LT AdditiveExpr
162 $$ = new ExprLT ((Expression) $1, (Expression) $3);
164 | RelationalExpr GT AdditiveExpr
166 $$ = new ExprGT ((Expression) $1, (Expression) $3);
168 | RelationalExpr LE AdditiveExpr
170 $$ = new ExprLE ((Expression) $1, (Expression) $3);
172 | RelationalExpr GE AdditiveExpr
174 $$ = new ExprGE ((Expression) $1, (Expression) $3);
180 | AdditiveExpr PLUS MultiplicativeExpr
182 $$ = new ExprPLUS ((Expression) $1, (Expression) $3);
184 | AdditiveExpr MINUS MultiplicativeExpr
186 $$ = new ExprMINUS ((Expression) $1, (Expression) $3);
192 | MultiplicativeExpr ASTERISK UnaryExpr
194 $$ = new ExprMULT ((Expression) $1, (Expression) $3);
196 | MultiplicativeExpr DIV UnaryExpr
198 $$ = new ExprDIV ((Expression) $1, (Expression) $3);
200 | MultiplicativeExpr MOD UnaryExpr
202 $$ = new ExprMOD ((Expression) $1, (Expression) $3);
210 $$ = new ExprNEG ((Expression) $2);
216 | UnionExpr BAR PathExpr
218 $$ = new ExprUNION ((NodeSet) $1, (NodeSet) $3);
223 : RelativeLocationPath
226 $$ = new ExprRoot ();
228 | SLASH RelativeLocationPath
230 $$ = new ExprSLASH (new ExprRoot (), (NodeSet) $2);
232 | SLASH2 RelativeLocationPath
234 ExprStep exprStep = new ExprStep (new NodeTypeTest (Axes.DescendantOrSelf, XPathNodeType.All));
235 $$ = new ExprSLASH (new ExprSLASH (new ExprRoot (), exprStep), (NodeSet) $2);
238 | FilterExpr SLASH RelativeLocationPath
240 $$ = new ExprSLASH ((Expression) $1, (NodeSet) $3);
242 | FilterExpr SLASH2 RelativeLocationPath
244 ExprStep exprStep = new ExprStep (new NodeTypeTest (Axes.DescendantOrSelf, XPathNodeType.All));
245 $$ = new ExprSLASH (new ExprSLASH ((Expression) $1, exprStep), (NodeSet) $3);
251 | RelativeLocationPath SLASH Step
253 $$ = new ExprSLASH ((Expression) $1, (NodeSet) $3);
255 | RelativeLocationPath SLASH2 Step
257 ExprStep exprStep = new ExprStep (new NodeTypeTest (Axes.DescendantOrSelf, XPathNodeType.All));
258 $$ = new ExprSLASH (new ExprSLASH ((Expression) $1, exprStep), (NodeSet) $3);
263 : AxisSpecifier QName ZeroOrMorePredicates
265 $$ = new ExprStep (new NodeNameTest ((Axes) $1, (QName) $2), (ExprPredicates) $3);
267 | AxisSpecifier ASTERISK ZeroOrMorePredicates
269 $$ = new ExprStep (new NodeTypeTest ((Axes) $1), (ExprPredicates) $3);
271 | AxisSpecifier NodeType PAREN_OPEN OptionalLiteral PAREN_CLOSE ZeroOrMorePredicates
273 $$ = new ExprStep (new NodeTypeTest ((Axes) $1, (XPathNodeType) $2, (String) $4), (ExprPredicates) $6);
277 $$ = new ExprStep (new NodeTypeTest (Axes.Self, XPathNodeType.All));
281 $$ = new ExprStep (new NodeTypeTest (Axes.Parent, XPathNodeType.All));
301 : COMMENT { $$ = XPathNodeType.Comment; }
302 | TEXT { $$ = XPathNodeType.Text; }
303 | PROCESSING_INSTRUCTION { $$ = XPathNodeType.ProcessingInstruction; }
304 | NODE { $$ = XPathNodeType.All; }
310 | FilterExpr Predicate
312 $$ = new ExprFilter ((Expression) $1, (Expression) $2);
319 $$ = new ExprVariable ((QName) $2);
321 | PAREN_OPEN Expr PAREN_CLOSE
327 $$ = new ExprLiteral ((String) $1);
331 $$ = new ExprNumber ((double) $1);
337 : FUNCTION_NAME PAREN_OPEN OptionalArgumentList PAREN_CLOSE
339 $$ = new ExprFunctionCall ((String) $1, (FunctionArguments) $3);
345 | Expr OptionalArgumentListTail
347 $$ = new FunctionArguments ((Expression) $1, (FunctionArguments) $2);
351 OptionalArgumentListTail
353 | COMMA Expr OptionalArgumentListTail
355 $$ = new FunctionArguments ((Expression) $2, (FunctionArguments) $3);
362 | Predicate ZeroOrMorePredicates
364 $$ = new ExprPredicates ((Expression) $1, (ExprPredicates) $2);
369 : BRACKET_OPEN Expr BRACKET_CLOSE
376 : ANCESTOR { $$ = Axes.Ancestor; }
377 | ANCESTOR_OR_SELF { $$ = Axes.AncestorOrSelf; }
378 | ATTRIBUTE { $$ = Axes.Attribute; }
379 | CHILD { $$ = Axes.Child; }
380 | DESCENDANT { $$ = Axes.Descendant; }
381 | DESCENDANT_OR_SELF { $$ = Axes.DescendantOrSelf; }
382 | FOLLOWING { $$ = Axes.Following; }
383 | FOLLOWING_SIBLING { $$ = Axes.FollowingSibling; }
384 | NAMESPACE { $$ = Axes.Namespace; }
385 | PARENT { $$ = Axes.Parent; }
386 | PRECEDING { $$ = Axes.Preceding; }
387 | PRECEDING_SIBLING { $$ = Axes.PrecedingSibling; }
388 | SELF { $$ = Axes.Self; }
399 $$ = new NCName ((String) $1);
401 | NCName COLON ASTERISK
403 $$ = new QName ((String) $1, null);
405 | NCName COLON NCName
407 $$ = new QName ((String) $1, (String) $3);