ws-js
Version:
WS-* implementation for node
1,653 lines (1,510 loc) • 123 kB
JavaScript
/*
* xpath.js
*
* An XPath 1.0 library for JavaScript.
*
* Cameron McCormack <cam (at) mcc.id.au>
*
* This work is licensed under the Creative Commons Attribution-ShareAlike
* License. To view a copy of this license, visit
*
* http://creativecommons.org/licenses/by-sa/2.0/
*
* or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford,
* California 94305, USA.
*
* Revision 20: April 26, 2011
* Fixed a typo resulting in FIRST_ORDERED_NODE_TYPE results being wrong,
* thanks to <shi_a009 (at) hotmail.com>.
*
* Revision 19: November 29, 2005
* Nodesets now store their nodes in a height balanced tree, increasing
* performance for the common case of selecting nodes in document order,
* thanks to Sébastien Cramatte <contact (at) zeninteractif.com>.
* AVL tree code adapted from Raimund Neumann <rnova (at) gmx.net>.
*
* Revision 18: October 27, 2005
* DOM 3 XPath support. Caveats:
* - namespace prefixes aren't resolved in XPathEvaluator.createExpression,
* but in XPathExpression.evaluate.
* - XPathResult.invalidIteratorState is not implemented.
*
* Revision 17: October 25, 2005
* Some core XPath function fixes and a patch to avoid crashing certain
* versions of MSXML in PathExpr.prototype.getOwnerElement, thanks to
* Sébastien Cramatte <contact (at) zeninteractif.com>.
*
* Revision 16: September 22, 2005
* Workarounds for some IE 5.5 deficiencies.
* Fixed problem with prefix node tests on attribute nodes.
*
* Revision 15: May 21, 2005
* Fixed problem with QName node tests on elements with an xmlns="...".
*
* Revision 14: May 19, 2005
* Fixed QName node tests on attribute node regression.
*
* Revision 13: May 3, 2005
* Node tests are case insensitive now if working in an HTML DOM.
*
* Revision 12: April 26, 2005
* Updated licence. Slight code changes to enable use of Dean
* Edwards' script compression, http://dean.edwards.name/packer/ .
*
* Revision 11: April 23, 2005
* Fixed bug with 'and' and 'or' operators, fix thanks to
* Sandy McArthur <sandy (at) mcarthur.org>.
*
* Revision 10: April 15, 2005
* Added support for a virtual root node, supposedly helpful for
* implementing XForms. Fixed problem with QName node tests and
* the parent axis.
*
* Revision 9: March 17, 2005
* Namespace resolver tweaked so using the document node as the context
* for namespace lookups is equivalent to using the document element.
*
* Revision 8: February 13, 2005
* Handle implicit declaration of 'xmlns' namespace prefix.
* Fixed bug when comparing nodesets.
* Instance data can now be associated with a FunctionResolver, and
* workaround for MSXML not supporting 'localName' and 'getElementById',
* thanks to Grant Gongaware.
* Fix a few problems when the context node is the root node.
*
* Revision 7: February 11, 2005
* Default namespace resolver fix from Grant Gongaware
* <grant (at) gongaware.com>.
*
* Revision 6: February 10, 2005
* Fixed bug in 'number' function.
*
* Revision 5: February 9, 2005
* Fixed bug where text nodes not getting converted to string values.
*
* Revision 4: January 21, 2005
* Bug in 'name' function, fix thanks to Bill Edney.
* Fixed incorrect processing of namespace nodes.
* Fixed NamespaceResolver to resolve 'xml' namespace.
* Implemented union '|' operator.
*
* Revision 3: January 14, 2005
* Fixed bug with nodeset comparisons, bug lexing < and >.
*
* Revision 2: October 26, 2004
* QName node test namespace handling fixed. Few other bug fixes.
*
* Revision 1: August 13, 2004
* Bug fixes from William J. Edney <bedney (at) technicalpursuit.com>.
* Added minimal licence.
*
* Initial version: June 14, 2004
*/
// XPathParser ///////////////////////////////////////////////////////////////
XPathParser.prototype = new Object();
XPathParser.prototype.constructor = XPathParser;
XPathParser.superclass = Object.prototype;
function XPathParser() {
this.init();
}
XPathParser.prototype.init = function() {
this.reduceActions = [];
this.reduceActions[3] = function(rhs) {
return new OrOperation(rhs[0], rhs[2]);
};
this.reduceActions[5] = function(rhs) {
return new AndOperation(rhs[0], rhs[2]);
};
this.reduceActions[7] = function(rhs) {
return new EqualsOperation(rhs[0], rhs[2]);
};
this.reduceActions[8] = function(rhs) {
return new NotEqualOperation(rhs[0], rhs[2]);
};
this.reduceActions[10] = function(rhs) {
return new LessThanOperation(rhs[0], rhs[2]);
};
this.reduceActions[11] = function(rhs) {
return new GreaterThanOperation(rhs[0], rhs[2]);
};
this.reduceActions[12] = function(rhs) {
return new LessThanOrEqualOperation(rhs[0], rhs[2]);
};
this.reduceActions[13] = function(rhs) {
return new GreaterThanOrEqualOperation(rhs[0], rhs[2]);
};
this.reduceActions[15] = function(rhs) {
return new PlusOperation(rhs[0], rhs[2]);
};
this.reduceActions[16] = function(rhs) {
return new MinusOperation(rhs[0], rhs[2]);
};
this.reduceActions[18] = function(rhs) {
return new MultiplyOperation(rhs[0], rhs[2]);
};
this.reduceActions[19] = function(rhs) {
return new DivOperation(rhs[0], rhs[2]);
};
this.reduceActions[20] = function(rhs) {
return new ModOperation(rhs[0], rhs[2]);
};
this.reduceActions[22] = function(rhs) {
return new UnaryMinusOperation(rhs[1]);
};
this.reduceActions[24] = function(rhs) {
return new BarOperation(rhs[0], rhs[2]);
};
this.reduceActions[25] = function(rhs) {
return new PathExpr(undefined, undefined, rhs[0]);
};
this.reduceActions[27] = function(rhs) {
rhs[0].locationPath = rhs[2];
return rhs[0];
};
this.reduceActions[28] = function(rhs) {
rhs[0].locationPath = rhs[2];
rhs[0].locationPath.steps.unshift(new Step(Step.DESCENDANTORSELF, new NodeTest(NodeTest.NODE, undefined), []));
return rhs[0];
};
this.reduceActions[29] = function(rhs) {
return new PathExpr(rhs[0], [], undefined);
};
this.reduceActions[30] = function(rhs) {
if (Utilities.instance_of(rhs[0], PathExpr)) {
if (rhs[0].filterPredicates == undefined) {
rhs[0].filterPredicates = [];
}
rhs[0].filterPredicates.push(rhs[1]);
return rhs[0];
} else {
return new PathExpr(rhs[0], [rhs[1]], undefined);
}
};
this.reduceActions[32] = function(rhs) {
return rhs[1];
};
this.reduceActions[33] = function(rhs) {
return new XString(rhs[0]);
};
this.reduceActions[34] = function(rhs) {
return new XNumber(rhs[0]);
};
this.reduceActions[36] = function(rhs) {
return new FunctionCall(rhs[0], []);
};
this.reduceActions[37] = function(rhs) {
return new FunctionCall(rhs[0], rhs[2]);
};
this.reduceActions[38] = function(rhs) {
return [ rhs[0] ];
};
this.reduceActions[39] = function(rhs) {
rhs[2].unshift(rhs[0]);
return rhs[2];
};
this.reduceActions[43] = function(rhs) {
return new LocationPath(true, []);
};
this.reduceActions[44] = function(rhs) {
rhs[1].absolute = true;
return rhs[1];
};
this.reduceActions[46] = function(rhs) {
return new LocationPath(false, [ rhs[0] ]);
};
this.reduceActions[47] = function(rhs) {
rhs[0].steps.push(rhs[2]);
return rhs[0];
};
this.reduceActions[49] = function(rhs) {
return new Step(rhs[0], rhs[1], []);
};
this.reduceActions[50] = function(rhs) {
return new Step(Step.CHILD, rhs[0], []);
};
this.reduceActions[51] = function(rhs) {
return new Step(rhs[0], rhs[1], rhs[2]);
};
this.reduceActions[52] = function(rhs) {
return new Step(Step.CHILD, rhs[0], rhs[1]);
};
this.reduceActions[54] = function(rhs) {
return [ rhs[0] ];
};
this.reduceActions[55] = function(rhs) {
rhs[1].unshift(rhs[0]);
return rhs[1];
};
this.reduceActions[56] = function(rhs) {
if (rhs[0] == "ancestor") {
return Step.ANCESTOR;
} else if (rhs[0] == "ancestor-or-self") {
return Step.ANCESTORORSELF;
} else if (rhs[0] == "attribute") {
return Step.ATTRIBUTE;
} else if (rhs[0] == "child") {
return Step.CHILD;
} else if (rhs[0] == "descendant") {
return Step.DESCENDANT;
} else if (rhs[0] == "descendant-or-self") {
return Step.DESCENDANTORSELF;
} else if (rhs[0] == "following") {
return Step.FOLLOWING;
} else if (rhs[0] == "following-sibling") {
return Step.FOLLOWINGSIBLING;
} else if (rhs[0] == "namespace") {
return Step.NAMESPACE;
} else if (rhs[0] == "parent") {
return Step.PARENT;
} else if (rhs[0] == "preceding") {
return Step.PRECEDING;
} else if (rhs[0] == "preceding-sibling") {
return Step.PRECEDINGSIBLING;
} else if (rhs[0] == "self") {
return Step.SELF;
}
return -1;
};
this.reduceActions[57] = function(rhs) {
return Step.ATTRIBUTE;
};
this.reduceActions[59] = function(rhs) {
if (rhs[0] == "comment") {
return new NodeTest(NodeTest.COMMENT, undefined);
} else if (rhs[0] == "text") {
return new NodeTest(NodeTest.TEXT, undefined);
} else if (rhs[0] == "processing-instruction") {
return new NodeTest(NodeTest.PI, undefined);
} else if (rhs[0] == "node") {
return new NodeTest(NodeTest.NODE, undefined);
}
return new NodeTest(-1, undefined);
};
this.reduceActions[60] = function(rhs) {
return new NodeTest(NodeTest.PI, rhs[2]);
};
this.reduceActions[61] = function(rhs) {
return rhs[1];
};
this.reduceActions[63] = function(rhs) {
rhs[1].absolute = true;
rhs[1].steps.unshift(new Step(Step.DESCENDANTORSELF, new NodeTest(NodeTest.NODE, undefined), []));
return rhs[1];
};
this.reduceActions[64] = function(rhs) {
rhs[0].steps.push(new Step(Step.DESCENDANTORSELF, new NodeTest(NodeTest.NODE, undefined), []));
rhs[0].steps.push(rhs[2]);
return rhs[0];
};
this.reduceActions[65] = function(rhs) {
return new Step(Step.SELF, new NodeTest(NodeTest.NODE, undefined), []);
};
this.reduceActions[66] = function(rhs) {
return new Step(Step.PARENT, new NodeTest(NodeTest.NODE, undefined), []);
};
this.reduceActions[67] = function(rhs) {
return new VariableReference(rhs[1]);
};
this.reduceActions[68] = function(rhs) {
return new NodeTest(NodeTest.NAMETESTANY, undefined);
};
this.reduceActions[69] = function(rhs) {
var prefix = rhs[0].substring(0, rhs[0].indexOf(":"));
return new NodeTest(NodeTest.NAMETESTPREFIXANY, prefix);
};
this.reduceActions[70] = function(rhs) {
return new NodeTest(NodeTest.NAMETESTQNAME, rhs[0]);
};
};
XPathParser.actionTable = [
" s s sssssssss s ss s ss",
" s ",
"r rrrrrrrrr rrrrrrr rr r ",
" rrrrr ",
" s s sssssssss s ss s ss",
"rs rrrrrrrr s sssssrrrrrr rrs rs ",
" s s sssssssss s ss s ss",
" s ",
" s ",
"r rrrrrrrrr rrrrrrr rr rr ",
"r rrrrrrrrr rrrrrrr rr rr ",
"r rrrrrrrrr rrrrrrr rr rr ",
"r rrrrrrrrr rrrrrrr rr rr ",
"r rrrrrrrrr rrrrrrr rr rr ",
" s ",
" s ",
" s s sssss s s ",
"r rrrrrrrrr rrrrrrr rr r ",
"a ",
"r s rr r ",
"r sr rr r ",
"r s rr s rr r ",
"r rssrr rss rr r ",
"r rrrrr rrrss rr r ",
"r rrrrrsss rrrrr rr r ",
"r rrrrrrrr rrrrr rr r ",
"r rrrrrrrr rrrrrs rr r ",
"r rrrrrrrr rrrrrr rr r ",
"r rrrrrrrr rrrrrr rr r ",
"r srrrrrrrr rrrrrrs rr sr ",
"r srrrrrrrr rrrrrrs rr r ",
"r rrrrrrrrr rrrrrrr rr rr ",
"r rrrrrrrrr rrrrrrr rr rr ",
"r rrrrrrrrr rrrrrrr rr rr ",
"r rrrrrrrr rrrrrr rr r ",
"r rrrrrrrr rrrrrr rr r ",
"r rrrrrrrrr rrrrrrr rr r ",
"r rrrrrrrrr rrrrrrr rr r ",
" sssss ",
"r rrrrrrrrr rrrrrrr rr sr ",
"r rrrrrrrrr rrrrrrr rr r ",
"r rrrrrrrrr rrrrrrr rr rr ",
"r rrrrrrrrr rrrrrrr rr rr ",
" s ",
"r srrrrrrrr rrrrrrs rr r ",
"r rrrrrrrr rrrrr rr r ",
" s ",
" s ",
" rrrrr ",
" s s sssssssss s sss s ss",
"r srrrrrrrr rrrrrrs rr r ",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss s ss s ss",
" s s sssssssss ss s ss",
" s s sssssssss s ss s ss",
" s s sssss s s ",
" s s sssss s s ",
"r rrrrrrrrr rrrrrrr rr rr ",
" s s sssss s s ",
" s s sssss s s ",
"r rrrrrrrrr rrrrrrr rr sr ",
"r rrrrrrrrr rrrrrrr rr sr ",
"r rrrrrrrrr rrrrrrr rr r ",
"r rrrrrrrrr rrrrrrr rr rr ",
" s ",
"r rrrrrrrrr rrrrrrr rr rr ",
"r rrrrrrrrr rrrrrrr rr rr ",
" rr ",
" s ",
" rs ",
"r sr rr r ",
"r s rr s rr r ",
"r rssrr rss rr r ",
"r rssrr rss rr r ",
"r rrrrr rrrss rr r ",
"r rrrrr rrrss rr r ",
"r rrrrr rrrss rr r ",
"r rrrrr rrrss rr r ",
"r rrrrrsss rrrrr rr r ",
"r rrrrrsss rrrrr rr r ",
"r rrrrrrrr rrrrr rr r ",
"r rrrrrrrr rrrrr rr r ",
"r rrrrrrrr rrrrr rr r ",
"r rrrrrrrr rrrrrr rr r ",
" r ",
" s ",
"r srrrrrrrr rrrrrrs rr r ",
"r srrrrrrrr rrrrrrs rr r ",
"r rrrrrrrrr rrrrrrr rr r ",
"r rrrrrrrrr rrrrrrr rr r ",
"r rrrrrrrrr rrrrrrr rr r ",
"r rrrrrrrrr rrrrrrr rr r ",
"r rrrrrrrrr rrrrrrr rr rr ",
"r rrrrrrrrr rrrrrrr rr rr ",
" s s sssssssss s ss s ss",
"r rrrrrrrrr rrrrrrr rr rr ",
" r "
];
XPathParser.actionTableNumber = [
" 1 0 /.-,+*)(' & %$ # \"!",
" J ",
"a aaaaaaaaa aaaaaaa aa a ",
" YYYYY ",
" 1 0 /.-,+*)(' & %$ # \"!",
"K1 KKKKKKKK . +*)('KKKKKK KK# K\" ",
" 1 0 /.-,+*)(' & %$ # \"!",
" N ",
" O ",
"e eeeeeeeee eeeeeee ee ee ",
"f fffffffff fffffff ff ff ",
"d ddddddddd ddddddd dd dd ",
"B BBBBBBBBB BBBBBBB BB BB ",
"A AAAAAAAAA AAAAAAA AA AA ",
" P ",
" Q ",
" 1 . +*)(' # \" ",
"b bbbbbbbbb bbbbbbb bb b ",
" ",
"! S !! ! ",
"\" T\" \"\" \" ",
"$ V $$ U $$ $ ",
"& &ZY&& &XW && & ",
") ))))) )))\\[ )) ) ",
". ....._^] ..... .. . ",
"1 11111111 11111 11 1 ",
"5 55555555 55555` 55 5 ",
"7 77777777 777777 77 7 ",
"9 99999999 999999 99 9 ",
": c:::::::: ::::::b :: a: ",
"I fIIIIIIII IIIIIIe II I ",
"= ========= ======= == == ",
"? ????????? ??????? ?? ?? ",
"C CCCCCCCCC CCCCCCC CC CC ",
"J JJJJJJJJ JJJJJJ JJ J ",
"M MMMMMMMM MMMMMM MM M ",
"N NNNNNNNNN NNNNNNN NN N ",
"P PPPPPPPPP PPPPPPP PP P ",
" +*)(' ",
"R RRRRRRRRR RRRRRRR RR aR ",
"U UUUUUUUUU UUUUUUU UU U ",
"Z ZZZZZZZZZ ZZZZZZZ ZZ ZZ ",
"c ccccccccc ccccccc cc cc ",
" j ",
"L fLLLLLLLL LLLLLLe LL L ",
"6 66666666 66666 66 6 ",
" k ",
" l ",
" XXXXX ",
" 1 0 /.-,+*)(' & %$m # \"!",
"_ f________ ______e __ _ ",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 0 /.-,+*)(' %$ # \"!",
" 1 0 /.-,+*)(' & %$ # \"!",
" 1 . +*)(' # \" ",
" 1 . +*)(' # \" ",
"> >>>>>>>>> >>>>>>> >> >> ",
" 1 . +*)(' # \" ",
" 1 . +*)(' # \" ",
"Q QQQQQQQQQ QQQQQQQ QQ aQ ",
"V VVVVVVVVV VVVVVVV VV aV ",
"T TTTTTTTTT TTTTTTT TT T ",
"@ @@@@@@@@@ @@@@@@@ @@ @@ ",
" \x87 ",
"[ [[[[[[[[[ [[[[[[[ [[ [[ ",
"D DDDDDDDDD DDDDDDD DD DD ",
" HH ",
" \x88 ",
" F\x89 ",
"# T# ## # ",
"% V %% U %% % ",
"' 'ZY'' 'XW '' ' ",
"( (ZY(( (XW (( ( ",
"+ +++++ +++\\[ ++ + ",
"* ***** ***\\[ ** * ",
"- ----- ---\\[ -- - ",
", ,,,,, ,,,\\[ ,, , ",
"0 00000_^] 00000 00 0 ",
"/ /////_^] ///// // / ",
"2 22222222 22222 22 2 ",
"3 33333333 33333 33 3 ",
"4 44444444 44444 44 4 ",
"8 88888888 888888 88 8 ",
" ^ ",
" \x8a ",
"; f;;;;;;;; ;;;;;;e ;; ; ",
"< f<<<<<<<< <<<<<<e << < ",
"O OOOOOOOOO OOOOOOO OO O ",
"` ````````` ``````` `` ` ",
"S SSSSSSSSS SSSSSSS SS S ",
"W WWWWWWWWW WWWWWWW WW W ",
"\\ \\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\ \\\\ \\\\ ",
"E EEEEEEEEE EEEEEEE EE EE ",
" 1 0 /.-,+*)(' & %$ # \"!",
"] ]]]]]]]]] ]]]]]]] ]] ]] ",
" G "
];
XPathParser.gotoTable = [
"3456789:;<=>?@ AB CDEFGH IJ ",
" ",
" ",
" ",
"L456789:;<=>?@ AB CDEFGH IJ ",
" M EFGH IJ ",
" N;<=>?@ AB CDEFGH IJ ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" S EFGH IJ ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" e ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" h J ",
" i j ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"o456789:;<=>?@ ABpqCDEFGH IJ ",
" ",
" r6789:;<=>?@ AB CDEFGH IJ ",
" s789:;<=>?@ AB CDEFGH IJ ",
" t89:;<=>?@ AB CDEFGH IJ ",
" u89:;<=>?@ AB CDEFGH IJ ",
" v9:;<=>?@ AB CDEFGH IJ ",
" w9:;<=>?@ AB CDEFGH IJ ",
" x9:;<=>?@ AB CDEFGH IJ ",
" y9:;<=>?@ AB CDEFGH IJ ",
" z:;<=>?@ AB CDEFGH IJ ",
" {:;<=>?@ AB CDEFGH IJ ",
" |;<=>?@ AB CDEFGH IJ ",
" };<=>?@ AB CDEFGH IJ ",
" ~;<=>?@ AB CDEFGH IJ ",
" \x7f=>?@ AB CDEFGH IJ ",
"\x80456789:;<=>?@ AB CDEFGH IJ\x81",
" \x82 EFGH IJ ",
" \x83 EFGH IJ ",
" ",
" \x84 GH IJ ",
" \x85 GH IJ ",
" i \x86 ",
" i \x87 ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
"o456789:;<=>?@ AB\x8cqCDEFGH IJ ",
" ",
" "
];
XPathParser.productions = [
[1, 1, 2],
[2, 1, 3],
[3, 1, 4],
[3, 3, 3, -9, 4],
[4, 1, 5],
[4, 3, 4, -8, 5],
[5, 1, 6],
[5, 3, 5, -22, 6],
[5, 3, 5, -5, 6],
[6, 1, 7],
[6, 3, 6, -23, 7],
[6, 3, 6, -24, 7],
[6, 3, 6, -6, 7],
[6, 3, 6, -7, 7],
[7, 1, 8],
[7, 3, 7, -25, 8],
[7, 3, 7, -26, 8],
[8, 1, 9],
[8, 3, 8, -12, 9],
[8, 3, 8, -11, 9],
[8, 3, 8, -10, 9],
[9, 1, 10],
[9, 2, -26, 9],
[10, 1, 11],
[10, 3, 10, -27, 11],
[11, 1, 12],
[11, 1, 13],
[11, 3, 13, -28, 14],
[11, 3, 13, -4, 14],
[13, 1, 15],
[13, 2, 13, 16],
[15, 1, 17],
[15, 3, -29, 2, -30],
[15, 1, -15],
[15, 1, -16],
[15, 1, 18],
[18, 3, -13, -29, -30],
[18, 4, -13, -29, 19, -30],
[19, 1, 20],
[19, 3, 20, -31, 19],
[20, 1, 2],
[12, 1, 14],
[12, 1, 21],
[21, 1, -28],
[21, 2, -28, 14],
[21, 1, 22],
[14, 1, 23],
[14, 3, 14, -28, 23],
[14, 1, 24],
[23, 2, 25, 26],
[23, 1, 26],
[23, 3, 25, 26, 27],
[23, 2, 26, 27],
[23, 1, 28],
[27, 1, 16],
[27, 2, 16, 27],
[25, 2, -14, -3],
[25, 1, -32],
[26, 1, 29],
[26, 3, -20, -29, -30],
[26, 4, -21, -29, -15, -30],
[16, 3, -33, 30, -34],
[30, 1, 2],
[22, 2, -4, 14],
[24, 3, 14, -4, 23],
[28, 1, -35],
[28, 1, -2],
[17, 2, -36, -18],
[29, 1, -17],
[29, 1, -19],
[29, 1, -18]
];
XPathParser.DOUBLEDOT = 2;
XPathParser.DOUBLECOLON = 3;
XPathParser.DOUBLESLASH = 4;
XPathParser.NOTEQUAL = 5;
XPathParser.LESSTHANOREQUAL = 6;
XPathParser.GREATERTHANOREQUAL = 7;
XPathParser.AND = 8;
XPathParser.OR = 9;
XPathParser.MOD = 10;
XPathParser.DIV = 11;
XPathParser.MULTIPLYOPERATOR = 12;
XPathParser.FUNCTIONNAME = 13;
XPathParser.AXISNAME = 14;
XPathParser.LITERAL = 15;
XPathParser.NUMBER = 16;
XPathParser.ASTERISKNAMETEST = 17;
XPathParser.QNAME = 18;
XPathParser.NCNAMECOLONASTERISK = 19;
XPathParser.NODETYPE = 20;
XPathParser.PROCESSINGINSTRUCTIONWITHLITERAL = 21;
XPathParser.EQUALS = 22;
XPathParser.LESSTHAN = 23;
XPathParser.GREATERTHAN = 24;
XPathParser.PLUS = 25;
XPathParser.MINUS = 26;
XPathParser.BAR = 27;
XPathParser.SLASH = 28;
XPathParser.LEFTPARENTHESIS = 29;
XPathParser.RIGHTPARENTHESIS = 30;
XPathParser.COMMA = 31;
XPathParser.AT = 32;
XPathParser.LEFTBRACKET = 33;
XPathParser.RIGHTBRACKET = 34;
XPathParser.DOT = 35;
XPathParser.DOLLAR = 36;
XPathParser.prototype.tokenize = function(s1) {
var types = [];
var values = [];
var s = s1 + '\0';
var pos = 0;
var c = s.charAt(pos++);
while (1) {
while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
c = s.charAt(pos++);
}
if (c == '\0' || pos >= s.length) {
break;
}
if (c == '(') {
types.push(XPathParser.LEFTPARENTHESIS);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == ')') {
types.push(XPathParser.RIGHTPARENTHESIS);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == '[') {
types.push(XPathParser.LEFTBRACKET);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == ']') {
types.push(XPathParser.RIGHTBRACKET);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == '@') {
types.push(XPathParser.AT);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == ',') {
types.push(XPathParser.COMMA);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == '|') {
types.push(XPathParser.BAR);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == '+') {
types.push(XPathParser.PLUS);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == '-') {
types.push(XPathParser.MINUS);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == '=') {
types.push(XPathParser.EQUALS);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == '$') {
types.push(XPathParser.DOLLAR);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == '.') {
c = s.charAt(pos++);
if (c == '.') {
types.push(XPathParser.DOUBLEDOT);
values.push("..");
c = s.charAt(pos++);
continue;
}
if (c >= '0' && c <= '9') {
var number = "." + c;
c = s.charAt(pos++);
while (c >= '0' && c <= '9') {
number += c;
c = s.charAt(pos++);
}
types.push(XPathParser.NUMBER);
values.push(number);
continue;
}
types.push(XPathParser.DOT);
values.push('.');
continue;
}
if (c == '\'' || c == '"') {
var delimiter = c;
var literal = "";
while ((c = s.charAt(pos++)) != delimiter) {
literal += c;
}
types.push(XPathParser.LITERAL);
values.push(literal);
c = s.charAt(pos++);
continue;
}
if (c >= '0' && c <= '9') {
var number = c;
c = s.charAt(pos++);
while (c >= '0' && c <= '9') {
number += c;
c = s.charAt(pos++);
}
if (c == '.') {
if (s.charAt(pos) >= '0' && s.charAt(pos) <= '9') {
number += c;
number += s.charAt(pos++);
c = s.charAt(pos++);
while (c >= '0' && c <= '9') {
number += c;
c = s.charAt(pos++);
}
}
}
types.push(XPathParser.NUMBER);
values.push(number);
continue;
}
if (c == '*') {
if (types.length > 0) {
var last = types[types.length - 1];
if (last != XPathParser.AT
&& last != XPathParser.DOUBLECOLON
&& last != XPathParser.LEFTPARENTHESIS
&& last != XPathParser.LEFTBRACKET
&& last != XPathParser.AND
&& last != XPathParser.OR
&& last != XPathParser.MOD
&& last != XPathParser.DIV
&& last != XPathParser.MULTIPLYOPERATOR
&& last != XPathParser.SLASH
&& last != XPathParser.DOUBLESLASH
&& last != XPathParser.BAR
&& last != XPathParser.PLUS
&& last != XPathParser.MINUS
&& last != XPathParser.EQUALS
&& last != XPathParser.NOTEQUAL
&& last != XPathParser.LESSTHAN
&& last != XPathParser.LESSTHANOREQUAL
&& last != XPathParser.GREATERTHAN
&& last != XPathParser.GREATERTHANOREQUAL) {
types.push(XPathParser.MULTIPLYOPERATOR);
values.push(c);
c = s.charAt(pos++);
continue;
}
}
types.push(XPathParser.ASTERISKNAMETEST);
values.push(c);
c = s.charAt(pos++);
continue;
}
if (c == ':') {
if (s.charAt(pos) == ':') {
types.push(XPathParser.DOUBLECOLON);
values.push("::");
pos++;
c = s.charAt(pos++);
continue;
}
}
if (c == '/') {
c = s.charAt(pos++);
if (c == '/') {
types.push(XPathParser.DOUBLESLASH);
values.push("//");
c = s.charAt(pos++);
continue;
}
types.push(XPathParser.SLASH);
values.push('/');
continue;
}
if (c == '!') {
if (s.charAt(pos) == '=') {
types.push(XPathParser.NOTEQUAL);
values.push("!=");
pos++;
c = s.charAt(pos++);
continue;
}
}
if (c == '<') {
if (s.charAt(pos) == '=') {
types.push(XPathParser.LESSTHANOREQUAL);
values.push("<=");
pos++;
c = s.charAt(pos++);
continue;
}
types.push(XPathParser.LESSTHAN);
values.push('<');
c = s.charAt(pos++);
continue;
}
if (c == '>') {
if (s.charAt(pos) == '=') {
types.push(XPathParser.GREATERTHANOREQUAL);
values.push(">=");
pos++;
c = s.charAt(pos++);
continue;
}
types.push(XPathParser.GREATERTHAN);
values.push('>');
c = s.charAt(pos++);
continue;
}
if (c == '_' || Utilities.isLetter(c.charCodeAt(0))) {
var name = c;
c = s.charAt(pos++);
while (Utilities.isNCNameChar(c.charCodeAt(0))) {
name += c;
c = s.charAt(pos++);
}
if (types.length > 0) {
var last = types[types.length - 1];
if (last != XPathParser.AT
&& last != XPathParser.DOUBLECOLON
&& last != XPathParser.LEFTPARENTHESIS
&& last != XPathParser.LEFTBRACKET
&& last != XPathParser.AND
&& last != XPathParser.OR
&& last != XPathParser.MOD
&& last != XPathParser.DIV
&& last != XPathParser.MULTIPLYOPERATOR
&& last != XPathParser.SLASH
&& last != XPathParser.DOUBLESLASH
&& last != XPathParser.BAR
&& last != XPathParser.PLUS
&& last != XPathParser.MINUS
&& last != XPathParser.EQUALS
&& last != XPathParser.NOTEQUAL
&& last != XPathParser.LESSTHAN
&& last != XPathParser.LESSTHANOREQUAL
&& last != XPathParser.GREATERTHAN
&& last != XPathParser.GREATERTHANOREQUAL) {
if (name == "and") {
types.push(XPathParser.AND);
values.push(name);
continue;
}
if (name == "or") {
types.push(XPathParser.OR);
values.push(name);
continue;
}
if (name == "mod") {
types.push(XPathParser.MOD);
values.push(name);
continue;
}
if (name == "div") {
types.push(XPathParser.DIV);
values.push(name);
continue;
}
}
}
if (c == ':') {
if (s.charAt(pos) == '*') {
types.push(XPathParser.NCNAMECOLONASTERISK);
values.push(name + ":*");
pos++;
c = s.charAt(pos++);
continue;
}
if (s.charAt(pos) == '_' || Utilities.isLetter(s.charCodeAt(pos))) {
name += ':';
c = s.charAt(pos++);
while (Utilities.isNCNameChar(c.charCodeAt(0))) {
name += c;
c = s.charAt(pos++);
}
if (c == '(') {
types.push(XPathParser.FUNCTIONNAME);
values.push(name);
continue;
}
types.push(XPathParser.QNAME);
values.push(name);
continue;
}
if (s.charAt(pos) == ':') {
types.push(XPathParser.AXISNAME);
values.push(name);
continue;
}
}
if (c == '(') {
if (name == "comment" || name == "text" || name == "node") {
types.push(XPathParser.NODETYPE);
values.push(name);
continue;
}
if (name == "processing-instruction") {
if (s.charAt(pos) == ')') {
types.push(XPathParser.NODETYPE);
} else {
types.push(XPathParser.PROCESSINGINSTRUCTIONWITHLITERAL);
}
values.push(name);
continue;
}
types.push(XPathParser.FUNCTIONNAME);
values.push(name);
continue;
}
types.push(XPathParser.QNAME);
values.push(name);
continue;
}
throw new Error("Unexpected character " + c);
}
types.push(1);
values.push("[EOF]");
return [types, values];
};
XPathParser.SHIFT = 's';
XPathParser.REDUCE = 'r';
XPathParser.ACCEPT = 'a';
XPathParser.prototype.parse = function(s) {
var types;
var values;
var res = this.tokenize(s);
if (res == undefined) {
return undefined;
}
types = res[0];
values = res[1];
var tokenPos = 0;
var state = [];
var tokenType = [];
var tokenValue = [];
var s;
var a;
var t;
state.push(0);
tokenType.push(1);
tokenValue.push("_S");
a = types[tokenPos];
t = values[tokenPos++];
while (1) {
s = state[state.length - 1];
switch (XPathParser.actionTable[s].charAt(a - 1)) {
case XPathParser.SHIFT:
tokenType.push(-a);
tokenValue.push(t);
state.push(XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32);
a = types[tokenPos];
t = values[tokenPos++];
break;
case XPathParser.REDUCE:
var num = XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][1];
var rhs = [];
for (var i = 0; i < num; i++) {
tokenType.pop();
rhs.unshift(tokenValue.pop());
state.pop();
}
var s_ = state[state.length - 1];
tokenType.push(XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][0]);
if (this.reduceActions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32] == undefined) {
tokenValue.push(rhs[0]);
} else {
tokenValue.push(this.reduceActions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32](rhs));
}
state.push(XPathParser.gotoTable[s_].charCodeAt(XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][0] - 2) - 33);
break;
case XPathParser.ACCEPT:
return new XPath(tokenValue.pop());
default:
throw new Error("XPath parse error");
}
}
};
// XPath /////////////////////////////////////////////////////////////////////
XPath.prototype = new Object();
XPath.prototype.constructor = XPath;
XPath.superclass = Object.prototype;
function XPath(e) {
this.expression = e;
}
XPath.prototype.toString = function() {
return this.expression.toString();
};
XPath.prototype.evaluate = function(c) {
c.contextNode = c.expressionContextNode;
c.contextSize = 1;
c.contextPosition = 1;
c.caseInsensitive = false;
if (c.contextNode != null) {
var doc = c.contextNode;
if (doc.nodeType != 9 /*Node.DOCUMENT_NODE*/) {
doc = doc.ownerDocument;
}
try {
c.caseInsensitive = doc.implementation.hasFeature("HTML", "2.0");
} catch (e) {
c.caseInsensitive = true;
}
}
return this.expression.evaluate(c);
};
XPath.XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace";
XPath.XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
// Expression ////////////////////////////////////////////////////////////////
Expression.prototype = new Object();
Expression.prototype.constructor = Expression;
Expression.superclass = Object.prototype;
function Expression() {
}
Expression.prototype.init = function() {
};
Expression.prototype.toString = function() {
return "<Expression>";
};
Expression.prototype.evaluate = function(c) {
throw new Error("Could not evaluate expression.");
};
// UnaryOperation ////////////////////////////////////////////////////////////
UnaryOperation.prototype = new Expression();
UnaryOperation.prototype.constructor = UnaryOperation;
UnaryOperation.superclass = Expression.prototype;
function UnaryOperation(rhs) {
if (arguments.length > 0) {
this.init(rhs);
}
}
UnaryOperation.prototype.init = function(rhs) {
this.rhs = rhs;
};
// UnaryMinusOperation ///////////////////////////////////////////////////////
UnaryMinusOperation.prototype = new UnaryOperation();
UnaryMinusOperation.prototype.constructor = UnaryMinusOperation;
UnaryMinusOperation.superclass = UnaryOperation.prototype;
function UnaryMinusOperation(rhs) {
if (arguments.length > 0) {
this.init(rhs);
}
}
UnaryMinusOperation.prototype.init = function(rhs) {
UnaryMinusOperation.superclass.init.call(this, rhs);
};
UnaryMinusOperation.prototype.evaluate = function(c) {
return this.rhs.evaluate(c).number().negate();
};
UnaryMinusOperation.prototype.toString = function() {
return "-" + this.rhs.toString();
};
// BinaryOperation ///////////////////////////////////////////////////////////
BinaryOperation.prototype = new Expression();
BinaryOperation.prototype.constructor = BinaryOperation;
BinaryOperation.superclass = Expression.prototype;
function BinaryOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
BinaryOperation.prototype.init = function(lhs, rhs) {
this.lhs = lhs;
this.rhs = rhs;
};
// OrOperation ///////////////////////////////////////////////////////////////
OrOperation.prototype = new BinaryOperation();
OrOperation.prototype.constructor = OrOperation;
OrOperation.superclass = BinaryOperation.prototype;
function OrOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
OrOperation.prototype.init = function(lhs, rhs) {
OrOperation.superclass.init.call(this, lhs, rhs);
};
OrOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " or " + this.rhs.toString() + ")";
};
OrOperation.prototype.evaluate = function(c) {
var b = this.lhs.evaluate(c).bool();
if (b.booleanValue()) {
return b;
}
return this.rhs.evaluate(c).bool();
};
// AndOperation //////////////////////////////////////////////////////////////
AndOperation.prototype = new BinaryOperation();
AndOperation.prototype.constructor = AndOperation;
AndOperation.superclass = BinaryOperation.prototype;
function AndOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
AndOperation.prototype.init = function(lhs, rhs) {
AndOperation.superclass.init.call(this, lhs, rhs);
};
AndOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " and " + this.rhs.toString() + ")";
};
AndOperation.prototype.evaluate = function(c) {
var b = this.lhs.evaluate(c).bool();
if (!b.booleanValue()) {
return b;
}
return this.rhs.evaluate(c).bool();
};
// EqualsOperation ///////////////////////////////////////////////////////////
EqualsOperation.prototype = new BinaryOperation();
EqualsOperation.prototype.constructor = EqualsOperation;
EqualsOperation.superclass = BinaryOperation.prototype;
function EqualsOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
EqualsOperation.prototype.init = function(lhs, rhs) {
EqualsOperation.superclass.init.call(this, lhs, rhs);
};
EqualsOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " = " + this.rhs.toString() + ")";
};
EqualsOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).equals(this.rhs.evaluate(c));
};
// NotEqualOperation /////////////////////////////////////////////////////////
NotEqualOperation.prototype = new BinaryOperation();
NotEqualOperation.prototype.constructor = NotEqualOperation;
NotEqualOperation.superclass = BinaryOperation.prototype;
function NotEqualOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
NotEqualOperation.prototype.init = function(lhs, rhs) {
NotEqualOperation.superclass.init.call(this, lhs, rhs);
};
NotEqualOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " != " + this.rhs.toString() + ")";
};
NotEqualOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).notequal(this.rhs.evaluate(c));
};
// LessThanOperation /////////////////////////////////////////////////////////
LessThanOperation.prototype = new BinaryOperation();
LessThanOperation.prototype.constructor = LessThanOperation;
LessThanOperation.superclass = BinaryOperation.prototype;
function LessThanOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
LessThanOperation.prototype.init = function(lhs, rhs) {
LessThanOperation.superclass.init.call(this, lhs, rhs);
};
LessThanOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).lessthan(this.rhs.evaluate(c));
};
LessThanOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " < " + this.rhs.toString() + ")";
};
// GreaterThanOperation //////////////////////////////////////////////////////
GreaterThanOperation.prototype = new BinaryOperation();
GreaterThanOperation.prototype.constructor = GreaterThanOperation;
GreaterThanOperation.superclass = BinaryOperation.prototype;
function GreaterThanOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
GreaterThanOperation.prototype.init = function(lhs, rhs) {
GreaterThanOperation.superclass.init.call(this, lhs, rhs);
};
GreaterThanOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).greaterthan(this.rhs.evaluate(c));
};
GreaterThanOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " > " + this.rhs.toString() + ")";
};
// LessThanOrEqualOperation //////////////////////////////////////////////////
LessThanOrEqualOperation.prototype = new BinaryOperation();
LessThanOrEqualOperation.prototype.constructor = LessThanOrEqualOperation;
LessThanOrEqualOperation.superclass = BinaryOperation.prototype;
function LessThanOrEqualOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
LessThanOrEqualOperation.prototype.init = function(lhs, rhs) {
LessThanOrEqualOperation.superclass.init.call(this, lhs, rhs);
};
LessThanOrEqualOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).lessthanorequal(this.rhs.evaluate(c));
};
LessThanOrEqualOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " <= " + this.rhs.toString() + ")";
};
// GreaterThanOrEqualOperation ///////////////////////////////////////////////
GreaterThanOrEqualOperation.prototype = new BinaryOperation();
GreaterThanOrEqualOperation.prototype.constructor = GreaterThanOrEqualOperation;
GreaterThanOrEqualOperation.superclass = BinaryOperation.prototype;
function GreaterThanOrEqualOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
GreaterThanOrEqualOperation.prototype.init = function(lhs, rhs) {
GreaterThanOrEqualOperation.superclass.init.call(this, lhs, rhs);
};
GreaterThanOrEqualOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).greaterthanorequal(this.rhs.evaluate(c));
};
GreaterThanOrEqualOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " >= " + this.rhs.toString() + ")";
};
// PlusOperation /////////////////////////////////////////////////////////////
PlusOperation.prototype = new BinaryOperation();
PlusOperation.prototype.constructor = PlusOperation;
PlusOperation.superclass = BinaryOperation.prototype;
function PlusOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
PlusOperation.prototype.init = function(lhs, rhs) {
PlusOperation.superclass.init.call(this, lhs, rhs);
};
PlusOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).number().plus(this.rhs.evaluate(c).number());
};
PlusOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " + " + this.rhs.toString() + ")";
};
// MinusOperation ////////////////////////////////////////////////////////////
MinusOperation.prototype = new BinaryOperation();
MinusOperation.prototype.constructor = MinusOperation;
MinusOperation.superclass = BinaryOperation.prototype;
function MinusOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
MinusOperation.prototype.init = function(lhs, rhs) {
MinusOperation.superclass.init.call(this, lhs, rhs);
};
MinusOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).number().minus(this.rhs.evaluate(c).number());
};
MinusOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " - " + this.rhs.toString() + ")";
};
// MultiplyOperation /////////////////////////////////////////////////////////
MultiplyOperation.prototype = new BinaryOperation();
MultiplyOperation.prototype.constructor = MultiplyOperation;
MultiplyOperation.superclass = BinaryOperation.prototype;
function MultiplyOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
MultiplyOperation.prototype.init = function(lhs, rhs) {
MultiplyOperation.superclass.init.call(this, lhs, rhs);
};
MultiplyOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).number().multiply(this.rhs.evaluate(c).number());
};
MultiplyOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " * " + this.rhs.toString() + ")";
};
// DivOperation //////////////////////////////////////////////////////////////
DivOperation.prototype = new BinaryOperation();
DivOperation.prototype.constructor = DivOperation;
DivOperation.superclass = BinaryOperation.prototype;
function DivOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
DivOperation.prototype.init = function(lhs, rhs) {
DivOperation.superclass.init.call(this, lhs, rhs);
};
DivOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).number().div(this.rhs.evaluate(c).number());
};
DivOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " div " + this.rhs.toString() + ")";
};
// ModOperation //////////////////////////////////////////////////////////////
ModOperation.prototype = new BinaryOperation();
ModOperation.prototype.constructor = ModOperation;
ModOperation.superclass = BinaryOperation.prototype;
function ModOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
ModOperation.prototype.init = function(lhs, rhs) {
ModOperation.superclass.init.call(this, lhs, rhs);
};
ModOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).number().mod(this.rhs.evaluate(c).number());
};
ModOperation.prototype.toString = function() {
return "(" + this.lhs.toString() + " mod " + this.rhs.toString() + ")";
};
// BarOperation //////////////////////////////////////////////////////////////
BarOperation.prototype = new BinaryOperation();
BarOperation.prototype.constructor = BarOperation;
BarOperation.superclass = BinaryOperation.prototype;
function BarOperation(lhs, rhs) {
if (arguments.length > 0) {
this.init(lhs, rhs);
}
}
BarOperation.prototype.init = function(lhs, rhs) {
BarOperation.superclass.init.call(this, lhs, rhs);
};
BarOperation.prototype.evaluate = function(c) {
return this.lhs.evaluate(c).nodeset().union(this.rhs.evaluate(c).nodeset());
};
BarOperation.prototype.toString = function() {
return this.lhs.toString() + " | " + this.rhs.toString();
};
// PathExpr //////////////////////////////////////////////////////////////////
PathExpr.prototype = new Expression();
PathExpr.prototype.constructor = PathExpr;
PathExpr.superclass = Expression.prototype;
function PathExpr(filter, filterPreds, locpath) {
if (arguments.length > 0) {
this.init(filter, filterPreds, locpath);
}
}
PathExpr.prototype.init = function(filter, filterPreds, locpath) {
PathExpr.superclass.init.call(this);
this.filter = filter;
this.filterPredicates = filterPreds;
this.locationPath = locpath;