rsel-exprparser-basic

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

Този скрипт не може да бъде инсталиран директно. Това е библиотека за други скриптове и може да бъде използвана с мета-директива // @require https://update.greatest.deepsurf.us/scripts/17641/1367967/rsel-exprparser-basic.js

  1. // ==UserScript==
  2. // @name rsel-exprparser-basic
  3. // @namespace https://greatest.deepsurf.us/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. op: function(selText) {
  259. },
  260. val: function(val) {
  261. document.getElementById('opRSRoutePrf').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSRoutePrf').options, val);
  262. },
  263. add: function() {
  264. document.getElementById('btnRSAddRoutePrf').click();
  265. }
  266. },
  267. updatedby: {
  268. op: function(selText) {
  269. selText = '^' + selText + '$';
  270. document.getElementById('opRSUpdtd').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSUpdtd').options, selText);
  271. },
  272. val: function(val) {
  273. document.getElementById('inRSUpdtd').value = val;
  274. },
  275. add: function() {
  276. document.getElementById('btnRSAddUpdtd').click();
  277. }
  278. },
  279. createdby: {
  280. op: function(selText) {
  281. selText = '^' + selText + '$';
  282. document.getElementById('opRSCrtd').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSCrtd').options, selText);
  283. },
  284. val: function(val) {
  285. document.getElementById('inRSCrtd').value = val;
  286. },
  287. add: function() {
  288. document.getElementById('btnRSAddCrtd').click();
  289. }
  290. },
  291. last: {
  292. op: function(selText) {
  293. selText = '^' + selText + '$';
  294. document.getElementById('opRSLastU').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSLastU').options, selText);
  295. },
  296. val: function(val) {
  297. document.getElementById('inRSLastU').value = val;
  298. },
  299. add: function() {
  300. document.getElementById('btnRSAddLastU').click();
  301. }
  302. },
  303. length: {
  304. op: function(selText) {
  305. selText = '^' + selText + '$';
  306. document.getElementById('opRSLength').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSLength').options, selText);
  307. },
  308. val: function(val) {
  309. document.getElementById('inRSLength').value = val;
  310. },
  311. condmod: function(selText) {
  312. selText = '^' + selText + '$';
  313. document.getElementById('unitRSLength').value = RSelExprParser._getSelectionIndex(document.getElementById('unitRSLength').options, selText);
  314. },
  315. add: function() {
  316. document.getElementById('btnRSAddLength').click();
  317. }
  318. },
  319. id: {
  320. op: function(selText) {
  321. selText = '^' + selText + '$';
  322. document.getElementById('opRSSegId').value = RSelExprParser._getSelectionIndex(document.getElementById('opRSSegId').options, selText);
  323. },
  324. val: function(val) {
  325. document.getElementById('inRSSegId').value = val;
  326. },
  327. add: function() {
  328. document.getElementById('btnRSAddSegId').click();
  329. }
  330. },
  331. roundabout: {
  332. op: function(checked) {
  333. document.getElementById('cbRSIsRound').checked = checked;
  334. },
  335. add: function() {
  336. document.getElementById('btnRSAddIsRound').click();
  337. }
  338. },
  339. toll: {
  340. op: function(checked) {
  341. document.getElementById('cbRSIsToll').checked = checked;
  342. },
  343. add: function() {
  344. document.getElementById('btnRSAddIsToll').click();
  345. }
  346. },
  347. tunnel: {
  348. op: function(checked) {
  349. document.getElementById('cbRSTunnel').checked = checked;
  350. },
  351. add: function() {
  352. document.getElementById('btnRSAddTunnel').click();
  353. }
  354. },
  355. unpaved: {
  356. op: function(checked) {
  357. document.getElementById('cbRSUnpaved').checked = checked;
  358. },
  359. add: function() {
  360. document.getElementById('btnRSAddUnpaved').click();
  361. }
  362. },
  363. hov: {
  364. op: function(checked) {
  365. document.getElementById('cbRSHOV').checked = checked;
  366. },
  367. add: function() {
  368. document.getElementById('btnRSAddHOV').click();
  369. }
  370. },
  371. headlights: {
  372. op: function(checked) {
  373. document.getElementById('cbRSHeadlights').checked = checked;
  374. },
  375. add: function() {
  376. document.getElementById('btnRSAddHeadlights').click();
  377. }
  378. },
  379. new: {
  380. op: function(checked) {
  381. document.getElementById('cbRSIsNew').checked = checked;
  382. },
  383. add: function() {
  384. document.getElementById('btnRSAddIsNew').click();
  385. }
  386. },
  387. changed: {
  388. op: function(checked) {
  389. document.getElementById('cbRSIsChngd').checked = checked;
  390. },
  391. add: function() {
  392. document.getElementById('btnRSAddIsChngd').click();
  393. }
  394. },
  395. screen: {
  396. op: function(checked) {
  397. document.getElementById('cbRSOnScr').checked = checked;
  398. },
  399. add: function() {
  400. document.getElementById('btnRSAddOnScr').click();
  401. }
  402. },
  403. restriction: {
  404. op: function(checked) {
  405. document.getElementById('cbRSRestr').checked = checked;
  406. },
  407. add: function() {
  408. document.getElementById('btnRSAddRestr').click();
  409. }
  410. },
  411. editable: {
  412. op: function(checked) {
  413. document.getElementById('cbRSEdtbl').checked = checked;
  414. },
  415. add: function() {
  416. document.getElementById('btnRSAddEdtbl').click();
  417. }
  418. }
  419. },
  420. addExpr: function(eb) {
  421. var checkKeys = false;
  422. Object.keys(this.rselConditions).map(function(a, i) {
  423. if (a === eb.cond)
  424. checkKeys = true;
  425. });
  426. if (checkKeys) {
  427. try {
  428. this.rselConditions[eb.cond].op(eb.op);
  429. if (eb.op2 !== null )
  430. this.rselConditions[eb.cond].op2(eb.op2);
  431. if (eb.condmod !== null )
  432. this.rselConditions[eb.cond].condmod(eb.condmod);
  433.  
  434. if (eb.val2 === null ) {
  435. if (eb.val !== null )
  436. this.rselConditions[eb.cond].val(eb.val);
  437. this.rselConditions[eb.cond].add();
  438. } else {
  439. this.rselButtons.lfParens();
  440. this.rselConditions[eb.cond].val(eb.val);
  441. this.rselConditions[eb.cond].add();
  442. this.rselButtons.or();
  443. this.rselConditions[eb.cond].val(eb.val2);
  444. this.rselConditions[eb.cond].add();
  445. this.rselButtons.rtParens();
  446. }
  447.  
  448. } catch (err) {
  449. return {
  450. errorCode: 101,
  451. errorMsg: 'Error: Unable to parse expression text.',
  452. err: err
  453. };
  454. }
  455. } else {
  456. return {
  457. errorCode: 3,
  458. errorMsg: 'Selection condition was not recognized'
  459. };
  460. //
  461. }
  462. return {
  463. errorCode: 0
  464. };
  465. },
  466. //=============================================================================
  467. parseExpr: function(parseThis) {
  468. //---------------------------------------------------------------
  469. parseThis = parseThis.replace(/\bpri?m?(?:ary|\.)?\s?(?:or)\s?alt(?:ern|s)?(?:\.)?/ig, 'any');
  470. 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')
  471. parseThis = parseThis.replace(/\b(man)ual (lock)s?\b|\b(traf)[fic]* (lock)s?\b/ig, '$1$2$3$4');
  472. parseThis = parseThis.replace(/\b(created|updated)\s(by)\b/ig, '$1$2');
  473. parseThis = parseThis.replace(/\b(routing)\s(preference)\b/ig, '$1$2');
  474. parseThis = parseThis.replace(/\bon screen/ig, 'onscreen');
  475. //\b(?:in|on|off|out|outside)(?: of)?[- ]?screen\b
  476. parseThis = parseThis.replace(/\b(?:off|out)(?: of)?[- ]?screen/ig, 'offscreen');
  477.  
  478. var parseExprArray = parseThis.match(
  479. /(\(['"].*?['"]\)|".*?"|'.*?'|\/.+?\/)|\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),
  480. parseExprHistory = [],
  481. condMatches = [],
  482. condMatchPhrases = [],
  483. exprMatches = [],
  484. exprMatchPhrases = [],
  485. exprFragment, unwantedWordsSearch,
  486. e, f, b, fLength;
  487.  
  488. // The following parses the expression text into unique chunks within separate array elements
  489. e = parseExprArray.length;
  490. while (e-- > 0) {
  491. try {
  492. exprFragment = parseExprArray.shift();
  493. //console.info(exprFragment);
  494.  
  495. // Find operators that join individual expressions (AND|OR|!|parenthesis)
  496. if (/^(?:and|or|&&|\|\||!=|[=&|()!])$/i.test(exprFragment)) {
  497. exprMatches.push(exprFragment.toLowerCase());
  498. exprMatchPhrases.push(exprFragment.toLowerCase());
  499. }
  500.  
  501. // Identify elements that contain selection condition names
  502. if (
  503. /^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
  504. .test(exprFragment)) {
  505. condMatches.push(exprFragment.toLowerCase());
  506. // lists specific selection conditions
  507. exprMatches.push(exprFragment.toLowerCase());
  508. //same as condMatches, but includes operations as separate array elements
  509.  
  510. try {
  511. //search phrase fowards
  512. fLength = parseExprArray.length;
  513. f = 0;
  514. while (!(/^(and|or|&&|\|\||[&|)])$/i.test(parseExprArray[f])) && (++f < fLength)) {}
  515. //search phrase backwards
  516. b = parseExprHistory.length;
  517. while (!(/^(and|or|&&|\|\||[&|(])$/i.test(parseExprHistory[b - 1])) && (--b > 0)) {}
  518.  
  519. condMatchPhrases.push(parseExprHistory.slice(b).concat(exprFragment, parseExprArray.slice(0, f)));
  520. //list specific selection conditions and its criteria
  521.  
  522. unwantedWordsSearch = parseExprHistory.slice(b);
  523. if (unwantedWordsSearch && unwantedWordsSearch.length) {
  524. unwantedWordsSearch = unwantedWordsSearch.filter(function(a) {
  525. return !/\b(has|have|is|=|are|does|was|were)\b/i.test(a)
  526. });
  527. }
  528. if (/!|!=/.test(unwantedWordsSearch[0]))
  529. unwantedWordsSearch.splice(0, 1);
  530.  
  531. exprMatchPhrases.push(unwantedWordsSearch.concat(parseExprArray.slice(0, f)));
  532. //excludes the match cond
  533.  
  534. parseExprHistory = parseExprHistory.concat(exprFragment, parseExprArray.slice(0, f));
  535. parseExprArray = parseExprArray.slice(f);
  536. e -= f;
  537. } catch (err) {
  538. return {
  539. errorCode: 101,
  540. errorMsg: 'Error parsing expression at ' + exprFragment,
  541. err: err
  542. };
  543. }
  544. } else {
  545. parseExprHistory.push(exprFragment);
  546. }
  547. } catch (err) {
  548. return {
  549. errorCode: 101,
  550. errdebug: 'Error parsing expression at ' + exprFragment,
  551. err: err
  552. };
  553. }
  554. }
  555. //while
  556.  
  557.  
  558. //---------------------------------------------------------------
  559. // Quick crude check for unmatched parentheses
  560. var nOpenParens = exprMatches.toString().match(/\(/g),
  561. nCloseParens = exprMatches.toString().match(/\)/g);
  562. if (!nOpenParens) nOpenParens = [];
  563. if (!nCloseParens) nCloseParens = [];
  564. if (nOpenParens.length !== nCloseParens.length)
  565. return {
  566. errorCode: 1,
  567. errorMsg: 'Warning: Open and close paretheses may be unmatched.'
  568. };
  569.  
  570. //---------------------------------------------------------------
  571.  
  572. return {
  573. errorCode: 0,
  574. exprMatches: exprMatches,
  575. exprMatchPhrases: exprMatchPhrases,
  576. condMatches: condMatches,
  577. condMatchPhrases: condMatchPhrases
  578. };
  579. },
  580. buildExpr: function(exprWord, exprPhrase) {
  581.  
  582. var exprBuild = RSelExprParser._getNewExprBuild();
  583. exprBuild.cond = exprWord;
  584.  
  585. //if (m===10) debugger;
  586.  
  587. //============================================================
  588. // Where the magic happens... sort of.
  589. //============================================================
  590. switch (true) {
  591. case exprWord === '(':
  592. this.rselButtons.lfParens();
  593. return false;
  594. case exprWord === ')':
  595. this.rselButtons.rtParens();
  596. return false;
  597. case 'and' === exprWord:
  598. this.rselButtons.and();
  599. return false;
  600. case 'or' === exprWord:
  601. this.rselButtons.or();
  602. return false;
  603. case /no alt/i.test(exprPhrase):
  604. exprBuild.cond = 'unnamed';
  605. exprBuild.op = true;
  606. exprBuild.op2 = true;
  607. return exprBuild;
  608. case '!' === exprWord:
  609. this.rselButtons.not();
  610. return false;
  611. case /^unnamed/.test(exprBuild.cond):
  612. exprBuild.cond = 'unnamed';
  613. exprBuild.op = true;
  614. exprBuild.op2 = false;
  615. return exprBuild;
  616.  
  617. // SPEED LIMITS
  618. case 'speed' === exprBuild.cond:
  619. try {
  620. if (exprPhrase.length < 2 && /\bnot?\b|!|!=/i.test(exprPhrase[0])) {
  621. exprBuild.op = 'none';
  622. } else {
  623. exprPhrase = exprPhrase.join(' ');
  624.  
  625. if (/\bnot?\b|!|!=/i.test(exprPhrase)) {
  626. RSelExprParser.rselButtons.not();
  627. }
  628.  
  629. var optionText = RSelExprParser._getSelectOptions(RSelExprParser.rselConditions.speed.opOptNodes());
  630. optionText = RegExp(optionText.join('|'), 'i').exec(exprPhrase);
  631. if (optionText) exprBuild.op = optionText[0];
  632. else exprBuild.op = 'any';
  633. }
  634.  
  635. if (exprPhrase.length > 1) {
  636. exprBuild.val = exprPhrase.replace(/.*?(\d+)\s?mph.*|.*?(\d+)\s?km.*/i,'$1$2');
  637. } else {
  638. exprBuild.val = '';
  639. }
  640. } catch (err) {
  641. exprBuild.errorCode = 101;
  642. exprBuild.err = err;
  643. return exprBuild;
  644. }
  645. return exprBuild;
  646.  
  647. // BINARY CONDITIONS:
  648. case exprPhrase.length === 0 || //suggests binary
  649. /^(screen|roundabout|toll|tun|unpaved|carpool|headlights|new|changed|restrict|editable)/.test(exprBuild.cond) || //binary selection conditions
  650. (/^name.*|^closure/i.test(exprBuild.cond) && exprPhrase.length <= 1):
  651. //selection conditions that have both binary and multiple options
  652.  
  653. exprPhrase = exprPhrase.join(' ');
  654.  
  655. exprBuild.cond = exprBuild.cond.replace(/^name.*/, 'name');
  656. exprBuild.cond = exprBuild.cond.replace(/^toll\s.*/, 'toll');
  657.  
  658. if (/\bnot?\b|!|!=/i.test(exprPhrase)) {
  659. exprBuild.op = false;
  660. } else {
  661. exprBuild.op = true;
  662. }
  663. switch (exprBuild.cond) {
  664. case 'name':
  665. try {
  666. if (/alt/i.test(exprPhrase)) {
  667. exprBuild.cond = 'unnamed';
  668. exprBuild.op = false;
  669. exprBuild.op2 = true;
  670. } else {
  671. exprBuild.cond = 'unnamed';
  672. exprBuild.op = false;
  673. exprBuild.op2 = false;
  674. }
  675. return exprBuild;
  676. } catch (err) {
  677. exprBuild.errorCode = 101;
  678. exprBuild.err = err;
  679. return exprBuild;
  680. }
  681. case 'closure':
  682. exprBuild.op2 = '---';
  683. exprBuild.val = '';
  684. return exprBuild;
  685. case 'onscreen':
  686. exprBuild.cond = 'screen';
  687. exprBuild.op = true;
  688. return exprBuild;
  689. case 'offscreen':
  690. exprBuild.cond = 'screen';
  691. exprBuild.op = false;
  692. return exprBuild;
  693. case 'roundabout':
  694. case 'toll':
  695. case 'tunnel':
  696. case 'unpaved':
  697. case 'headlights':
  698. case 'new':
  699. case 'changed':
  700. case 'restriction':
  701. case 'editable':
  702. return exprBuild;
  703. case 'carpool/hov/bus':
  704. exprBuild.cond = "hov";
  705. return exprBuild;
  706. default:
  707. exprBuild.errorCode = 101;
  708. exprBuild.errorMsg = 'Error: Presumed binary selector had no match.';
  709. return exprBuild;
  710. }
  711. //switch
  712.  
  713. //--------------------------------------------------------------------
  714.  
  715. case /^closure/.test(exprBuild.cond):
  716. try {
  717. exprPhrase = exprPhrase.join().toLowerCase();
  718. exprBuild.op = !(/does\s?n['o]t|!|!=/.test(exprPhrase));
  719. //checkbox
  720. exprBuild.op2 = /start|end/.exec(exprPhrase) + 's';
  721. //starts/ends
  722. exprBuild.condmod = /before|after|\bin\b/.exec(exprPhrase) + '';
  723. //in/before/after
  724. if (!exprBuild.condmod)
  725. exprBuild.condmod = 'in';
  726. exprBuild.val = /\d+/.exec(exprPhrase) + '';
  727. //days ago
  728. } catch (err) {
  729. exprBuild.errorCode = 101;
  730. exprBuild.err = err;
  731. return exprBuild;
  732. }
  733. return exprBuild;
  734.  
  735. default:
  736. // CONDITION NAME MATCHING (TYPE OF SELECTION)
  737. try {
  738. if (/^(str.*|cit.*)/.test(exprBuild.cond)) {
  739. exprBuild.cond = exprBuild.cond.replace(/^str.*/, 'street');
  740. exprBuild.cond = exprBuild.cond.replace(/^cit.*/, 'city');
  741. var exprStart = exprPhrase.slice(0, -1), //don't include last element bc it should be the name itself
  742. prim, alt;
  743. if (exprStart) {
  744. //exprStart = exprStart.toString().toLowerCase();
  745. prim = /\bprim?(?:ary|\.)?\b/i.test(exprStart);
  746. alt = /\balt(?:ern\w*|\.)?\b/i.test(exprStart);
  747. any = /\bany\b/i.test(exprStart);
  748. exprPhrase = exprStart.filter(function(a) {return !/^pr|^alt|^any/i.test(a)}).concat(exprPhrase.slice(-1));
  749. } else {
  750. prim = false;
  751. alt = false;
  752. }
  753. if ((prim && alt) || any)
  754. exprBuild.condmod = 2;
  755. else if (prim)
  756. exprBuild.condmod = 0;
  757. else if (alt)
  758. exprBuild.condmod = 1;
  759. else
  760. exprBuild.condmod = 0;
  761. }
  762. } catch (err) {
  763. exprBuild.errorCode = 101;
  764. exprBuild.err = err;
  765. return exprBuild;
  766. }
  767.  
  768. // COMPARATOR OPERATION MATCHING
  769. try {
  770. // Convert to standard comparator operations
  771. var exprPhraseStr = exprPhrase.join(' ').replace(/\bcontains?/i, 'contains').replace(/(?:\bdo(?:es)?\s?n[o']t\s|!\s?)(contains)/i, '! $1');
  772. //.replace(/\b(?:do(?:es)?\s?n[o']t\s|!\s?)contains?/i, '!^').replace(/\bcontains?/i,'\u220b');
  773.  
  774. // Comparator operations with standard representation
  775. exprBuild.op = /(?:! )?contains|[!<>=~]{1,2}/i.exec(exprPhraseStr) + '';
  776.  
  777. } catch (err) {
  778. exprBuild.errorCode = 101;
  779. exprBuild.err = err;
  780. return exprBuild;
  781. }
  782.  
  783. // SELECTION VALUE MATCHING
  784. if (/^length|^last/.test(exprBuild.cond)) {
  785. exprBuild.val = exprPhraseStr.match(/\b\d+/) + '';
  786. } else {
  787. try {
  788. 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]+',
  789. whitemagic = '^\\(["\'](.*?)[\'"]\\)$|^\\s?["\'](.*)["\']$|^["\'](.*)[\'"]$|\\b(';
  790.  
  791. // The following line is kind of elaborate bc it needed to grab text between parens/quotes while keeping the inner quotes
  792. 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');
  793.  
  794. if (!/^street|^city/.test(exprBuild.cond)) {
  795. exprBuild.val = exprBuild.val.replace(/"(.*)"|'(.*)'/, '$1$2');
  796. }
  797. } catch (err) {
  798. exprBuild.errorCode = 2;
  799. exprBuild.err = err;
  800. return exprBuild;
  801. }
  802.  
  803. if (/^direction/.test(exprBuild.cond)) {
  804. 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
  805. //reduce to unique key words...
  806. }
  807. }
  808.  
  809. return exprBuild;
  810. }
  811. //switch
  812. },
  813. //parseExpr()
  814. updateExpression: function(parseThis) {
  815. this.rselButtons.clear();
  816. if (parseThis) {
  817. //console.info('*** Begin parsing expression... ***');
  818.  
  819.  
  820. var parsed = this.parseExpr(parseThis);
  821.  
  822. if (parsed && !parsed.errorCode) {
  823. var exprMatches = parsed.exprMatches,
  824. exprMatchPhrases = parsed.exprMatchPhrases,
  825. exprFragment, exprFragPhrase, mLength, m;
  826.  
  827. mLength = exprMatchPhrases.length;
  828. for (m = 0; m < mLength; m++) {
  829. RSelExprParser.__EXPR_DEBUGINFO = this.new__EXPR_DEBUGINFO(m, exprMatches[m], exprMatchPhrases[m]);
  830.  
  831. //if (m > 3) debugger;
  832.  
  833. exprFragment = exprMatches[m];
  834. exprFragPhrase = exprMatchPhrases[m];
  835.  
  836. if (exprFragPhrase.constructor !== Array) exprFragPhrase = [exprFragPhrase];
  837.  
  838. var exprBuild = this.buildExpr(exprFragment, exprFragPhrase);
  839.  
  840. if (exprBuild && !exprBuild.errorCode) {
  841. RSelExprParser.__EXPR_DEBUGINFO.errorStatus = this.addExpr(exprBuild);
  842.  
  843. if (RSelExprParser.__EXPR_DEBUGINFO.errorStatus && RSelExprParser.__EXPR_DEBUGINFO.errorStatus.errorCode) {
  844. console.warn('updateExpression() may have partly failed. Check results.');
  845. RSelExprParser.__EXPR_DEBUGINFO.exprBuild = exprBuild;
  846. console.debug(RSelExprParser.__EXPR_DEBUGINFO);
  847. return false;
  848. }
  849. } else if (exprBuild && exprBuild.errorCode) {
  850. console.warn('updateExpression() may have partly failed. Check results.');
  851. RSelExprParser.__EXPR_DEBUGINFO.exprBuild = exprBuild;
  852. console.debug(RSelExprParser.__EXPR_DEBUGINFO);
  853. return false;
  854. }
  855. } //for each condition matched
  856.  
  857. return this.getCurrentExprText();
  858. } else {
  859. console.debug(parsed);
  860. return false;
  861. }
  862. } else {
  863. return null;
  864. }
  865. }
  866. };