rsel-exprparser-basic

Parses RSel-specific expression text and rebuilds it in the UI.

目前为 2024-04-28 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/17641/1367961/rsel-exprparser-basic.js

  1. // ==UserScript==
  2. // @name rsel-exprparser-basic
  3. // @namespace https://greasyfork.org/users/11629-TheLastTaterTot
  4. // @version 2024.03.08.01
  5. // @description Parses RSel-specific expression text and rebuilds it in the UI.
  6. // @author TheLastTaterTot, jangliss, fuji2086
  7. // @include https://editor-beta.waze.com/*editor/*
  8. // @include https://www.waze.com/*editor/*
  9. // @exclude https://www.waze.com/*user/editor/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // Main usage: RSelExprParser.updateExpression(<rsel expression text>)
  14.  
  15. var RSelExprParser = {
  16. version: '2024.04.28.01',
  17. new__EXPR_DEBUGINFO: function(m, exprWord, exprPhrase) {
  18. return {
  19. m: m,
  20. exprMatches: exprWord,
  21. exprMatchPhrases: exprPhrase,
  22. exprBuild: {},
  23. err: null ,
  24. errorMsg: null
  25. };
  26. },
  27. escapeRegExp(s) {
  28. return s.replace(/[.*+?{}()|[\]\\\/]/g, '\\$&'); // $& means the whole matched string
  29. },
  30. _getSelectionIndex: function(selector, selText) {
  31. for (var s = 0, sLength = selector.length; s < sLength; s++) {
  32. if (new RegExp(RSelExprParser.escapeRegExp(selText),'i').test(selector[s].text) && !selector[s].disabled) {
  33. return selector[s].value;
  34. }
  35. }
  36. },
  37. _getSelectOptions: function(selector) {
  38. for (var opts = [], s = 0, sLength = selector.length; s < sLength; s++) {
  39. if (!selector[s].disabled) {
  40. opts[s] = selector[s].text.toLowerCase();
  41. }
  42. }
  43. return opts;
  44. },
  45. _getNewExprBuild: function() {
  46. return {
  47. cond: null ,
  48. op: null ,
  49. op2: null ,
  50. val: null ,
  51. val2: null ,
  52. condmod: null ,
  53. errorCode: 0
  54.  
  55. }
  56. },
  57. getCurrentExprText: function(){
  58. return document.getElementById('outRSExpr').value;
  59. },
  60. /*Using RSel DOM elements rather than requesting dev to provide direct modifiction of RSel's expr object.
  61. This is so the RSel dev can feel free to significantly change his object storage structure if needed. */
  62. rselButtons: {
  63. lfParens: function() {
  64. try {
  65. document.getElementById('btnRSLBkt').click();
  66. } catch (err) {}
  67. },
  68. rtParens: function() {
  69. try {
  70. document.getElementById('btnRSRBkt').click();
  71. } catch (err) {}
  72. },
  73. and: function() {
  74. try {
  75. document.getElementById('btnRSAnd').click()
  76. } catch (err) {}
  77. },
  78. or: function() {
  79. try {
  80. document.getElementById('btnRSOr').click()
  81. } catch (err) {}
  82. },
  83. not: function() {
  84. try {
  85. document.getElementById('btnRSNot').click()
  86. } catch (err) {}
  87. },
  88. clear: function() {
  89. try {
  90. document.getElementById('btnRSClear').click()
  91. } catch (err) {}
  92. }
  93. },
  94. rselConditions: {
  95. country: {
  96. op: function(selText) {
  97. selText = '^' + selText + '$';
  98. document.getElementById('opRSCountry').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSCountry').options, selText);
  99. },
  100. val: function(selText) {
  101. selText = '^' + selText + '$';
  102. document.getElementById('selRSCountry').value = RSelExprParser._getSelectionIndex(document.getElementById('selRSCountry').options, selText);
  103. },
  104. add: function() {
  105. document.getElementById('btnRSAddCountry').click();
  106. }
  107. },
  108. state: {
  109. op: function(selText) {
  110. selText = '^' + selText + '$';
  111. document.getElementById('opRSState').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSState').options, selText);
  112. },
  113. val: function(val) {
  114. document.getElementById('inRSState').value = val;
  115. },
  116. add: function() {
  117. document.getElementById('btnRSAddState').click();
  118. }
  119. },
  120. city: {
  121. op: function(selText) {
  122. selText = '^' + selText + '$';
  123. document.getElementById('opRSCity').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSCity').options, selText);
  124. },
  125. val: function(val) {
  126. document.getElementById('inRSCity').value = val;
  127. },
  128. condmod: function(val) {
  129. document.getElementById('selRSAltCity').value = val;
  130. },
  131. add: function() {
  132. document.getElementById('btnRSAddCity').click();
  133. }
  134. },
  135. street: {
  136. op: function(selText) {
  137. selText = '^' + selText + '$';
  138. document.getElementById('opRSStreet').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSStreet').options, selText);
  139. },
  140. val: function(val) {
  141. document.getElementById('inRSStreet').value = val;
  142. },
  143. condmod: function(val) {
  144. document.getElementById('selRSAlttStreet').value = val;
  145. },
  146. add: function() {
  147. document.getElementById('btnRSAddStreet').click();
  148. }
  149. },
  150. unnamed: {
  151. op: function(checked) {
  152. document.getElementById('cbRSNoName').checked = checked;
  153. },
  154. //checked - has no name
  155. op2: function(checked) {
  156. document.getElementById('cbRSAltNoName').checked = checked;
  157. },
  158. //checked - alt name
  159. add: function() {
  160. document.getElementById('btnRSAddNoName').click();
  161. }
  162. },
  163. road: {
  164. op: function(selText) {
  165. selText = '^' + selText + '$';
  166. document.getElementById('opRSRoadType').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSRoadType').options, selText);
  167. },
  168. val: function(selText) {
  169. selText = '^' + selText.replace("/", "\/") + '$';
  170. document.getElementById('selRSRoadType').value = RSelExprParser._getSelectionIndex(document.getElementById('selRSRoadType').options, selText);
  171. },
  172. add: function() {
  173. document.getElementById('btnRSAddRoadType').click();
  174. }
  175. },
  176. direction: {
  177. op: function(selText) {
  178. selText = '^' + selText + '$';
  179. document.getElementById('opRSDirection').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSDirection').options, selText);
  180. },
  181. val: function(selText) {
  182. document.getElementById('selRSDirection').value = RSelExprParser._getSelectionIndex(document.getElementById('selRSDirection').options, selText);
  183. },
  184. add: function() {
  185. document.getElementById('btnRSAddDirection').click();
  186. }
  187. },
  188. elevation: {
  189. op: function(selText) {
  190. selText = '^' + selText + '$';
  191. document.getElementById('opRSElevation').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSElevation').options, selText);
  192. },
  193. val: function(selText) {
  194. selText = '^' + selText + '$';
  195. document.getElementById('selRSElevation').value = RSelExprParser._getSelectionIndex(document.getElementById('selRSElevation').options, selText);
  196. },
  197. add: function() {
  198. document.getElementById('btnRSAddElevation').click();
  199. }
  200. },
  201. manlock: {
  202. op: function(selText) {
  203. selText = '^' + selText + '$';
  204. document.getElementById('opRSManLock').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSManLock').options, selText);
  205. },
  206. val: function(val) {
  207. document.getElementById('selRSManLock').value = val;
  208. },
  209. add: function() {
  210. document.getElementById('btnRSAddManLock').click();
  211. }
  212. },
  213. traflock: {
  214. op: function(selText) {
  215. selText = '^' + selText + '$';
  216. document.getElementById('opRSTrLock').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSTrLock').options, selText);
  217. },
  218. val: function(val) {
  219. document.getElementById('selRSTrLock').value = val;
  220. },
  221. add: function() {
  222. document.getElementById('btnRSAddTrLock').click();
  223. }
  224. },
  225. speed: {
  226. opOptNodes: function() { return document.getElementById('opRSSpeed').options },
  227. op: function(selText) {
  228. selText = '^' + selText + '$';
  229. document.getElementById('opRSSpeed').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSSpeed').options, selText);
  230. },
  231. val: function(val) {
  232. document.getElementById('inRSSpeed').value = val;
  233. },
  234. add: function() {
  235. document.getElementById('btnRSAddSpeed').click();
  236. }
  237. },
  238. closure: {
  239. op: function(checked) {
  240. document.getElementById('cbRSClsr').checked = checked;
  241. },
  242. op2: function(selText) {
  243. selText = '^' + selText + '$';
  244. document.getElementById('opRSClsrStrtEnd').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSClsrStrtEnd').options, selText);
  245. },
  246. val: function(val) {
  247. document.getElementById('inRSClsrDays').value = val;
  248. },
  249. condmod: function(selText) {
  250. selText = '^' + selText + '$';
  251. document.getElementById('opRSClsrBeforeAter').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSClsrBeforeAter').options, selText);
  252. },
  253. add: function() {
  254. document.getElementById('btnRSAddClsr').click();
  255. }
  256. },
  257. routingpreference: {
  258. val: function(val) {
  259. document.getElementById('opRSRoutePrf').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSRoutePrf').options, selText);
  260. },
  261. add: function() {
  262. document.getElementById('btnRSAddRoutePrf').click();
  263. }
  264. },
  265. updatedby: {
  266. op: function(selText) {
  267. selText = '^' + selText + '$';
  268. document.getElementById('opRSUpdtd').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSUpdtd').options, selText);
  269. },
  270. val: function(val) {
  271. document.getElementById('inRSUpdtd').value = val;
  272. },
  273. add: function() {
  274. document.getElementById('btnRSAddUpdtd').click();
  275. }
  276. },
  277. createdby: {
  278. op: function(selText) {
  279. selText = '^' + selText + '$';
  280. document.getElementById('opRSCrtd').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSCrtd').options, selText);
  281. },
  282. val: function(val) {
  283. document.getElementById('inRSCrtd').value = val;
  284. },
  285. add: function() {
  286. document.getElementById('btnRSAddCrtd').click();
  287. }
  288. },
  289. last: {
  290. op: function(selText) {
  291. selText = '^' + selText + '$';
  292. document.getElementById('opRSLastU').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSLastU').options, selText);
  293. },
  294. val: function(val) {
  295. document.getElementById('inRSLastU').value = val;
  296. },
  297. add: function() {
  298. document.getElementById('btnRSAddLastU').click();
  299. }
  300. },
  301. length: {
  302. op: function(selText) {
  303. selText = '^' + selText + '$';
  304. document.getElementById('opRSLength').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSLength').options, selText);
  305. },
  306. val: function(val) {
  307. document.getElementById('inRSLength').value = val;
  308. },
  309. condmod: function(selText) {
  310. selText = '^' + selText + '$';
  311. document.getElementById('unitRSLength').value = RSelExprParser._getSelectionIndex(document.getElementById('unitRSLength').options, selText);
  312. },
  313. add: function() {
  314. document.getElementById('btnRSAddLength').click();
  315. }
  316. },
  317. id: {
  318. op: function(selText) {
  319. selText = '^' + selText + '$';
  320. document.getElementById('opRSSegId').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSSegId').options, selText);
  321. },
  322. val: function(val) {
  323. document.getElementById('inRSSegId').value = val;
  324. },
  325. add: function() {
  326. document.getElementById('btnRSAddSegId').click();
  327. }
  328. },
  329. roundabout: {
  330. op: function(checked) {
  331. document.getElementById('cbRSIsRound').checked = checked;
  332. },
  333. add: function() {
  334. document.getElementById('btnRSAddIsRound').click();
  335. }
  336. },
  337. toll: {
  338. op: function(checked) {
  339. document.getElementById('cbRSIsToll').checked = checked;
  340. },
  341. add: function() {
  342. document.getElementById('btnRSAddIsToll').click();
  343. }
  344. },
  345. tunnel: {
  346. op: function(checked) {
  347. document.getElementById('cbRSTunnel').checked = checked;
  348. },
  349. add: function() {
  350. document.getElementById('btnRSAddTunnel').click();
  351. }
  352. },
  353. unpaved: {
  354. op: function(checked) {
  355. document.getElementById('cbRSUnpaved').checked = checked;
  356. },
  357. add: function() {
  358. document.getElementById('btnRSAddUnpaved').click();
  359. }
  360. },
  361. hov: {
  362. op: function(checked) {
  363. document.getElementById('cbRSHOV').checked = checked;
  364. },
  365. add: function() {
  366. document.getElementById('btnRSAddHOV').click();
  367. }
  368. },
  369. headlights: {
  370. op: function(checked) {
  371. document.getElementById('cbRSHeadlights').checked = checked;
  372. },
  373. add: function() {
  374. document.getElementById('btnRSAddHeadlights').click();
  375. }
  376. },
  377. new: {
  378. op: function(checked) {
  379. document.getElementById('cbRSIsNew').checked = checked;
  380. },
  381. add: function() {
  382. document.getElementById('btnRSAddIsNew').click();
  383. }
  384. },
  385. changed: {
  386. op: function(checked) {
  387. document.getElementById('cbRSIsChngd').checked = checked;
  388. },
  389. add: function() {
  390. document.getElementById('btnRSAddIsChngd').click();
  391. }
  392. },
  393. screen: {
  394. op: function(checked) {
  395. document.getElementById('cbRSOnScr').checked = checked;
  396. },
  397. add: function() {
  398. document.getElementById('btnRSAddOnScr').click();
  399. }
  400. },
  401. restriction: {
  402. op: function(checked) {
  403. document.getElementById('cbRSRestr').checked = checked;
  404. },
  405. add: function() {
  406. document.getElementById('btnRSAddRestr').click();
  407. }
  408. },
  409. editable: {
  410. op: function(checked) {
  411. document.getElementById('cbRSEdtbl').checked = checked;
  412. },
  413. add: function() {
  414. document.getElementById('btnRSAddEdtbl').click();
  415. }
  416. }
  417. },
  418. addExpr: function(eb) {
  419. var checkKeys = false;
  420. Object.keys(this.rselConditions).map(function(a, i) {
  421. if (a === eb.cond)
  422. checkKeys = true;
  423. });
  424. if (checkKeys) {
  425. try {
  426. this.rselConditions[eb.cond].op(eb.op);
  427. if (eb.op2 !== null )
  428. this.rselConditions[eb.cond].op2(eb.op2);
  429. if (eb.condmod !== null )
  430. this.rselConditions[eb.cond].condmod(eb.condmod);
  431.  
  432. if (eb.val2 === null ) {
  433. if (eb.val !== null )
  434. this.rselConditions[eb.cond].val(eb.val);
  435. this.rselConditions[eb.cond].add();
  436. } else {
  437. this.rselButtons.lfParens();
  438. this.rselConditions[eb.cond].val(eb.val);
  439. this.rselConditions[eb.cond].add();
  440. this.rselButtons.or();
  441. this.rselConditions[eb.cond].val(eb.val2);
  442. this.rselConditions[eb.cond].add();
  443. this.rselButtons.rtParens();
  444. }
  445.  
  446. } catch (err) {
  447. return {
  448. errorCode: 101,
  449. errorMsg: 'Error: Unable to parse expression text.',
  450. err: err
  451. };
  452. }
  453. } else {
  454. return {
  455. errorCode: 3,
  456. errorMsg: 'Selection condition was not recognized'
  457. };
  458. //
  459. }
  460. return {
  461. errorCode: 0
  462. };
  463. },
  464. //=============================================================================
  465. parseExpr: function(parseThis) {
  466. //---------------------------------------------------------------
  467. parseThis = parseThis.replace(/\bpri?m?(?:ary|\.)?\s?(?:or)\s?alt(?:ern|s)?(?:\.)?/ig, 'any');
  468. parseThis = parseThis.replace(/\b((?:un)?name[ds]?)\b|\b(road) type\b|\b(last) update\b|\b(speed) limits?\b/ig, '$1$2$3$4')
  469. parseThis = parseThis.replace(/\b(man)ual (lock)s?\b|\b(traf)[fic]* (lock)s?\b/ig, '$1$2$3$4');
  470. parseThis = parseThis.replace(/\b(created|updated)\s(by)\b/ig, '$1$2');
  471. parseThis = parseThis.replace(/\b(routing)\s(preference)\b/ig, '$1$2');
  472. parseThis = parseThis.replace(/\bon screen/ig, 'onscreen');
  473. //\b(?:in|on|off|out|outside)(?: of)?[- ]?screen\b
  474. parseThis = parseThis.replace(/\b(?:off|out)(?: of)?[- ]?screen/ig, 'offscreen');
  475.  
  476. var parseExprArray = parseThis.match(
  477. /(\(['"].*?['"]\)|".*?"|'.*?'|\/.+?\/)|\bno[\s-]alt|\b(?:street[\s-]?)?name\(s\)|\bstreet(?:\snames?)\b|\btoll(?:[-\s]?ro?a?d)?\b|\bdoes(?:\s?n[o']t)\b|(?:!\s?)?contains?\b|\w+n't\b|!=|>=|<=|([ab](<-|->)[ab])|&&|\|\||!=|[|&<>=()!~]|[\u0023-\u0027\u002A-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]+/gim),
  478. parseExprHistory = [],
  479. condMatches = [],
  480. condMatchPhrases = [],
  481. exprMatches = [],
  482. exprMatchPhrases = [],
  483. exprFragment, unwantedWordsSearch,
  484. e, f, b, fLength;
  485.  
  486. // The following parses the expression text into unique chunks within separate array elements
  487. e = parseExprArray.length;
  488. while (e-- > 0) {
  489. try {
  490. exprFragment = parseExprArray.shift();
  491. //console.info(exprFragment);
  492.  
  493. // Find operators that join individual expressions (AND|OR|!|parenthesis)
  494. if (/^(?:and|or|&&|\|\||!=|[=&|()!])$/i.test(exprFragment)) {
  495. exprMatches.push(exprFragment.toLowerCase());
  496. exprMatchPhrases.push(exprFragment.toLowerCase());
  497. }
  498.  
  499. // Identify elements that contain selection condition names
  500. if (
  501. /^country|^state|^city|^street|^(?:un|street[\s-]?)?name|^road|^round|^toll|^speed|^dir|^elevation|^tun|^unpaved|^carpool|^headlights|^manlock|^traflock|^speed|^new|^changed|screen$|^restrict|^clos|^createdby|^last|^updatedby|^length|^routingpreference|^id|^editable/i
  502. .test(exprFragment)) {
  503. condMatches.push(exprFragment.toLowerCase());
  504. // lists specific selection conditions
  505. exprMatches.push(exprFragment.toLowerCase());
  506. //same as condMatches, but includes operations as separate array elements
  507.  
  508. try {
  509. //search phrase fowards
  510. fLength = parseExprArray.length;
  511. f = 0;
  512. while (!(/^(and|or|&&|\|\||[&|)])$/i.test(parseExprArray[f])) && (++f < fLength)) {}
  513. //search phrase backwards
  514. b = parseExprHistory.length;
  515. while (!(/^(and|or|&&|\|\||[&|(])$/i.test(parseExprHistory[b - 1])) && (--b > 0)) {}
  516.  
  517. condMatchPhrases.push(parseExprHistory.slice(b).concat(exprFragment, parseExprArray.slice(0, f)));
  518. //list specific selection conditions and its criteria
  519.  
  520. unwantedWordsSearch = parseExprHistory.slice(b);
  521. if (unwantedWordsSearch && unwantedWordsSearch.length) {
  522. unwantedWordsSearch = unwantedWordsSearch.filter(function(a) {
  523. return !/\b(has|have|is|=|are|does|was|were)\b/i.test(a)
  524. });
  525. }
  526. if (/!|!=/.test(unwantedWordsSearch[0]))
  527. unwantedWordsSearch.splice(0, 1);
  528.  
  529. exprMatchPhrases.push(unwantedWordsSearch.concat(parseExprArray.slice(0, f)));
  530. //excludes the match cond
  531.  
  532. parseExprHistory = parseExprHistory.concat(exprFragment, parseExprArray.slice(0, f));
  533. parseExprArray = parseExprArray.slice(f);
  534. e -= f;
  535. } catch (err) {
  536. return {
  537. errorCode: 101,
  538. errorMsg: 'Error parsing expression at ' + exprFragment,
  539. err: err
  540. };
  541. }
  542. } else {
  543. parseExprHistory.push(exprFragment);
  544. }
  545. } catch (err) {
  546. return {
  547. errorCode: 101,
  548. errdebug: 'Error parsing expression at ' + exprFragment,
  549. err: err
  550. };
  551. }
  552. }
  553. //while
  554.  
  555.  
  556. //---------------------------------------------------------------
  557. // Quick crude check for unmatched parentheses
  558. var nOpenParens = exprMatches.toString().match(/\(/g),
  559. nCloseParens = exprMatches.toString().match(/\)/g);
  560. if (!nOpenParens) nOpenParens = [];
  561. if (!nCloseParens) nCloseParens = [];
  562. if (nOpenParens.length !== nCloseParens.length)
  563. return {
  564. errorCode: 1,
  565. errorMsg: 'Warning: Open and close paretheses may be unmatched.'
  566. };
  567.  
  568. //---------------------------------------------------------------
  569.  
  570. return {
  571. errorCode: 0,
  572. exprMatches: exprMatches,
  573. exprMatchPhrases: exprMatchPhrases,
  574. condMatches: condMatches,
  575. condMatchPhrases: condMatchPhrases
  576. };
  577. },
  578. buildExpr: function(exprWord, exprPhrase) {
  579.  
  580. var exprBuild = RSelExprParser._getNewExprBuild();
  581. exprBuild.cond = exprWord;
  582.  
  583. //if (m===10) debugger;
  584.  
  585. //============================================================
  586. // Where the magic happens... sort of.
  587. //============================================================
  588. switch (true) {
  589. case exprWord === '(':
  590. this.rselButtons.lfParens();
  591. return false;
  592. case exprWord === ')':
  593. this.rselButtons.rtParens();
  594. return false;
  595. case 'and' === exprWord:
  596. this.rselButtons.and();
  597. return false;
  598. case 'or' === exprWord:
  599. this.rselButtons.or();
  600. return false;
  601. case /no alt/i.test(exprPhrase):
  602. exprBuild.cond = 'unnamed';
  603. exprBuild.op = true;
  604. exprBuild.op2 = true;
  605. return exprBuild;
  606. case '!' === exprWord:
  607. this.rselButtons.not();
  608. return false;
  609. case /^unnamed/.test(exprBuild.cond):
  610. exprBuild.cond = 'unnamed';
  611. exprBuild.op = true;
  612. exprBuild.op2 = false;
  613. return exprBuild;
  614.  
  615. // SPEED LIMITS
  616. case 'speed' === exprBuild.cond:
  617. try {
  618. if (exprPhrase.length < 2 && /\bnot?\b|!|!=/i.test(exprPhrase[0])) {
  619. exprBuild.op = 'none';
  620. } else {
  621. exprPhrase = exprPhrase.join(' ');
  622.  
  623. if (/\bnot?\b|!|!=/i.test(exprPhrase)) {
  624. RSelExprParser.rselButtons.not();
  625. }
  626.  
  627. var optionText = RSelExprParser._getSelectOptions(RSelExprParser.rselConditions.speed.opOptNodes());
  628. optionText = RegExp(optionText.join('|'), 'i').exec(exprPhrase);
  629. if (optionText) exprBuild.op = optionText[0];
  630. else exprBuild.op = 'any';
  631. }
  632.  
  633. if (exprPhrase.length > 1) {
  634. exprBuild.val = exprPhrase.replace(/.*?(\d+)\s?mph.*|.*?(\d+)\s?km.*/i,'$1$2');
  635. } else {
  636. exprBuild.val = '';
  637. }
  638. } catch (err) {
  639. exprBuild.errorCode = 101;
  640. exprBuild.err = err;
  641. return exprBuild;
  642. }
  643. return exprBuild;
  644.  
  645. // BINARY CONDITIONS:
  646. case exprPhrase.length === 0 || //suggests binary
  647. /^(screen|roundabout|toll|tun|unpaved|carpool|headlights|new|changed|restrict|editable)/.test(exprBuild.cond) || //binary selection conditions
  648. (/^name.*|^closure/i.test(exprBuild.cond) && exprPhrase.length <= 1):
  649. //selection conditions that have both binary and multiple options
  650.  
  651. exprPhrase = exprPhrase.join(' ');
  652.  
  653. exprBuild.cond = exprBuild.cond.replace(/^name.*/, 'name');
  654. exprBuild.cond = exprBuild.cond.replace(/^toll\s.*/, 'toll');
  655.  
  656. if (/\bnot?\b|!|!=/i.test(exprPhrase)) {
  657. exprBuild.op = false;
  658. } else {
  659. exprBuild.op = true;
  660. }
  661. switch (exprBuild.cond) {
  662. case 'name':
  663. try {
  664. if (/alt/i.test(exprPhrase)) {
  665. exprBuild.cond = 'unnamed';
  666. exprBuild.op = false;
  667. exprBuild.op2 = true;
  668. } else {
  669. exprBuild.cond = 'unnamed';
  670. exprBuild.op = false;
  671. exprBuild.op2 = false;
  672. }
  673. return exprBuild;
  674. } catch (err) {
  675. exprBuild.errorCode = 101;
  676. exprBuild.err = err;
  677. return exprBuild;
  678. }
  679. case 'closure':
  680. exprBuild.op2 = '---';
  681. exprBuild.val = '';
  682. return exprBuild;
  683. case 'onscreen':
  684. exprBuild.cond = 'screen';
  685. exprBuild.op = true;
  686. return exprBuild;
  687. case 'offscreen':
  688. exprBuild.cond = 'screen';
  689. exprBuild.op = false;
  690. return exprBuild;
  691. case 'roundabout':
  692. case 'toll':
  693. case 'tunnel':
  694. case 'unpaved':
  695. case 'headlights':
  696. case 'new':
  697. case 'changed':
  698. case 'restriction':
  699. case 'editable':
  700. return exprBuild;
  701. case 'carpool/hov/bus':
  702. exprBuild.cond = "hov";
  703. return exprBuild;
  704. default:
  705. exprBuild.errorCode = 101;
  706. exprBuild.errorMsg = 'Error: Presumed binary selector had no match.';
  707. return exprBuild;
  708. }
  709. //switch
  710.  
  711. //--------------------------------------------------------------------
  712.  
  713. case /^closure/.test(exprBuild.cond):
  714. try {
  715. exprPhrase = exprPhrase.join().toLowerCase();
  716. exprBuild.op = !(/does\s?n['o]t|!|!=/.test(exprPhrase));
  717. //checkbox
  718. exprBuild.op2 = /start|end/.exec(exprPhrase) + 's';
  719. //starts/ends
  720. exprBuild.condmod = /before|after|\bin\b/.exec(exprPhrase) + '';
  721. //in/before/after
  722. if (!exprBuild.condmod)
  723. exprBuild.condmod = 'in';
  724. exprBuild.val = /\d+/.exec(exprPhrase) + '';
  725. //days ago
  726. } catch (err) {
  727. exprBuild.errorCode = 101;
  728. exprBuild.err = err;
  729. return exprBuild;
  730. }
  731. return exprBuild;
  732.  
  733. default:
  734. // CONDITION NAME MATCHING (TYPE OF SELECTION)
  735. try {
  736. if (/^(str.*|cit.*)/.test(exprBuild.cond)) {
  737. exprBuild.cond = exprBuild.cond.replace(/^str.*/, 'street');
  738. exprBuild.cond = exprBuild.cond.replace(/^cit.*/, 'city');
  739. var exprStart = exprPhrase.slice(0, -1), //don't include last element bc it should be the name itself
  740. prim, alt;
  741. if (exprStart) {
  742. //exprStart = exprStart.toString().toLowerCase();
  743. prim = /\bprim?(?:ary|\.)?\b/i.test(exprStart);
  744. alt = /\balt(?:ern\w*|\.)?\b/i.test(exprStart);
  745. any = /\bany\b/i.test(exprStart);
  746. exprPhrase = exprStart.filter(function(a) {return !/^pr|^alt|^any/i.test(a)}).concat(exprPhrase.slice(-1));
  747. } else {
  748. prim = false;
  749. alt = false;
  750. }
  751. if ((prim && alt) || any)
  752. exprBuild.condmod = 2;
  753. else if (prim)
  754. exprBuild.condmod = 0;
  755. else if (alt)
  756. exprBuild.condmod = 1;
  757. else
  758. exprBuild.condmod = 0;
  759. }
  760. } catch (err) {
  761. exprBuild.errorCode = 101;
  762. exprBuild.err = err;
  763. return exprBuild;
  764. }
  765.  
  766. // COMPARATOR OPERATION MATCHING
  767. try {
  768. // Convert to standard comparator operations
  769. var exprPhraseStr = exprPhrase.join(' ').replace(/\bcontains?/i, 'contains').replace(/(?:\bdo(?:es)?\s?n[o']t\s|!\s?)(contains)/i, '! $1');
  770. //.replace(/\b(?:do(?:es)?\s?n[o']t\s|!\s?)contains?/i, '!^').replace(/\bcontains?/i,'\u220b');
  771.  
  772. // Comparator operations with standard representation
  773. exprBuild.op = /(?:! )?contains|[!<>=~]{1,2}/i.exec(exprPhraseStr) + '';
  774.  
  775. } catch (err) {
  776. exprBuild.errorCode = 101;
  777. exprBuild.err = err;
  778. return exprBuild;
  779. }
  780.  
  781. // SELECTION VALUE MATCHING
  782. if (/^length|^last/.test(exprBuild.cond)) {
  783. exprBuild.val = exprPhraseStr.match(/\b\d+/) + '';
  784. } else {
  785. try {
  786. var blackmagic = '[\u0023-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]+',
  787. whitemagic = '^\\(["\'](.*?)[\'"]\\)$|^\\s?["\'](.*)["\']$|^["\'](.*)[\'"]$|\\b(';
  788.  
  789. // The following line is kind of elaborate bc it needed to grab text between parens/quotes while keeping the inner quotes
  790. exprBuild.val = exprPhraseStr.replace(new RegExp('^(?:\\s?' + exprBuild.op + '\\s)(.*)','i'),'$1').replace(new RegExp(whitemagic + blackmagic + '?)\\b','ig'),'$1$2$3$4').replace(new RegExp('(") (' + blackmagic + ') (")','ig'),'$1$2$3');
  791.  
  792. if (!/^street|^city/.test(exprBuild.cond)) {
  793. exprBuild.val = exprBuild.val.replace(/"(.*)"|'(.*)'/, '$1$2');
  794. }
  795. } catch (err) {
  796. exprBuild.errorCode = 2;
  797. exprBuild.err = err;
  798. return exprBuild;
  799. }
  800.  
  801. if (/^direction/.test(exprBuild.cond)) {
  802. exprBuild.val = exprBuild.val.match(/A[<>‹›-\s]*B|B[<>‹›-\s]*A|^"?one[\s-]?ways?"?$|unknown|\btwo/i)+''; //reduce to unique key words... last option will automatically input both one ways
  803. //reduce to unique key words...
  804. }
  805. }
  806.  
  807. return exprBuild;
  808. }
  809. //switch
  810. },
  811. //parseExpr()
  812. updateExpression: function(parseThis) {
  813. this.rselButtons.clear();
  814. if (parseThis) {
  815. //console.info('*** Begin parsing expression... ***');
  816.  
  817.  
  818. var parsed = this.parseExpr(parseThis);
  819.  
  820. if (parsed && !parsed.errorCode) {
  821. var exprMatches = parsed.exprMatches,
  822. exprMatchPhrases = parsed.exprMatchPhrases,
  823. exprFragment, exprFragPhrase, mLength, m;
  824.  
  825. mLength = exprMatchPhrases.length;
  826. for (m = 0; m < mLength; m++) {
  827. RSelExprParser.__EXPR_DEBUGINFO = this.new__EXPR_DEBUGINFO(m, exprMatches[m], exprMatchPhrases[m]);
  828.  
  829. //if (m > 3) debugger;
  830.  
  831. exprFragment = exprMatches[m];
  832. exprFragPhrase = exprMatchPhrases[m];
  833.  
  834. if (exprFragPhrase.constructor !== Array) exprFragPhrase = [exprFragPhrase];
  835.  
  836. var exprBuild = this.buildExpr(exprFragment, exprFragPhrase);
  837.  
  838. if (exprBuild && !exprBuild.errorCode) {
  839. RSelExprParser.__EXPR_DEBUGINFO.errorStatus = this.addExpr(exprBuild);
  840.  
  841. if (RSelExprParser.__EXPR_DEBUGINFO.errorStatus && RSelExprParser.__EXPR_DEBUGINFO.errorStatus.errorCode) {
  842. console.warn('updateExpression() may have partly failed. Check results.');
  843. RSelExprParser.__EXPR_DEBUGINFO.exprBuild = exprBuild;
  844. console.debug(RSelExprParser.__EXPR_DEBUGINFO);
  845. return false;
  846. }
  847. } else if (exprBuild && exprBuild.errorCode) {
  848. console.warn('updateExpression() may have partly failed. Check results.');
  849. RSelExprParser.__EXPR_DEBUGINFO.exprBuild = exprBuild;
  850. console.debug(RSelExprParser.__EXPR_DEBUGINFO);
  851. return false;
  852. }
  853. } //for each condition matched
  854.  
  855. return this.getCurrentExprText();
  856. } else {
  857. console.debug(parsed);
  858. return false;
  859. }
  860. } else {
  861. return null;
  862. }
  863. }
  864. };