PageRenderTime 57ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/files/jquery.xpath/0.2.5/jquery.xpath.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1652 lines | 1415 code | 225 blank | 12 comment | 358 complexity | 94e6961389b7d1e2eacec6e5ac079258 MD5 | raw file
  1. /*
  2. * jQuery XPath plugin v0.2.5
  3. * https://github.com/ilinsky/jquery-xpath
  4. * Copyright 2013, Sergey Ilinsky
  5. * Dual licensed under the MIT and GPL licenses.
  6. *
  7. * Includes xpath.js - XPath 2.0 implementation in JavaScript
  8. * https://github.com/ilinsky/xpath.js
  9. * Copyright 2013, Sergey Ilinsky
  10. * Dual licensed under the MIT and GPL licenses.
  11. *
  12. */
  13. (function () {
  14. var cString = window.String,
  15. cBoolean = window.Boolean,
  16. cNumber = window.Number,
  17. cObject = window.Object,
  18. cArray = window.Array,
  19. cRegExp = window.RegExp,
  20. cDate = window.Date,
  21. cFunction = window.Function,
  22. cMath = window.Math,
  23. cError = window.Error,
  24. cSyntaxError= window.SyntaxError,
  25. cTypeError = window.TypeError,
  26. fIsNaN = window.isNaN,
  27. fIsFinite = window.isFinite,
  28. nNaN = window.NaN,
  29. nInfinity = window.Infinity,
  30. fString_trim =(function() {
  31. return cString.prototype.trim ? function(sValue) {return cString(sValue).trim();} : function(sValue) {
  32. return cString(sValue).replace(/^\s+|\s+$/g, '');
  33. };
  34. })(),
  35. fArray_indexOf =(function() {
  36. return cArray.prototype.indexOf ? function(aValue, vItem) {return aValue.indexOf(vItem);} : function(aValue, vItem) {
  37. for (var nIndex = 0, nLength = aValue.length; nIndex < nLength; nIndex++)
  38. if (aValue[nIndex] === vItem)
  39. return nIndex;
  40. return -1;
  41. };
  42. })();
  43. var sNS_XSD = "http://www.w3.org/2001/XMLSchema",
  44. sNS_XPF = "http://www.w3.org/2005/xpath-functions",
  45. sNS_XNS = "http://www.w3.org/2000/xmlns/",
  46. sNS_XML = "http://www.w3.org/XML/1998/namespace";
  47. function cException(sCode
  48. , sMessage
  49. ) {
  50. this.code = sCode;
  51. this.message =
  52. sMessage ||
  53. oException_messages[sCode];
  54. };
  55. cException.prototype = new cError;
  56. var oException_messages = {};
  57. oException_messages["XPDY0002"] = "Evaluation of an expression relies on some part of the dynamic context that has not been assigned a value.";
  58. oException_messages["XPST0003"] = "Expression is not a valid instance of the grammar";
  59. oException_messages["XPTY0004"] = "Type is not appropriate for the context in which the expression occurs";
  60. oException_messages["XPST0008"] = "Expression refers to an element name, attribute name, schema type name, namespace prefix, or variable name that is not defined in the static context";
  61. oException_messages["XPST0010"] = "Axis not supported";
  62. oException_messages["XPST0017"] = "Expanded QName and number of arguments in a function call do not match the name and arity of a function signature";
  63. oException_messages["XPTY0018"] = "The result of the last step in a path expression contains both nodes and atomic values";
  64. oException_messages["XPTY0019"] = "The result of a step (other than the last step) in a path expression contains an atomic value.";
  65. oException_messages["XPTY0020"] = "In an axis step, the context item is not a node.";
  66. oException_messages["XPST0051"] = "It is a static error if a QName that is used as an AtomicType in a SequenceType is not defined in the in-scope schema types as an atomic type.";
  67. oException_messages["XPST0081"] = "A QName used in an expression contains a namespace prefix that cannot be expanded into a namespace URI by using the statically known namespaces.";
  68. oException_messages["FORG0001"] = "Invalid value for cast/constructor.";
  69. oException_messages["FORG0003"] = "fn:zero-or-one called with a sequence containing more than one item.";
  70. oException_messages["FORG0004"] = "fn:one-or-more called with a sequence containing no items.";
  71. oException_messages["FORG0005"] = "fn:exactly-one called with a sequence containing zero or more than one item.";
  72. oException_messages["FORG0006"] = "Invalid argument type.";
  73. oException_messages["FODC0001"] = "No context document.";
  74. oException_messages["FORX0001"] = "Invalid regular expression flags.";
  75. oException_messages["FOCA0002"] = "Invalid lexical value.";
  76. oException_messages["FOCH0002"] = "Unsupported collation.";
  77. oException_messages["FONS0004"] = "No namespace found for prefix.";
  78. function cLexer(sValue) {
  79. var aMatch = sValue.match(/\$?(?:(?![0-9-])(?:[\w-]+|\*):)?(?![0-9-])(?:[\w-]+|\*)|\(:|:\)|\/\/|\.\.|::|\d+(?:\.\d*)?(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?|"[^"]*(?:""[^"]*)*"|'[^']*(?:''[^']*)*'|<<|>>|[!<>]=|(?![0-9-])[\w-]+:\*|\s+|./g);
  80. if (aMatch) {
  81. var nStack = 0;
  82. for (var nIndex = 0, nLength = aMatch.length; nIndex < nLength; nIndex++)
  83. if (aMatch[nIndex] == '(:')
  84. nStack++;
  85. else
  86. if (aMatch[nIndex] == ':)' && nStack)
  87. nStack--;
  88. else
  89. if (!nStack && !/^\s/.test(aMatch[nIndex]))
  90. this[this.length++] = aMatch[nIndex];
  91. if (nStack)
  92. throw new cException("XPST0003"
  93. , "Unclosed comment"
  94. );
  95. }
  96. };
  97. cLexer.prototype.index = 0;
  98. cLexer.prototype.length = 0;
  99. cLexer.prototype.reset = function() {
  100. this.index = 0;
  101. };
  102. cLexer.prototype.peek = function(nOffset) {
  103. return this[this.index +(nOffset || 0)] || '';
  104. };
  105. cLexer.prototype.next = function(nOffset) {
  106. return(this.index+= nOffset || 1) < this.length;
  107. };
  108. cLexer.prototype.back = function(nOffset) {
  109. return(this.index-= nOffset || 1) > 0;
  110. };
  111. cLexer.prototype.eof = function() {
  112. return this.index >= this.length;
  113. };
  114. function cDOMAdapter() {
  115. };
  116. cDOMAdapter.prototype.isNode = function(oNode) {
  117. return oNode &&!!oNode.nodeType;
  118. };
  119. cDOMAdapter.prototype.getProperty = function(oNode, sName) {
  120. return oNode[sName];
  121. };
  122. cDOMAdapter.prototype.isSameNode = function(oNode, oNode2) {
  123. return oNode == oNode2;
  124. };
  125. cDOMAdapter.prototype.compareDocumentPosition = function(oNode, oNode2) {
  126. return oNode.compareDocumentPosition(oNode2);
  127. };
  128. cDOMAdapter.prototype.lookupNamespaceURI = function(oNode, sPrefix) {
  129. return oNode.lookupNamespaceURI(sPrefix);
  130. };
  131. cDOMAdapter.prototype.getElementById = function(oNode, sId) {
  132. return oNode.getElementById(sId);
  133. };
  134. cDOMAdapter.prototype.getElementsByTagNameNS = function(oNode, sNameSpaceURI, sLocalName) {
  135. return oNode.getElementsByTagNameNS(sNameSpaceURI, sLocalName);
  136. };
  137. function cDynamicContext(oStaticContext, vItem, oScope, oDOMAdapter) {
  138. this.staticContext = oStaticContext;
  139. this.item = vItem;
  140. this.scope = oScope || {};
  141. this.stack = {};
  142. this.DOMAdapter = oDOMAdapter || new cDOMAdapter;
  143. var oDate = new cDate,
  144. nOffset = oDate.getTimezoneOffset();
  145. this.dateTime = new cXSDateTime(oDate.getFullYear(), oDate.getMonth() + 1, oDate.getDate(), oDate.getHours(), oDate.getMinutes(), oDate.getSeconds() + oDate.getMilliseconds() / 1000, -nOffset);
  146. this.timezone = new cXSDayTimeDuration(0, cMath.abs(~~(nOffset / 60)), cMath.abs(nOffset % 60), 0, nOffset > 0);
  147. };
  148. cDynamicContext.prototype.item = null;
  149. cDynamicContext.prototype.position = 0;
  150. cDynamicContext.prototype.size = 0;
  151. cDynamicContext.prototype.scope = null;
  152. cDynamicContext.prototype.stack = null; cDynamicContext.prototype.dateTime = null;
  153. cDynamicContext.prototype.timezone = null;
  154. cDynamicContext.prototype.staticContext = null;
  155. cDynamicContext.prototype.pushVariable = function(sName, vValue) {
  156. if (!this.stack.hasOwnProperty(sName))
  157. this.stack[sName] = [];
  158. this.stack[sName].push(this.scope[sName]);
  159. this.scope[sName] = vValue;
  160. };
  161. cDynamicContext.prototype.popVariable = function(sName) {
  162. if (this.stack.hasOwnProperty(sName)) {
  163. this.scope[sName] = this.stack[sName].pop();
  164. if (!this.stack[sName].length) {
  165. delete this.stack[sName];
  166. if (typeof this.scope[sName] == "undefined")
  167. delete this.scope[sName];
  168. }
  169. }
  170. };
  171. function cStaticContext() {
  172. this.dataTypes = {};
  173. this.documents = {};
  174. this.functions = {};
  175. this.collations = {};
  176. this.collections= {};
  177. };
  178. cStaticContext.prototype.baseURI = null;
  179. cStaticContext.prototype.dataTypes = null;
  180. cStaticContext.prototype.documents = null;
  181. cStaticContext.prototype.functions = null;
  182. cStaticContext.prototype.defaultFunctionNamespace = null;
  183. cStaticContext.prototype.collations = null;
  184. cStaticContext.prototype.defaultCollationName = sNS_XPF + "/collation/codepoint";
  185. cStaticContext.prototype.collections = null;
  186. cStaticContext.prototype.namespaceResolver = null;
  187. cStaticContext.prototype.defaultElementNamespace = null;
  188. var rStaticContext_uri = /^(?:\{([^\}]+)\})?(.+)$/;
  189. cStaticContext.prototype.setDataType = function(sUri, fFunction) {
  190. var aMatch = sUri.match(rStaticContext_uri);
  191. if (aMatch)
  192. if (aMatch[1] != sNS_XSD)
  193. this.dataTypes[sUri] = fFunction;
  194. };
  195. cStaticContext.prototype.getDataType = function(sUri) {
  196. var aMatch = sUri.match(rStaticContext_uri);
  197. if (aMatch)
  198. return aMatch[1] == sNS_XSD ? hStaticContext_dataTypes[cRegExp.$2] : this.dataTypes[sUri];
  199. };
  200. cStaticContext.prototype.setDocument = function(sUri, fFunction) {
  201. this.documents[sUri] = fFunction;
  202. };
  203. cStaticContext.prototype.setFunction = function(sUri, fFunction) {
  204. var aMatch = sUri.match(rStaticContext_uri);
  205. if (aMatch)
  206. if (aMatch[1] != sNS_XPF)
  207. this.functions[sUri] = fFunction;
  208. };
  209. cStaticContext.prototype.getFunction = function(sUri) {
  210. var aMatch = sUri.match(rStaticContext_uri);
  211. if (aMatch)
  212. return aMatch[1] == sNS_XPF ? hStaticContext_functions[cRegExp.$2] : this.functions[sUri];
  213. };
  214. cStaticContext.prototype.setCollation = function(sUri, fFunction) {
  215. this.collations[sUri] = fFunction;
  216. };
  217. cStaticContext.prototype.getCollation = function(sUri) {
  218. return this.collations[sUri];
  219. };
  220. cStaticContext.prototype.setCollection = function(sUri, fFunction) {
  221. this.collections[sUri] = fFunction;
  222. };
  223. cStaticContext.prototype.getURIForPrefix = function(sPrefix) {
  224. var oResolver = this.namespaceResolver,
  225. fResolver = oResolver && oResolver.lookupNamespaceURI ? oResolver.lookupNamespaceURI : oResolver,
  226. sNameSpaceURI;
  227. if (fResolver instanceof cFunction && (sNameSpaceURI = fResolver.call(oResolver, sPrefix)))
  228. return sNameSpaceURI;
  229. if (sPrefix == 'fn')
  230. return sNS_XPF;
  231. if (sPrefix == 'xs')
  232. return sNS_XSD;
  233. if (sPrefix == "xml")
  234. return sNS_XML;
  235. if (sPrefix == "xmlns")
  236. return sNS_XNS;
  237. throw new cException("XPST0081"
  238. , "Prefix '" + sPrefix + "' has not been declared"
  239. );
  240. };
  241. cStaticContext.js2xs = function(vItem) {
  242. if (typeof vItem == "boolean")
  243. vItem = new cXSBoolean(vItem);
  244. else
  245. if (typeof vItem == "number")
  246. vItem =(fIsNaN(vItem) ||!fIsFinite(vItem)) ? new cXSDouble(vItem) : fNumericLiteral_parseValue(cString(vItem));
  247. else
  248. vItem = new cXSString(cString(vItem));
  249. return vItem;
  250. };
  251. cStaticContext.xs2js = function(vItem) {
  252. if (vItem instanceof cXSBoolean)
  253. vItem = vItem.valueOf();
  254. else
  255. if (fXSAnyAtomicType_isNumeric(vItem))
  256. vItem = vItem.valueOf();
  257. else
  258. vItem = vItem.toString();
  259. return vItem;
  260. };
  261. var hStaticContext_functions = {},
  262. hStaticContext_signatures = {},
  263. hStaticContext_dataTypes = {},
  264. hStaticContext_operators = {};
  265. function fStaticContext_defineSystemFunction(sName, aParameters, fFunction) {
  266. hStaticContext_functions[sName] = fFunction;
  267. hStaticContext_signatures[sName] = aParameters;
  268. };
  269. function fStaticContext_defineSystemDataType(sName, fFunction) {
  270. hStaticContext_dataTypes[sName] = fFunction;
  271. };
  272. function cExpression(sExpression, oStaticContext) {
  273. var oLexer = new cLexer(sExpression),
  274. oExpr = fExpr_parse(oLexer, oStaticContext);
  275. if (!oLexer.eof())
  276. throw new cException("XPST0003"
  277. , "Unexpected token beyond end of query"
  278. );
  279. if (!oExpr)
  280. throw new cException("XPST0003"
  281. , "Expected expression"
  282. );
  283. this.internalExpression = oExpr;
  284. };
  285. cExpression.prototype.internalExpression = null;
  286. cExpression.prototype.evaluate = function(oContext) {
  287. return this.internalExpression.evaluate(oContext);
  288. };
  289. function cStringCollator() {
  290. };
  291. cStringCollator.prototype.equals = function(sValue1, sValue2) {
  292. throw "Not implemented";
  293. };
  294. cStringCollator.prototype.compare = function(sValue1, sValue2) {
  295. throw "Not implemented";
  296. };
  297. function cXSConstants(){};
  298. cXSConstants.ANYSIMPLETYPE_DT = 1;
  299. cXSConstants.STRING_DT = 2;
  300. cXSConstants.BOOLEAN_DT = 3;
  301. cXSConstants.DECIMAL_DT = 4;
  302. cXSConstants.FLOAT_DT = 5;
  303. cXSConstants.DOUBLE_DT = 6;
  304. cXSConstants.DURATION_DT = 7;
  305. cXSConstants.DATETIME_DT = 8;
  306. cXSConstants.TIME_DT = 9;
  307. cXSConstants.DATE_DT = 10;
  308. cXSConstants.GYEARMONTH_DT = 11;
  309. cXSConstants.GYEAR_DT = 12;
  310. cXSConstants.GMONTHDAY_DT = 13;
  311. cXSConstants.GDAY_DT = 14;
  312. cXSConstants.GMONTH_DT = 15;
  313. cXSConstants.HEXBINARY_DT = 16;
  314. cXSConstants.BASE64BINARY_DT = 17;
  315. cXSConstants.ANYURI_DT = 18;
  316. cXSConstants.QNAME_DT = 19;
  317. cXSConstants.NOTATION_DT = 20;
  318. cXSConstants.NORMALIZEDSTRING_DT = 21;
  319. cXSConstants.TOKEN_DT = 22;
  320. cXSConstants.LANGUAGE_DT = 23;
  321. cXSConstants.NMTOKEN_DT = 24;
  322. cXSConstants.NAME_DT = 25;
  323. cXSConstants.NCNAME_DT = 26;
  324. cXSConstants.ID_DT = 27;
  325. cXSConstants.IDREF_DT = 28;
  326. cXSConstants.ENTITY_DT = 29;
  327. cXSConstants.INTEGER_DT = 30;
  328. cXSConstants.NONPOSITIVEINTEGER_DT = 31;
  329. cXSConstants.NEGATIVEINTEGER_DT = 32;
  330. cXSConstants.LONG_DT = 33;
  331. cXSConstants.INT_DT = 34;
  332. cXSConstants.SHORT_DT = 35;
  333. cXSConstants.BYTE_DT = 36;
  334. cXSConstants.NONNEGATIVEINTEGER_DT = 37;
  335. cXSConstants.UNSIGNEDLONG_DT = 38;
  336. cXSConstants.UNSIGNEDINT_DT = 39;
  337. cXSConstants.UNSIGNEDSHORT_DT = 40;
  338. cXSConstants.UNSIGNEDBYTE_DT = 41;
  339. cXSConstants.POSITIVEINTEGER_DT = 42;
  340. cXSConstants.LISTOFUNION_DT = 43;
  341. cXSConstants.LIST_DT = 44;
  342. cXSConstants.UNAVAILABLE_DT = 45;
  343. cXSConstants.DATETIMESTAMP_DT = 46;
  344. cXSConstants.DAYMONTHDURATION_DT = 47;
  345. cXSConstants.DAYTIMEDURATION_DT = 48;
  346. cXSConstants.PRECISIONDECIMAL_DT = 49;
  347. cXSConstants.ANYATOMICTYPE_DT = 50;
  348. cXSConstants.ANYTYPE_DT = 51;
  349. cXSConstants.XT_YEARMONTHDURATION_DT=-1;
  350. cXSConstants.XT_UNTYPEDATOMIC_DT =-2;
  351. function cExpr() {
  352. this.items = [];
  353. };
  354. cExpr.prototype.items = null;
  355. function fExpr_parse (oLexer, oStaticContext) {
  356. var oItem;
  357. if (oLexer.eof() ||!(oItem = fExprSingle_parse(oLexer, oStaticContext)))
  358. return;
  359. var oExpr = new cExpr;
  360. oExpr.items.push(oItem);
  361. while (oLexer.peek() == ',') {
  362. oLexer.next();
  363. if (oLexer.eof() ||!(oItem = fExprSingle_parse(oLexer, oStaticContext)))
  364. throw new cException("XPST0003"
  365. , "Expected expression"
  366. );
  367. oExpr.items.push(oItem);
  368. }
  369. return oExpr;
  370. };
  371. cExpr.prototype.evaluate = function(oContext) {
  372. var oSequence = [];
  373. for (var nIndex = 0, nLength = this.items.length; nIndex < nLength; nIndex++)
  374. oSequence = hStaticContext_operators["concatenate"].call(oContext, oSequence, this.items[nIndex].evaluate(oContext));
  375. return oSequence;
  376. };
  377. function cExprSingle() {
  378. };
  379. function fExprSingle_parse (oLexer, oStaticContext) {
  380. if (!oLexer.eof())
  381. return fIfExpr_parse(oLexer, oStaticContext)
  382. || fForExpr_parse(oLexer, oStaticContext)
  383. || fQuantifiedExpr_parse(oLexer, oStaticContext)
  384. || fOrExpr_parse(oLexer, oStaticContext);
  385. };
  386. function cForExpr() {
  387. this.bindings = [];
  388. this.returnExpr = null;
  389. };
  390. cForExpr.prototype.bindings = null;
  391. cForExpr.prototype.returnExpr = null;
  392. function fForExpr_parse (oLexer, oStaticContext) {
  393. if (oLexer.peek() == "for" && oLexer.peek(1).substr(0, 1) == '$') {
  394. oLexer.next();
  395. var oForExpr = new cForExpr,
  396. oExpr;
  397. do {
  398. oForExpr.bindings.push(fSimpleForBinding_parse(oLexer, oStaticContext));
  399. }
  400. while (oLexer.peek() == ',' && oLexer.next());
  401. if (oLexer.peek() != "return")
  402. throw new cException("XPST0003"
  403. , "Expected 'return' token in for expression"
  404. );
  405. oLexer.next();
  406. if (oLexer.eof() ||!(oExpr = fExprSingle_parse(oLexer, oStaticContext)))
  407. throw new cException("XPST0003"
  408. , "Expected return statement operand in for expression"
  409. );
  410. oForExpr.returnExpr = oExpr;
  411. return oForExpr;
  412. }
  413. };
  414. cForExpr.prototype.evaluate = function (oContext) {
  415. var oSequence = [];
  416. (function(oSelf, nBinding) {
  417. var oBinding = oSelf.bindings[nBinding++],
  418. oSequence1 = oBinding.inExpr.evaluate(oContext),
  419. sUri = (oBinding.namespaceURI ? '{' + oBinding.namespaceURI + '}' : '') + oBinding.localName;
  420. for (var nIndex = 0, nLength = oSequence1.length; nIndex < nLength; nIndex++) {
  421. oContext.pushVariable(sUri, oSequence1[nIndex]);
  422. if (nBinding < oSelf.bindings.length)
  423. arguments.callee(oSelf, nBinding);
  424. else
  425. oSequence = oSequence.concat(oSelf.returnExpr.evaluate(oContext));
  426. oContext.popVariable(sUri);
  427. }
  428. })(this, 0);
  429. return oSequence;
  430. };
  431. function cSimpleForBinding(sPrefix, sLocalName, sNameSpaceURI, oInExpr) {
  432. this.prefix = sPrefix;
  433. this.localName = sLocalName;
  434. this.namespaceURI = sNameSpaceURI;
  435. this.inExpr = oInExpr;
  436. };
  437. cSimpleForBinding.prototype.prefix = null;
  438. cSimpleForBinding.prototype.localName = null;
  439. cSimpleForBinding.prototype.namespaceURI = null;
  440. cSimpleForBinding.prototype.inExpr = null;
  441. function fSimpleForBinding_parse (oLexer, oStaticContext) {
  442. var aMatch = oLexer.peek().substr(1).match(rNameTest);
  443. if (!aMatch)
  444. throw new cException("XPST0003"
  445. , "Expected binding in for expression"
  446. );
  447. if (aMatch[1] == '*' || aMatch[2] == '*')
  448. throw new cException("XPST0003"
  449. , "Illegal use of wildcard in for expression binding variable name"
  450. );
  451. oLexer.next();
  452. if (oLexer.peek() != "in")
  453. throw new cException("XPST0003"
  454. , "Expected 'in' token in for expression binding"
  455. );
  456. oLexer.next();
  457. var oExpr;
  458. if (oLexer.eof() ||!(oExpr = fExprSingle_parse(oLexer, oStaticContext)))
  459. throw new cException("XPST0003"
  460. , "Expected in statement operand in for expression binding"
  461. );
  462. return new cSimpleForBinding(aMatch[1] || null, aMatch[2], aMatch[1] ? oStaticContext.getURIForPrefix(aMatch[1]) : null, oExpr);
  463. };
  464. function cIfExpr(oCondExpr, oThenExpr, oElseExpr) {
  465. this.condExpr = oCondExpr;
  466. this.thenExpr = oThenExpr;
  467. this.elseExpr = oElseExpr;
  468. };
  469. cIfExpr.prototype.condExpr = null;
  470. cIfExpr.prototype.thenExpr = null;
  471. cIfExpr.prototype.elseExpr = null;
  472. function fIfExpr_parse (oLexer, oStaticContext) {
  473. var oCondExpr,
  474. oThenExpr,
  475. oElseExpr;
  476. if (oLexer.peek() == "if" && oLexer.peek(1) == '(') {
  477. oLexer.next(2);
  478. if (oLexer.eof() ||!(oCondExpr = fExpr_parse(oLexer, oStaticContext)))
  479. throw new cException("XPST0003"
  480. , "Expected if statement operand in conditional expression"
  481. );
  482. if (oLexer.peek() != ')')
  483. throw new cException("XPST0003"
  484. , "Expected ')' token in for expression"
  485. );
  486. oLexer.next();
  487. if (oLexer.peek() != "then")
  488. throw new cException("XPST0003"
  489. , "Expected 'then' token in conditional if expression"
  490. );
  491. oLexer.next();
  492. if (oLexer.eof() ||!(oThenExpr = fExprSingle_parse(oLexer, oStaticContext)))
  493. throw new cException("XPST0003"
  494. , "Expected then statement operand in condional expression"
  495. );
  496. if (oLexer.peek() != "else")
  497. throw new cException("XPST0003"
  498. , "Expected 'else' token in conditional if expression"
  499. );
  500. oLexer.next();
  501. if (oLexer.eof() ||!(oElseExpr = fExprSingle_parse(oLexer, oStaticContext)))
  502. throw new cException("XPST0003"
  503. , "Expected else statement operand in condional expression"
  504. );
  505. return new cIfExpr(oCondExpr, oThenExpr, oElseExpr);
  506. }
  507. };
  508. cIfExpr.prototype.evaluate = function (oContext) {
  509. return this[fFunction_sequence_toEBV(this.condExpr.evaluate(oContext), oContext) ? "thenExpr" : "elseExpr"].evaluate(oContext);
  510. };
  511. function cQuantifiedExpr(sQuantifier) {
  512. this.quantifier = sQuantifier;
  513. this.bindings = [];
  514. this.satisfiesExpr = null;
  515. };
  516. cQuantifiedExpr.prototype.bindings = null;
  517. cQuantifiedExpr.prototype.quantifier = null;
  518. cQuantifiedExpr.prototype.satisfiesExpr = null;
  519. function fQuantifiedExpr_parse (oLexer, oStaticContext) {
  520. var sQuantifier = oLexer.peek();
  521. if ((sQuantifier == "some" || sQuantifier == "every") && oLexer.peek(1).substr(0, 1) == '$') {
  522. oLexer.next();
  523. var oQuantifiedExpr = new cQuantifiedExpr(sQuantifier),
  524. oExpr;
  525. do {
  526. oQuantifiedExpr.bindings.push(fSimpleQuantifiedBinding_parse(oLexer, oStaticContext));
  527. }
  528. while (oLexer.peek() == ',' && oLexer.next());
  529. if (oLexer.peek() != "satisfies")
  530. throw new cException("XPST0003"
  531. , "Expected 'satisfies' token in quantified expression"
  532. );
  533. oLexer.next();
  534. if (oLexer.eof() ||!(oExpr = fExprSingle_parse(oLexer, oStaticContext)))
  535. throw new cException("XPST0003"
  536. , "Expected satisfies statement operand in quantified expression"
  537. );
  538. oQuantifiedExpr.satisfiesExpr = oExpr;
  539. return oQuantifiedExpr;
  540. }
  541. };
  542. cQuantifiedExpr.prototype.evaluate = function (oContext) {
  543. var bEvery = this.quantifier == "every",
  544. bResult = bEvery ? true : false;
  545. (function(oSelf, nBinding) {
  546. var oBinding = oSelf.bindings[nBinding++],
  547. oSequence1 = oBinding.inExpr.evaluate(oContext),
  548. sUri = (oBinding.namespaceURI ? '{' + oBinding.namespaceURI + '}' : '') + oBinding.localName;
  549. for (var nIndex = 0, nLength = oSequence1.length; (nIndex < nLength) && (bEvery ? bResult :!bResult); nIndex++) {
  550. oContext.pushVariable(sUri, oSequence1[nIndex]);
  551. if (nBinding < oSelf.bindings.length)
  552. arguments.callee(oSelf, nBinding);
  553. else
  554. bResult = fFunction_sequence_toEBV(oSelf.satisfiesExpr.evaluate(oContext), oContext);
  555. oContext.popVariable(sUri);
  556. }
  557. })(this, 0);
  558. return [new cXSBoolean(bResult)];
  559. };
  560. function cSimpleQuantifiedBinding(sPrefix, sLocalName, sNameSpaceURI, oInExpr) {
  561. this.prefix = sPrefix;
  562. this.localName = sLocalName;
  563. this.namespaceURI = sNameSpaceURI;
  564. this.inExpr = oInExpr;
  565. };
  566. cSimpleQuantifiedBinding.prototype.prefix = null;
  567. cSimpleQuantifiedBinding.prototype.localName = null;
  568. cSimpleQuantifiedBinding.prototype.namespaceURI = null;
  569. cSimpleQuantifiedBinding.prototype.inExpr = null;
  570. function fSimpleQuantifiedBinding_parse (oLexer, oStaticContext) {
  571. var aMatch = oLexer.peek().substr(1).match(rNameTest);
  572. if (!aMatch)
  573. throw new cException("XPST0003"
  574. , "Expected binding in quantified expression"
  575. );
  576. if (aMatch[1] == '*' || aMatch[2] == '*')
  577. throw new cException("XPST0003"
  578. , "Illegal use of wildcard in quantified expression binding variable name"
  579. );
  580. oLexer.next();
  581. if (oLexer.peek() != "in")
  582. throw new cException("XPST0003"
  583. , "Expected 'in' token in quantified expression binding"
  584. );
  585. oLexer.next();
  586. var oExpr;
  587. if (oLexer.eof() ||!(oExpr = fExprSingle_parse(oLexer, oStaticContext)))
  588. throw new cException("XPST0003"
  589. , "Expected in statement operand in quantified expression binding"
  590. );
  591. return new cSimpleQuantifiedBinding(aMatch[1] || null, aMatch[2], aMatch[1] ? oStaticContext.getURIForPrefix(aMatch[1]) : null, oExpr);
  592. };
  593. function cComparisonExpr(oLeft, oRight, sOperator) {
  594. this.left = oLeft;
  595. this.right = oRight;
  596. this.operator = sOperator;
  597. };
  598. cComparisonExpr.prototype.left = null;
  599. cComparisonExpr.prototype.right = null;
  600. cComparisonExpr.prototype.operator = null;
  601. function fComparisonExpr_parse (oLexer, oStaticContext) {
  602. var oExpr,
  603. oRight;
  604. if (oLexer.eof() ||!(oExpr = fRangeExpr_parse(oLexer, oStaticContext)))
  605. return;
  606. if (!(oLexer.peek() in hComparisonExpr_operators))
  607. return oExpr;
  608. var sOperator = oLexer.peek();
  609. oLexer.next();
  610. if (oLexer.eof() ||!(oRight = fRangeExpr_parse(oLexer, oStaticContext)))
  611. throw new cException("XPST0003"
  612. , "Expected second operand in comparison expression"
  613. );
  614. return new cComparisonExpr(oExpr, oRight, sOperator);
  615. };
  616. cComparisonExpr.prototype.evaluate = function (oContext) {
  617. var oResult = hComparisonExpr_operators[this.operator](this, oContext);
  618. return oResult == null ? [] : [oResult];
  619. };
  620. function fComparisonExpr_GeneralComp(oExpr, oContext) {
  621. var oLeft = fFunction_sequence_atomize(oExpr.left.evaluate(oContext), oContext);
  622. if (!oLeft.length)
  623. return new cXSBoolean(false);
  624. var oRight = fFunction_sequence_atomize(oExpr.right.evaluate(oContext), oContext);
  625. if (!oRight.length)
  626. return new cXSBoolean(false);
  627. var bResult = false;
  628. for (var nLeftIndex = 0, nLeftLength = oLeft.length, bLeft, vLeft; (nLeftIndex < nLeftLength) &&!bResult; nLeftIndex++) {
  629. for (var nRightIndex = 0, nRightLength = oRight.length, bRight, vRight; (nRightIndex < nRightLength) &&!bResult; nRightIndex++) {
  630. vLeft = oLeft[nLeftIndex];
  631. vRight = oRight[nRightIndex];
  632. bLeft = vLeft instanceof cXSUntypedAtomic;
  633. bRight = vRight instanceof cXSUntypedAtomic;
  634. if (bLeft && bRight) {
  635. vLeft = cXSString.cast(vLeft);
  636. vRight = cXSString.cast(vRight);
  637. }
  638. else {
  639. if (bLeft) {
  640. if (vRight instanceof cXSDayTimeDuration)
  641. vLeft = cXSDayTimeDuration.cast(vLeft);
  642. else
  643. if (vRight instanceof cXSYearMonthDuration)
  644. vLeft = cXSYearMonthDuration.cast(vLeft);
  645. else
  646. if (vRight.primitiveKind)
  647. vLeft = hStaticContext_dataTypes[vRight.primitiveKind].cast(vLeft);
  648. }
  649. else
  650. if (bRight) {
  651. if (vLeft instanceof cXSDayTimeDuration)
  652. vRight = cXSDayTimeDuration.cast(vRight);
  653. else
  654. if (vLeft instanceof cXSYearMonthDuration)
  655. vRight = cXSYearMonthDuration.cast(vRight);
  656. else
  657. if (vLeft.primitiveKind)
  658. vRight = hStaticContext_dataTypes[vLeft.primitiveKind].cast(vRight);
  659. }
  660. if (vLeft instanceof cXSAnyURI)
  661. vLeft = cXSString.cast(vLeft);
  662. if (vRight instanceof cXSAnyURI)
  663. vRight = cXSString.cast(vRight);
  664. }
  665. bResult = hComparisonExpr_ValueComp_operators[hComparisonExpr_GeneralComp_map[oExpr.operator]](vLeft, vRight, oContext).valueOf();
  666. }
  667. }
  668. return new cXSBoolean(bResult);
  669. };
  670. var hComparisonExpr_GeneralComp_map = {
  671. '=': 'eq',
  672. '!=': 'ne',
  673. '>': 'gt',
  674. '<': 'lt',
  675. '>=': 'ge',
  676. '<=': 'le'
  677. };
  678. function fComparisonExpr_ValueComp(oExpr, oContext) {
  679. var oLeft = fFunction_sequence_atomize(oExpr.left.evaluate(oContext), oContext);
  680. if (!oLeft.length)
  681. return null;
  682. fFunctionCall_assertSequenceCardinality(oContext, oLeft, '?'
  683. , "first operand of '" + oExpr.operator + "'"
  684. );
  685. var oRight = fFunction_sequence_atomize(oExpr.right.evaluate(oContext), oContext);
  686. if (!oRight.length)
  687. return null;
  688. fFunctionCall_assertSequenceCardinality(oContext, oRight, '?'
  689. , "second operand of '" + oExpr.operator + "'"
  690. );
  691. var vLeft = oLeft[0],
  692. vRight = oRight[0];
  693. if (vLeft instanceof cXSUntypedAtomic)
  694. vLeft = cXSString.cast(vLeft);
  695. if (vRight instanceof cXSUntypedAtomic)
  696. vRight = cXSString.cast(vRight);
  697. if (vLeft instanceof cXSAnyURI)
  698. vLeft = cXSString.cast(vLeft);
  699. if (vRight instanceof cXSAnyURI)
  700. vRight = cXSString.cast(vRight);
  701. return hComparisonExpr_ValueComp_operators[oExpr.operator](vLeft, vRight, oContext);
  702. };
  703. var hComparisonExpr_ValueComp_operators = {};
  704. hComparisonExpr_ValueComp_operators['eq'] = function(oLeft, oRight, oContext) {
  705. var sOperator = '';
  706. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  707. if (fXSAnyAtomicType_isNumeric(oRight))
  708. sOperator = "numeric-equal";
  709. }
  710. else
  711. if (oLeft instanceof cXSBoolean) {
  712. if (oRight instanceof cXSBoolean)
  713. sOperator = "boolean-equal";
  714. }
  715. else
  716. if (oLeft instanceof cXSString) {
  717. if (oRight instanceof cXSString)
  718. return hStaticContext_operators["numeric-equal"].call(oContext, hStaticContext_functions["compare"].call(oContext, oLeft, oRight), new cXSInteger(0));
  719. }
  720. else
  721. if (oLeft instanceof cXSDate) {
  722. if (oRight instanceof cXSDate)
  723. sOperator = "date-equal";
  724. }
  725. else
  726. if (oLeft instanceof cXSTime) {
  727. if (oRight instanceof cXSTime)
  728. sOperator = "time-equal";
  729. }
  730. else
  731. if (oLeft instanceof cXSDateTime) {
  732. if (oRight instanceof cXSDateTime)
  733. sOperator = "dateTime-equal";
  734. }
  735. else
  736. if (oLeft instanceof cXSDuration) {
  737. if (oRight instanceof cXSDuration)
  738. sOperator = "duration-equal";
  739. }
  740. else
  741. if (oLeft instanceof cXSGYearMonth) {
  742. if (oRight instanceof cXSGYearMonth)
  743. sOperator = "gYearMonth-equal";
  744. }
  745. else
  746. if (oLeft instanceof cXSGYear) {
  747. if (oRight instanceof cXSGYear)
  748. sOperator = "gYear-equal";
  749. }
  750. else
  751. if (oLeft instanceof cXSGMonthDay) {
  752. if (oRight instanceof cXSGMonthDay)
  753. sOperator = "gMonthDay-equal";
  754. }
  755. else
  756. if (oLeft instanceof cXSGMonth) {
  757. if (oRight instanceof cXSGMonth)
  758. sOperator = "gMonth-equal";
  759. }
  760. else
  761. if (oLeft instanceof cXSGDay) {
  762. if (oRight instanceof cXSGDay)
  763. sOperator = "gDay-equal";
  764. }
  765. else
  766. if (oLeft instanceof cXSQName) {
  767. if (oRight instanceof cXSQName)
  768. sOperator = "QName-equal";
  769. }
  770. else
  771. if (oLeft instanceof cXSHexBinary) {
  772. if (oRight instanceof cXSHexBinary)
  773. sOperator = "hexBinary-equal";
  774. }
  775. else
  776. if (oLeft instanceof cXSBase64Binary) {
  777. if (oRight instanceof cXSBase64Binary)
  778. sOperator = "base64Binary-equal";
  779. }
  780. if (sOperator)
  781. return hStaticContext_operators[sOperator].call(oContext, oLeft, oRight);
  782. throw new cException("XPTY0004"
  783. , "Cannot compare values of given types"
  784. ); };
  785. hComparisonExpr_ValueComp_operators['ne'] = function(oLeft, oRight, oContext) {
  786. return new cXSBoolean(!hComparisonExpr_ValueComp_operators['eq'](oLeft, oRight, oContext).valueOf());
  787. };
  788. hComparisonExpr_ValueComp_operators['gt'] = function(oLeft, oRight, oContext) {
  789. var sOperator = '';
  790. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  791. if (fXSAnyAtomicType_isNumeric(oRight))
  792. sOperator = "numeric-greater-than";
  793. }
  794. else
  795. if (oLeft instanceof cXSBoolean) {
  796. if (oRight instanceof cXSBoolean)
  797. sOperator = "boolean-greater-than";
  798. }
  799. else
  800. if (oLeft instanceof cXSString) {
  801. if (oRight instanceof cXSString)
  802. return hStaticContext_operators["numeric-greater-than"].call(oContext, hStaticContext_functions["compare"].call(oContext, oLeft, oRight), new cXSInteger(0));
  803. }
  804. else
  805. if (oLeft instanceof cXSDate) {
  806. if (oRight instanceof cXSDate)
  807. sOperator = "date-greater-than";
  808. }
  809. else
  810. if (oLeft instanceof cXSTime) {
  811. if (oRight instanceof cXSTime)
  812. sOperator = "time-greater-than";
  813. }
  814. else
  815. if (oLeft instanceof cXSDateTime) {
  816. if (oRight instanceof cXSDateTime)
  817. sOperator = "dateTime-greater-than";
  818. }
  819. else
  820. if (oLeft instanceof cXSYearMonthDuration) {
  821. if (oRight instanceof cXSYearMonthDuration)
  822. sOperator = "yearMonthDuration-greater-than";
  823. }
  824. else
  825. if (oLeft instanceof cXSDayTimeDuration) {
  826. if (oRight instanceof cXSDayTimeDuration)
  827. sOperator = "dayTimeDuration-greater-than";
  828. }
  829. if (sOperator)
  830. return hStaticContext_operators[sOperator].call(oContext, oLeft, oRight);
  831. throw new cException("XPTY0004"
  832. , "Cannot compare values of given types"
  833. ); };
  834. hComparisonExpr_ValueComp_operators['lt'] = function(oLeft, oRight, oContext) {
  835. var sOperator = '';
  836. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  837. if (fXSAnyAtomicType_isNumeric(oRight))
  838. sOperator = "numeric-less-than";
  839. }
  840. else
  841. if (oLeft instanceof cXSBoolean) {
  842. if (oRight instanceof cXSBoolean)
  843. sOperator = "boolean-less-than";
  844. }
  845. else
  846. if (oLeft instanceof cXSString) {
  847. if (oRight instanceof cXSString)
  848. return hStaticContext_operators["numeric-less-than"].call(oContext, hStaticContext_functions["compare"].call(oContext, oLeft, oRight), new cXSInteger(0));
  849. }
  850. else
  851. if (oLeft instanceof cXSDate) {
  852. if (oRight instanceof cXSDate)
  853. sOperator = "date-less-than";
  854. }
  855. else
  856. if (oLeft instanceof cXSTime) {
  857. if (oRight instanceof cXSTime)
  858. sOperator = "time-less-than";
  859. }
  860. else
  861. if (oLeft instanceof cXSDateTime) {
  862. if (oRight instanceof cXSDateTime)
  863. sOperator = "dateTime-less-than";
  864. }
  865. else
  866. if (oLeft instanceof cXSYearMonthDuration) {
  867. if (oRight instanceof cXSYearMonthDuration)
  868. sOperator = "yearMonthDuration-less-than";
  869. }
  870. else
  871. if (oLeft instanceof cXSDayTimeDuration) {
  872. if (oRight instanceof cXSDayTimeDuration)
  873. sOperator = "dayTimeDuration-less-than";
  874. }
  875. if (sOperator)
  876. return hStaticContext_operators[sOperator].call(oContext, oLeft, oRight);
  877. throw new cException("XPTY0004"
  878. , "Cannot compare values of given types"
  879. ); };
  880. hComparisonExpr_ValueComp_operators['ge'] = function(oLeft, oRight, oContext) {
  881. var sOperator = '';
  882. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  883. if (fXSAnyAtomicType_isNumeric(oRight))
  884. return hStaticContext_operators["numeric-greater-than"].call(oContext, oLeft, oRight) || hStaticContext_operators["numeric-equal"].call(oContext, oLeft, oRight);
  885. }
  886. else
  887. if (oLeft instanceof cXSBoolean) {
  888. if (oRight instanceof cXSBoolean)
  889. sOperator = "boolean-less-than";
  890. }
  891. else
  892. if (oLeft instanceof cXSString) {
  893. if (oRight instanceof cXSString)
  894. return hStaticContext_operators["numeric-greater-than"].call(oContext, hStaticContext_functions["compare"].call(oContext, oLeft, oRight), new cXSInteger(-1));
  895. }
  896. else
  897. if (oLeft instanceof cXSDate) {
  898. if (oRight instanceof cXSDate)
  899. sOperator = "date-less-than";
  900. }
  901. else
  902. if (oLeft instanceof cXSTime) {
  903. if (oRight instanceof cXSTime)
  904. sOperator = "time-less-than";
  905. }
  906. else
  907. if (oLeft instanceof cXSDateTime) {
  908. if (oRight instanceof cXSDateTime)
  909. sOperator = "dateTime-less-than";
  910. }
  911. else
  912. if (oLeft instanceof cXSYearMonthDuration) {
  913. if (oRight instanceof cXSYearMonthDuration)
  914. sOperator = "yearMonthDuration-less-than";
  915. }
  916. else
  917. if (oLeft instanceof cXSDayTimeDuration) {
  918. if (oRight instanceof cXSDayTimeDuration)
  919. sOperator = "dayTimeDuration-less-than";
  920. }
  921. if (sOperator)
  922. return new cXSBoolean(!hStaticContext_operators[sOperator].call(oContext, oLeft, oRight).valueOf());
  923. throw new cException("XPTY0004"
  924. , "Cannot compare values of given types"
  925. ); };
  926. hComparisonExpr_ValueComp_operators['le'] = function(oLeft, oRight, oContext) {
  927. var sOperator = '';
  928. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  929. if (fXSAnyAtomicType_isNumeric(oRight))
  930. return hStaticContext_operators["numeric-less-than"].call(oContext, oLeft, oRight) || hStaticContext_operators["numeric-equal"].call(oContext, oLeft, oRight);
  931. }
  932. else
  933. if (oLeft instanceof cXSBoolean) {
  934. if (oRight instanceof cXSBoolean)
  935. sOperator = "boolean-greater-than";
  936. }
  937. else
  938. if (oLeft instanceof cXSString) {
  939. if (oRight instanceof cXSString)
  940. return hStaticContext_operators["numeric-less-than"].call(oContext, hStaticContext_functions["compare"].call(oContext, oLeft, oRight), new cXSInteger(1));
  941. }
  942. else
  943. if (oLeft instanceof cXSDate) {
  944. if (oRight instanceof cXSDate)
  945. sOperator = "date-greater-than";
  946. }
  947. else
  948. if (oLeft instanceof cXSTime) {
  949. if (oRight instanceof cXSTime)
  950. sOperator = "time-greater-than";
  951. }
  952. else
  953. if (oLeft instanceof cXSDateTime) {
  954. if (oRight instanceof cXSDateTime)
  955. sOperator = "dateTime-greater-than";
  956. }
  957. else
  958. if (oLeft instanceof cXSYearMonthDuration) {
  959. if (oRight instanceof cXSYearMonthDuration)
  960. sOperator = "yearMonthDuration-greater-than";
  961. }
  962. else
  963. if (oLeft instanceof cXSDayTimeDuration) {
  964. if (oRight instanceof cXSDayTimeDuration)
  965. sOperator = "dayTimeDuration-greater-than";
  966. }
  967. if (sOperator)
  968. return new cXSBoolean(!hStaticContext_operators[sOperator].call(oContext, oLeft, oRight).valueOf());
  969. throw new cException("XPTY0004"
  970. , "Cannot compare values of given types"
  971. ); };
  972. function fComparisonExpr_NodeComp(oExpr, oContext) {
  973. var oLeft = oExpr.left.evaluate(oContext);
  974. if (!oLeft.length)
  975. return null;
  976. fFunctionCall_assertSequenceCardinality(oContext, oLeft, '?'
  977. , "first operand of '" + oExpr.operator + "'"
  978. );
  979. fFunctionCall_assertSequenceItemType(oContext, oLeft, cXTNode
  980. , "first operand of '" + oExpr.operator + "'"
  981. );
  982. var oRight = oExpr.right.evaluate(oContext);
  983. if (!oRight.length)
  984. return null;
  985. fFunctionCall_assertSequenceCardinality(oContext, oRight, '?'
  986. , "second operand of '" + oExpr.operator + "'"
  987. );
  988. fFunctionCall_assertSequenceItemType(oContext, oRight, cXTNode
  989. , "second operand of '" + oExpr.operator + "'"
  990. );
  991. return hComparisonExpr_NodeComp_operators[oExpr.operator](oLeft[0], oRight[0], oContext);
  992. };
  993. var hComparisonExpr_NodeComp_operators = {};
  994. hComparisonExpr_NodeComp_operators['is'] = function(oLeft, oRight, oContext) {
  995. return hStaticContext_operators["is-same-node"].call(oContext, oLeft, oRight);
  996. };
  997. hComparisonExpr_NodeComp_operators['>>'] = function(oLeft, oRight, oContext) {
  998. return hStaticContext_operators["node-after"].call(oContext, oLeft, oRight);
  999. };
  1000. hComparisonExpr_NodeComp_operators['<<'] = function(oLeft, oRight, oContext) {
  1001. return hStaticContext_operators["node-before"].call(oContext, oLeft, oRight);
  1002. };
  1003. var hComparisonExpr_operators = {
  1004. '=': fComparisonExpr_GeneralComp,
  1005. '!=': fComparisonExpr_GeneralComp,
  1006. '<': fComparisonExpr_GeneralComp,
  1007. '<=': fComparisonExpr_GeneralComp,
  1008. '>': fComparisonExpr_GeneralComp,
  1009. '>=': fComparisonExpr_GeneralComp,
  1010. 'eq': fComparisonExpr_ValueComp,
  1011. 'ne': fComparisonExpr_ValueComp,
  1012. 'lt': fComparisonExpr_ValueComp,
  1013. 'le': fComparisonExpr_ValueComp,
  1014. 'gt': fComparisonExpr_ValueComp,
  1015. 'ge': fComparisonExpr_ValueComp,
  1016. 'is': fComparisonExpr_NodeComp,
  1017. '>>': fComparisonExpr_NodeComp,
  1018. '<<': fComparisonExpr_NodeComp
  1019. };
  1020. function cAdditiveExpr(oExpr) {
  1021. this.left = oExpr;
  1022. this.items = [];
  1023. };
  1024. cAdditiveExpr.prototype.left = null;
  1025. cAdditiveExpr.prototype.items = null;
  1026. var hAdditiveExpr_operators = {};
  1027. hAdditiveExpr_operators['+'] = function(oLeft, oRight, oContext) {
  1028. var sOperator = '',
  1029. bReverse = false;
  1030. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  1031. if (fXSAnyAtomicType_isNumeric(oRight))
  1032. sOperator = "numeric-add";
  1033. }
  1034. else
  1035. if (oLeft instanceof cXSDate) {
  1036. if (oRight instanceof cXSYearMonthDuration)
  1037. sOperator = "add-yearMonthDuration-to-date";
  1038. else
  1039. if (oRight instanceof cXSDayTimeDuration)
  1040. sOperator = "add-dayTimeDuration-to-date";
  1041. }
  1042. else
  1043. if (oLeft instanceof cXSYearMonthDuration) {
  1044. if (oRight instanceof cXSDate) {
  1045. sOperator = "add-yearMonthDuration-to-date";
  1046. bReverse = true;
  1047. }
  1048. else
  1049. if (oRight instanceof cXSDateTime) {
  1050. sOperator = "add-yearMonthDuration-to-dateTime";
  1051. bReverse = true;
  1052. }
  1053. else
  1054. if (oRight instanceof cXSYearMonthDuration)
  1055. sOperator = "add-yearMonthDurations";
  1056. }
  1057. else
  1058. if (oLeft instanceof cXSDayTimeDuration) {
  1059. if (oRight instanceof cXSDate) {
  1060. sOperator = "add-dayTimeDuration-to-date";
  1061. bReverse = true;
  1062. }
  1063. else
  1064. if (oRight instanceof cXSTime) {
  1065. sOperator = "add-dayTimeDuration-to-time";
  1066. bReverse = true;
  1067. }
  1068. else
  1069. if (oRight instanceof cXSDateTime) {
  1070. sOperator = "add-dayTimeDuration-to-dateTime";
  1071. bReverse = true;
  1072. }
  1073. else
  1074. if (oRight instanceof cXSDayTimeDuration)
  1075. sOperator = "add-dayTimeDurations";
  1076. }
  1077. else
  1078. if (oLeft instanceof cXSTime) {
  1079. if (oRight instanceof cXSDayTimeDuration)
  1080. sOperator = "add-dayTimeDuration-to-time";
  1081. }
  1082. else
  1083. if (oLeft instanceof cXSDateTime) {
  1084. if (oRight instanceof cXSYearMonthDuration)
  1085. sOperator = "add-yearMonthDuration-to-dateTime";
  1086. else
  1087. if (oRight instanceof cXSDayTimeDuration)
  1088. sOperator = "add-dayTimeDuration-to-dateTime";
  1089. }
  1090. if (sOperator)
  1091. return hStaticContext_operators[sOperator].call(oContext, bReverse ? oRight : oLeft, bReverse ? oLeft : oRight);
  1092. throw new cException("XPTY0004"
  1093. , "Arithmetic operator is not defined for provided arguments"
  1094. ); };
  1095. hAdditiveExpr_operators['-'] = function (oLeft, oRight, oContext) {
  1096. var sOperator = '';
  1097. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  1098. if (fXSAnyAtomicType_isNumeric(oRight))
  1099. sOperator = "numeric-subtract";
  1100. }
  1101. else
  1102. if (oLeft instanceof cXSDate) {
  1103. if (oRight instanceof cXSDate)
  1104. sOperator = "subtract-dates";
  1105. else
  1106. if (oRight instanceof cXSYearMonthDuration)
  1107. sOperator = "subtract-yearMonthDuration-from-date";
  1108. else
  1109. if (oRight instanceof cXSDayTimeDuration)
  1110. sOperator = "subtract-dayTimeDuration-from-date";
  1111. }
  1112. else
  1113. if (oLeft instanceof cXSTime) {
  1114. if (oRight instanceof cXSTime)
  1115. sOperator = "subtract-times";
  1116. else
  1117. if (oRight instanceof cXSDayTimeDuration)
  1118. sOperator = "subtract-dayTimeDuration-from-time";
  1119. }
  1120. else
  1121. if (oLeft instanceof cXSDateTime) {
  1122. if (oRight instanceof cXSDateTime)
  1123. sOperator = "subtract-dateTimes";
  1124. else
  1125. if (oRight instanceof cXSYearMonthDuration)
  1126. sOperator = "subtract-yearMonthDuration-from-dateTime";
  1127. else
  1128. if (oRight instanceof cXSDayTimeDuration)
  1129. sOperator = "subtract-dayTimeDuration-from-dateTime";
  1130. }
  1131. else
  1132. if (oLeft instanceof cXSYearMonthDuration) {
  1133. if (oRight instanceof cXSYearMonthDuration)
  1134. sOperator = "subtract-yearMonthDurations";
  1135. }
  1136. else
  1137. if (oLeft instanceof cXSDayTimeDuration) {
  1138. if (oRight instanceof cXSDayTimeDuration)
  1139. sOperator = "subtract-dayTimeDurations";
  1140. }
  1141. if (sOperator)
  1142. return hStaticContext_operators[sOperator].call(oContext, oLeft, oRight);
  1143. throw new cException("XPTY0004"
  1144. , "Arithmetic operator is not defined for provided arguments"
  1145. ); };
  1146. function fAdditiveExpr_parse (oLexer, oStaticContext) {
  1147. var oExpr;
  1148. if (oLexer.eof() ||!(oExpr = fMultiplicativeExpr_parse(oLexer, oStaticContext)))
  1149. return;
  1150. if (!(oLexer.peek() in hAdditiveExpr_operators))
  1151. return oExpr;
  1152. var oAdditiveExpr = new cAdditiveExpr(oExpr),
  1153. sOperator;
  1154. while ((sOperator = oLexer.peek()) in hAdditiveExpr_operators) {
  1155. oLexer.next();
  1156. if (oLexer.eof() ||!(oExpr = fMultiplicativeExpr_parse(oLexer, oStaticContext)))
  1157. throw new cException("XPST0003"
  1158. , "Expected second operand in additive expression"
  1159. );
  1160. oAdditiveExpr.items.push([sOperator, oExpr]);
  1161. }
  1162. return oAdditiveExpr;
  1163. };
  1164. cAdditiveExpr.prototype.evaluate = function (oContext) {
  1165. var oLeft = fFunction_sequence_atomize(this.left.evaluate(oContext), oContext);
  1166. if (!oLeft.length)
  1167. return [];
  1168. fFunctionCall_assertSequenceCardinality(oContext, oLeft, '?'
  1169. , "first operand of '" + this.items[0][0] + "'"
  1170. );
  1171. var vLeft = oLeft[0];
  1172. if (vLeft instanceof cXSUntypedAtomic)
  1173. vLeft = cXSDouble.cast(vLeft);
  1174. for (var nIndex = 0, nLength = this.items.length, oRight, vRight; nIndex < nLength; nIndex++) {
  1175. oRight = fFunction_sequence_atomize(this.items[nIndex][1].evaluate(oContext), oContext);
  1176. if (!oRight.length)
  1177. return [];
  1178. fFunctionCall_assertSequenceCardinality(oContext, oRight, '?'
  1179. , "first operand of '" + this.items[nIndex][0] + "'"
  1180. );
  1181. vRight = oRight[0];
  1182. if (vRight instanceof cXSUntypedAtomic)
  1183. vRight = cXSDouble.cast(vRight);
  1184. vLeft = hAdditiveExpr_operators[this.items[nIndex][0]](vLeft, vRight, oContext);
  1185. }
  1186. return [vLeft];
  1187. };
  1188. function cMultiplicativeExpr(oExpr) {
  1189. this.left = oExpr;
  1190. this.items = [];
  1191. };
  1192. cMultiplicativeExpr.prototype.left = null;
  1193. cMultiplicativeExpr.prototype.items = null;
  1194. var hMultiplicativeExpr_operators = {};
  1195. hMultiplicativeExpr_operators['*'] = function (oLeft, oRight, oContext) {
  1196. var sOperator = '',
  1197. bReverse = false;
  1198. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  1199. if (fXSAnyAtomicType_isNumeric(oRight))
  1200. sOperator = "numeric-multiply";
  1201. else
  1202. if (oRight instanceof cXSYearMonthDuration) {
  1203. sOperator = "multiply-yearMonthDuration";
  1204. bReverse = true;
  1205. }
  1206. else
  1207. if (oRight instanceof cXSDayTimeDuration) {
  1208. sOperator = "multiply-dayTimeDuration";
  1209. bReverse = true;
  1210. }
  1211. }
  1212. else {
  1213. if (oLeft instanceof cXSYearMonthDuration) {
  1214. if (fXSAnyAtomicType_isNumeric(oRight))
  1215. sOperator = "multiply-yearMonthDuration";
  1216. }
  1217. else
  1218. if (oLeft instanceof cXSDayTimeDuration) {
  1219. if (fXSAnyAtomicType_isNumeric(oRight))
  1220. sOperator = "multiply-dayTimeDuration";
  1221. }
  1222. }
  1223. if (sOperator)
  1224. return hStaticContext_operators[sOperator].call(oContext, bReverse ? oRight : oLeft, bReverse ? oLeft : oRight);
  1225. throw new cException("XPTY0004"
  1226. , "Arithmetic operator is not defined for provided arguments"
  1227. ); };
  1228. hMultiplicativeExpr_operators['div'] = function (oLeft, oRight, oContext) {
  1229. var sOperator = '';
  1230. if (fXSAnyAtomicType_isNumeric(oLeft)) {
  1231. if (fXSAnyAtomicType_isNumeric(oRight))
  1232. sOperator = "numeric-divide";
  1233. }
  1234. else
  1235. if (oLeft instanceof cXSYearMonthDuration) {
  1236. if (fXSAnyAtomicType_isNumeric(oRight))
  1237. sOperator = "divide-yearMonthDuration";
  1238. else
  1239. if (oRight instanceof cXSYearMonthDuration)
  1240. sOperator = "divide-yearMonthDuration-by-yearMonthDuration";
  1241. }
  1242. else
  1243. if (oLeft instanceof cXSDayTimeDuration) {
  1244. if (fXSAnyAtomicType_isNumeric(oRight))
  1245. sOperator = "divide-dayTimeDuration";
  1246. else
  1247. if (oRight instanceof cXSDayTimeDuration)
  1248. sOperator = "divide-dayTimeDuration-by-dayTimeDuration";
  1249. }
  1250. if (sOperator)
  1251. return hStaticContext_operators[sOperator].call(oContext, oLeft, oRight);
  1252. throw new cException("XPTY0004"
  1253. , "Arithmetic operator is not defined for provided arguments"
  1254. ); };
  1255. hMultiplicativeExpr_operators['idiv'] = function (oLeft, oRight, oContext) {
  1256. if (fXSAnyAtomicType_isNumeric(oLeft) && fXSAnyAtomicType_isNumeric(oRight))
  1257. return hStaticContext_operators["numeric-integer-divide"].call(oContext, oLeft, oRight);
  1258. throw new cException("XPTY0004"
  1259. , "Arithmetic operator is not defined for provided arguments"
  1260. ); };
  1261. hMultiplicativeExpr_operators['mod'] = function (oLeft, oRight, oContext) {
  1262. if (fXSAnyAtomicType_isNumeric(oLeft) && fXSAnyAtomicType_isNumeric(oRight))
  1263. return hStaticContext_operators["numeric-mod"].call(oContext, oLeft, oRight);
  1264. throw new cException("XPTY0004"
  1265. , "Arithmetic operator is not defined for provided arguments"
  1266. ); };
  1267. function fMultiplicativeExpr_parse (oLexer, oStaticContext) {
  1268. var oExpr;
  1269. if (oLexer.eof() ||!(oExpr = fUnionExpr_parse(oLexer, oStaticContext)))
  1270. return;
  1271. if (!(oLexer.peek() in hMultiplicativeExpr_operators))
  1272. return oExpr;
  1273. var oMultiplicativeExpr = new cMultiplicativeExpr(oExpr),
  1274. sOperator;
  1275. while ((sOperator = oLexer.peek()) in hMultiplicativeExpr_operators) {
  1276. oLexer.next();
  1277. if (oLexer.eof() ||!(oExpr = fUnionExpr_parse(oLexer, oStaticContext)))
  1278. throw new cException("XPST0003"
  1279. , "Expected second operand in multiplicative expression"
  1280. );
  1281. oMultiplicativeExpr.items.push([sOperator, oExpr]);
  1282. }
  1283. return oMultiplicativeExpr;
  1284. };
  1285. cMultiplicativeExpr.prototype.evaluate = function (oContext) {
  1286. var oLeft = fFunction_sequence_atomize(this.left.evaluate(oContext), oContext);
  1287. if (!oLeft.length)
  1288. return [];
  1289. fFunctionCall_assertSequenceCardinality(oContext, oLeft, '?'
  1290. , "first operand of '" + this.items[0][0] + "'"
  1291. );
  1292. var vLeft = oLeft[0];
  1293. if (vLeft instanceof cXSUntypedAtomic)
  1294. vLeft = cXSDouble.cast(vLeft);
  1295. for (var nIndex = 0, nLength = this.items.length, oRight, vRight; nIndex < nLength; nIndex++) {
  1296. oRight = fFunction_sequence_atomize(this.items[nIndex][1].evaluate(oContext), oContext);
  1297. if (!oRight.length)
  1298. return [];
  1299. fFunctionCall_assertSequenceCardinality(oContext, oRight, '?'
  1300. , "second operand of '" + this.items[nIndex][0] + "'"
  1301. );
  1302. vRight = oRight[0];
  1303. if (vRight instanceof cXSUntypedAtomic)
  1304. vRight = cXSDouble.cast(vRight);
  1305. vLeft = hMultiplicativeExpr_operators[this.items[nIndex][0]](vLeft, vRight, oContext);
  1306. }
  1307. return [vLeft];
  1308. };
  1309. function cUnaryExpr(sOperator, oExpr) {
  1310. this.operator = sOperator;
  1311. this.expression = oExpr;
  1312. };
  1313. cUnaryExpr.prototype.operator = null;
  1314. cUnaryExpr.prototype.expression = null;
  1315. var hUnaryExpr_operators = {};
  1316. hUnaryExpr_operators['-'] = function(oRight, oContext) {
  1317. if (fXSAnyAtomicType_isNumeric(oRight))
  1318. return hStaticContext_operators["numeric-unary-minus"].call(oContext, oRight);
  1319. throw new cException("XPTY0004"
  1320. , "Arithmetic operator is not defined for provided arguments"
  1321. ); };
  1322. hUnaryExpr_operators['+'] = function(oRight, oContext) {
  1323. if (fXSAnyAtomicType_isNumeric(oRight))
  1324. return hStaticContext_operators["numeric-unary-plus"].call(oContext, oRight);
  1325. throw new cException("XPTY0004"
  1326. , "Arithmetic operator is not defined for provided arguments"
  1327. ); };
  1328. function fUnaryExpr_parse (oLexer, oStaticContext) {
  1329. if (oLexer.eof())
  1330. return;
  1331. if (!(oLexer.peek() in hUnaryExpr_operators))
  1332. return fValueExpr_parse(oLexer, oStaticContext);
  1333. var sOperator = '+',
  1334. oExpr;
  1335. while (oLexer.peek() in hUnaryExpr_operators) {
  1336. if (oLexer.peek() == '-')
  1337. sOperator = sOperator == '-' ? '+' : '-';
  1338. oLexer.next();
  1339. }
  1340. if (oLexer.eof() ||!(oExpr = fValueExpr_parse(oLexer, oStaticContext)))
  1341. throw new cException("XPST0003"
  1342. , "Expected operand in unary expression"
  1343. );
  1344. return new cUnaryExpr(sOperator, oExpr);
  1345. };
  1346. cUnaryExpr.prototype.evaluate = function (oContext) {
  1347. var oRight = fFunction_sequence_atomize(this.expression.evaluate(oContext), oContext);
  1348. if (!oRight.length)
  1349. return [];
  1350. fFunctionCall_assertSequenceCardinality(oContext, oRight, '?'
  1351. , "second operand of '" + this.operator + "'"
  1352. );
  1353. var vRight = oRight[0];
  1354. if (vRight instanceof cXSUntypedAtomic)
  1355. vRight = cXSDouble.cast(vRight);
  1356. return [hUnaryExpr_operators[this.operator](vRight, oContext)];
  1357. };
  1358. function cValueExpr() {
  1359. };
  1360. function fValueExpr_parse (oLexer, oStaticContext) {
  1361. return fPathExpr_parse(oLexer, oStaticContext);
  1362. };
  1363. function cOrExpr(oExpr) {
  1364. this.left = oExpr;
  1365. this.items = [];
  1366. };
  1367. cOrExpr.prototype.left = null;
  1368. cOrExpr.prototype.items = null;
  1369. function fOrExpr_parse (oLexer, oStaticContext) {
  1370. var oExpr;
  1371. if (oLexer.eof() ||!(oExpr = fAndExpr_parse(oLexer, oStaticContext)))
  1372. return;
  1373. if (oLexer.peek() != "or")
  1374. return oExpr;
  1375. var oOrExpr = new cOrExpr(oExpr);
  1376. while (oLexer.peek() == "or") {
  1377. oLexer.next();
  1378. if (oLexer.eof() ||!(oExpr = fAndExpr_parse(oLexer, oStaticContext)))
  1379. throw new cException("XPST0003"
  1380. , "Expected second operand in logical expression"
  1381. );
  1382. oOrExpr.items.push(oExpr);
  1383. }
  1384. return oOrExpr;
  1385. };
  1386. cOrExpr.prototype.evaluate = function (oContext) {
  1387. var bValue = fFunction_sequence_toEBV(this.left.evaluate(oContext), oContext);
  1388. for (var nIndex = 0, nLength = this.items.length; (nIndex < nLength) && !bValue; nIndex++)
  1389. bValue = fFunction_sequence_toEBV(this.items[nIndex].evaluate(oContext), oContext);
  1390. return [new cXSBoolean(bValue)];
  1391. };
  1392. function cAndExpr(oExpr) {
  1393. this.left = oExpr;
  1394. this.items = [];
  1395. };
  1396. cAndExpr.prototype.left = null;
  1397. cAndExpr.prototype.items = null;
  1398. function fAndExpr_parse (oLexer, oStaticContext) {
  1399. var oExpr;
  1400. if (oLexer.eof() ||!(oExpr = fComparisonExpr_parse(oLexer, oStaticContext)))
  1401. return;
  1402. if (oLexer.peek() != "and")
  1403. return oExpr;
  1404. var oAndExpr = new cAndExpr(oExpr);
  1405. while (oLexer.peek() == "and") {
  1406. oLexer.next();
  1407. if (oLexer.eof() ||!(oExpr = fComparisonExpr_parse(oLexer, oStaticContext)))
  1408. throw new cException("XPST0003"
  1409. , "Expected second operand in logical expression"
  1410. );
  1411. oAndExpr.items.push(oExpr);
  1412. }
  1413. return oAndExpr;
  1414. };
  1415. cAndExpr.prototype.evaluate = function (oContext) {
  1416. var bValue = fFunction_sequence_toEBV(this.left.evaluate(oContext), oContext);
  1417. for (var nIndex = 0, nLength = this.items.length; (nIndex < nLength) && bValue; nIndex++)
  1418. bValue = fFunction_sequence_toEBV(this.items[nIndex].evaluate(oContext), oContext);
  1419. return [new cXSBoolean(bValue)];
  1420. };
  1421. function cStepExpr() {
  1422. };
  1423. cStepExpr.prototype.predicates = null;
  1424. function fStepExpr_parse (oLexer, oStaticContext) {
  1425. if (!oLexer.eof())
  1426. return fFilterExpr_parse(oLexer, oStaticContext)
  1427. ||