WME Road Selector Expression Editor (Library)

Allows easier editing of the selection criteria by converting the expressions into editable text

As of 04.03.2016. See ბოლო ვერსია.

ეს სკრიპტი არ უნდა იყოს პირდაპირ დაინსტალირებული. ეს ბიბლიოთეკაა, სხვა სკრიპტებისთვის უნდა ჩართეთ მეტა-დირექტივაში // @require https://update.greatest.deepsurf.us/scripts/17641/111332/WME%20Road%20Selector%20Expression%20Editor%20%28Library%29.js.

  1. // ==UserScript==
  2. // @name WME Road Selector Expression Editor (Library)
  3. // @namespace https://greatest.deepsurf.us/users/11629-TheLastTaterTot
  4. // @version 0.2.5
  5. // @description Allows easier editing of the selection criteria by converting the expressions into editable text
  6. // @author TheLastTaterTot
  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. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. var _rsel = {
  15. getSelectionIndex: function(selector, selText) {
  16. return selector.map(function(i) {
  17. if (new RegExp(selText, 'i').test(this.innerText)) return this.value
  18. }).get(0);
  19. },
  20. getSelectOptions: function(selector) {
  21. var opts = [];
  22. selector.map(function(i, a) {
  23. opts.push(a.innerText.toLowerCase());
  24. });
  25. return opts;
  26. },
  27. getNewExprBuild: function() {
  28. return {
  29. cond: null,
  30. op: null,
  31. op2: null,
  32. val: null,
  33. val2: null,
  34. condmod: null
  35. }
  36. }
  37. },
  38. /*Using RSel DOM elements rather than requesting dev to provide direct modifiction of RSel's expr object.
  39. This is so the RSel dev can feel free to significantly change his object storage structure if needed. */
  40. rselBtns = {
  41. lfParens: function() {
  42. try {
  43. $('#btnRSLBkt').click();
  44. } catch (err) {}
  45. },
  46. rtParens: function() {
  47. try {
  48. $('#btnRSRBkt').click();
  49. } catch (err) {}
  50. },
  51. and: function() {
  52. try {
  53. $('#btnRSAnd').click()
  54. } catch (err) {}
  55. },
  56. or: function() {
  57. try {
  58. $('#btnRSOr').click()
  59. } catch (err) {}
  60. },
  61. not: function() {
  62. try {
  63. $('#btnRSNot').click()
  64. } catch (err) {}
  65. },
  66. clear: function() {
  67. try {
  68. $('#btnRSClear').click()
  69. } catch (err) {}
  70. }
  71. },
  72. rselCond = {
  73. country: {
  74. op: function(selText) {
  75. $('#opRSCountry').val(_rsel.getSelectionIndex($('#opRSCountry option'), selText));
  76. },
  77. val: function(selText) {
  78. $('#selRSCountry').val(_rsel.getSelectionIndex($('#selRSCountry option'), selText));
  79. },
  80. add: function() {
  81. $('#btnRSAddCountry').click();
  82. }
  83. },
  84. state: {
  85. op: function(selText) {
  86. $('#opRSState').val(_rsel.getSelectionIndex($('#opRSState option'), selText));
  87. },
  88. val: function(val) {
  89. $('#inRSState').val(val);
  90. },
  91. add: function() {
  92. $('#btnRSAddState').click();
  93. }
  94. },
  95. city: {
  96. op: function(selText) {
  97. $('#opRSCity').val(_rsel.getSelectionIndex($('#opRSCity option'), selText));
  98. },
  99. val: function(val) {
  100. $('#inRSCity').val(val);
  101. },
  102. condmod: function(val) {
  103. $('#selRSAltCity').val(val);
  104. },
  105. add: function() {
  106. $('#btnRSAddCity').click();
  107. }
  108. },
  109. street: {
  110. op: function(selText) {
  111. $('#opRSStreet').val(_rsel.getSelectionIndex($('#opRSStreet option'), selText));
  112. },
  113. val: function(val) {
  114. $('#inRSStreet').val(val);
  115. },
  116. condmod: function(val) {
  117. $('#selRSAlttStreet').val(val);
  118. },
  119. add: function() {
  120. $('#btnRSAddStreet').click();
  121. }
  122. },
  123. unnamed: {
  124. op: function(chkVal) {
  125. $('#cbRSNoName').prop('checked', chkVal);
  126. }, //checked - has no name
  127. opAlt: function(chkVal) {
  128. $('#cbRSAltNoName').prop('checked', chkVal);
  129. }, //checked - alt name
  130. add: function() {
  131. $('#btnRSAddNoName').click();
  132. }
  133. },
  134. road: {
  135. op: function(selText) {
  136. $('#opRSRoadType').val(_rsel.getSelectionIndex($('#opRSRoadType option'), selText));
  137. },
  138. val: function(selText) {
  139. $('#selRSRoadType').val(_rsel.getSelectionIndex($('#selRSRoadType option'), selText));
  140. },
  141. add: function() {
  142. $('#btnRSAddRoadType').click();
  143. }
  144. },
  145. direction: {
  146. op: function(selText) {
  147. $('#opRSDirection').val(_rsel.getSelectionIndex($('#opRSDirection option'), selText));
  148. },
  149. val: function(selText) {
  150. $('#selRSDirection').val(_rsel.getSelectionIndex($('#selRSDirection option'), selText));
  151. },
  152. add: function() {
  153. $('#btnRSAddDirection').click();
  154. }
  155. },
  156. elevation: {
  157. op: function(selText) {
  158. $('#opRSElevation').val(_rsel.getSelectionIndex($('#opRSElevation option'), selText));
  159. },
  160. val: function(selText) {
  161. $('#selRSElevation').val(_rsel.getSelectionIndex($('#selRSElevation option'), selText));
  162. },
  163. add: function() {
  164. $('#btnRSAddElevation').click();
  165. }
  166. },
  167. manual: {
  168. op: function(selText) {
  169. $('#opRSManLock').val(_rsel.getSelectionIndex($('#opRSManLock option'), selText));
  170. },
  171. val: function(val) {
  172. $('#selRSManLock').val(val);
  173. },
  174. add: function() {
  175. $('#btnRSAddManLock').click();
  176. }
  177. },
  178. trafic: {
  179. op: function(selText) {
  180. $('#opRSTrLock').val(_rsel.getSelectionIndex($('#opRSTrLock option'), selText));
  181. },
  182. val: function(val) {
  183. $('#selRSTrLock').val(val);
  184. },
  185. add: function() {
  186. $('#btnRSAddTrLock').click();
  187. }
  188. },
  189. speed: {
  190. opOptNodes: $('#opRSSpeed option'),
  191. op: function(selText) {
  192. $('#opRSSpeed').val(_rsel.getSelectionIndex($('#opRSSpeed option'), selText));
  193. },
  194. val: function(val) {
  195. $('#inRSSpeed').val(val);
  196. },
  197. add: function() {
  198. $('#btnRSAddSpeed').click();
  199. }
  200. },
  201. closure: {
  202. op: function(checked) {
  203. $('#cbRSClsr').prop('checked', checked);
  204. },
  205. op2: function(selText) {
  206. $('#opRSClsrStrtEnd').val(_rsel.getSelectionIndex($('#opRSClsrStrtEnd option'), selText));
  207. },
  208. val: function(val) {
  209. $('#inRSClsrDays').val(val);
  210. },
  211. condmod: function(selText) {
  212. $('#opRSClsrBeforeAter').val(_rsel.getSelectionIndex($('#opRSClsrBeforeAter option'), selText));
  213. },
  214. add: function() {
  215. $('#btnRSAddClsr').click();
  216. }
  217. },
  218. updated: {
  219. op: function(selText) {
  220. $('#opRSUpdtd').val(_rsel.getSelectionIndex($('#opRSUpdtd option'), selText));
  221. },
  222. val: function(val) {
  223. $('#inRSUpdtd').val(val);
  224. },
  225. add: function() {
  226. $('#btnRSAddUpdtd').click();
  227. }
  228. },
  229. created: {
  230. op: function(selText) {
  231. $('#opRSCrtd').val(_rsel.getSelectionIndex($('#opRSCrtd option'), selText));
  232. },
  233. val: function(val) {
  234. $('#inRSCrtd').val(val);
  235. },
  236. add: function() {
  237. $('#btnRSAddCrtd').click();
  238. }
  239. },
  240. last: {
  241. op: function(selText) {
  242. $('#opRSLastU').val(_rsel.getSelectionIndex($('#opRSLastU option'), selText));
  243. },
  244. val: function(val) {
  245. $('#inRSLastU').val(val);
  246. },
  247. add: function() {
  248. $('#btnRSAddLastU').click();
  249. }
  250. },
  251. length: {
  252. op: function(selText) {
  253. $('#opRSLength').val(_rsel.getSelectionIndex($('#opRSLength option'), selText));
  254. },
  255. val: function(val) {
  256. $('#inRSLength').val(val);
  257. },
  258. condmod: function(selText) {
  259. $('#unitRSLength').val(_rsel.getSelectionIndex($('#unitRSLength option'), selText));
  260. },
  261. add: function() {
  262. $('#btnRSAddLength').click();
  263. }
  264. },
  265. id: {
  266. op: function(selText) {
  267. $('#opRSSegId').val(_rsel.getSelectionIndex($('#opRSSegId option'), selText));
  268. },
  269. val: function(val) {
  270. $('#inRSSegId').val(val);
  271. },
  272. add: function() {
  273. $('#btnRSAddSegId').click();
  274. }
  275. },
  276. roundabout: {
  277. op: function(checked) {
  278. $('#cbRSIsRound').prop('checked', checked);
  279. },
  280. add: function() {
  281. $('#btnRSAddIsRound').click();
  282. }
  283. },
  284. toll: {
  285. op: function(checked) {
  286. $('#cbRSIsToll').prop('checked', checked);
  287. },
  288. add: function() {
  289. $('#btnRSAddIsToll').click();
  290. }
  291. },
  292. tunnel: {
  293. op: function(checked) {
  294. $('#cbRSTunnel').prop('checked', checked);
  295. },
  296. add: function() {
  297. $('#btnRSAddTunnel').click();
  298. }
  299. },
  300. new: {
  301. op: function(checked) {
  302. $('#cbRSIsNew').prop('checked', checked);
  303. },
  304. add: function() {
  305. $('#btnRSAddIsNew').click();
  306. }
  307. },
  308. changed: {
  309. op: function(checked) {
  310. $('#cbRSIsChngd').prop('checked', checked);
  311. },
  312. add: function() {
  313. $('#btnRSAddIsChngd').click();
  314. }
  315. },
  316. screen: {
  317. op: function(checked) {
  318. $('#cbRSOnScr').prop('checked', checked);
  319. },
  320. add: function() {
  321. $('#btnRSAddOnScr').click();
  322. }
  323. },
  324. restriction: {
  325. op: function(checked) {
  326. $('#cbRSRestr').prop('checked', checked);
  327. },
  328. add: function() {
  329. $('#btnRSAddRestr').click();
  330. }
  331. },
  332. editable: {
  333. op: function(checked) {
  334. $('#cbRSEdtbl').prop('checked', checked);
  335. },
  336. add: function() {
  337. $('#btnRSAddEdtbl').click();
  338. }
  339. }
  340. };
  341.  
  342. //=============================================================================
  343. function updateExpr(parseThis) {
  344. var __EXPR_DEBUGINFO;
  345.  
  346. console.info('*** Begin parsing expression... ***');
  347. rselBtns.clear();
  348.  
  349. //---------------------------------------------------------------
  350. var addExpr = function(eb) {
  351. var checkKeys = false;
  352. Object.keys(rselCond).map(function(a, i) {
  353. if (a === eb.cond) checkKeys = true;
  354. })
  355. if (checkKeys) {
  356. try {
  357. rselCond[eb.cond].op(eb.op);
  358. if (eb.op2 !== null) rselCond[eb.cond].op2(eb.op2);
  359. if (eb.condmod !== null) rselCond[eb.cond].condmod(eb.condmod);
  360.  
  361. if (eb.val2 === null) {
  362. if (eb.val !== null) rselCond[eb.cond].val(eb.val);
  363. rselCond[eb.cond].add();
  364. } else {
  365. rselBtns.lfParens();
  366. rselCond[eb.cond].val(eb.val);
  367. rselCond[eb.cond].add();
  368. rselBtns.or();
  369. rselCond[eb.cond].val(eb.val2);
  370. rselCond[eb.cond].add();
  371. rselBtns.rtParens();
  372. }
  373.  
  374. } catch (err) {
  375. __EXPR_DEBUGINFO.eb = eb;
  376. return {__EXPR_DEBUGINFO, err};
  377. }
  378. } else {
  379. __EXPR_DEBUGINFO.eb = eb;
  380. return {__EXPR_DEBUGINFO, 'Selector condition was not recognized'};
  381. }
  382.  
  383. return true;
  384. };
  385. //---------------------------------------------------------------
  386. //parseThis = '(((Country="United States" AND State="Oregon") AND !(Prim name!="Somewhere") AND Name contains ("Somewhere")) OR (Alt name !contains ("Somewhere"))) AND Primary City ~("Some City") AND City="Big City" AND Alt. City!= "Big City" AND Prim. or Alt. City contains ("Big City") AND ((Has name OR Unnamed) AND (NO Alt. names OR Has Alt name(s))) AND Road Type = "Runway/Taxiway" AND !Roundabout AND Is NOT Toll Road AND != Unnamed & (Direction != "One way (A->B)" OR Direction = "Unknown") AND (Elevation != "Ground" AND Elevation > 1 AND Elevation <= 1) AND Is NOT Tunnel AND On Screen & OUT of Screen && Has restriction | Has NO restriction AND Has closure || Has NO closure AND Closure starts before 1 day AND Closure ends before 1 day AND Closure starts after 1 day AND Closure ends after 1 day AND Closure starts in 1 day AND Closure ends in 1 day AND Closure doesn\'t start in 1 day AND Closure doesn\'t end in 1 day';
  387. //parseThis.replace(/\bis(?:\s?n[o']t)\b/ig,'!=')
  388.  
  389. if (parseThis === undefined) parseThis = $('#cmEditExprBox').val();
  390.  
  391. var parseExprArray = parseThis.match(
  392. /\("(.*?)"\)|\('(.*?)'\)|"(.*?)"|'(.*?)'|\bpri?m?(?:ary|\.)?\s?(?:or|and|\|\||\||&|&&|\/)\s?alt(?:ern|s)?(?:\.)?|\bno[\s-]alt|\b(?:street[\s-]?)?name\(s\)|\bstreet(?:\snames?)\b|\b(?:un)?name[ds]?(?:[-\s]?seg[a-z]*)?\b|\b(?:road)(?:.?(?:type))?\b|\btoll(?:[-\s]?ro?a?d)?\b|\b(?:speed[\s-]?(?:limits?)?|sl)\b|\bman[ually]*[\s-]?(?:lock[eds]*)?\b|\btraf[fic]*[\s-]?(?:lock[eds]*)?\b|\bauto-?(?:matic[ally]*)?[\s-]?(?:lock[eds]*)?\b|\bcreated(?:[\s-]?by)?\b|\blast(?:[\s-]?(?:update[ds]?|edite?d?s?))?\b|\b(?:update[ds]?|edite?d?s?)(?:[\s-]?by)?\b|\b(?:in|on|off|out|outside)(?: of)?[- ]?screen\b|\bdoes(?:\s?n[o']t)\b|(?:!\s?)?contains?\b|!=|>=|<=|A->B|B->A|\w+(\(s\))?|&&|\|\||!=|[|&<>=()!~]/gi
  393. ),
  394. exprHistory = [],
  395. condMatches = [],
  396. condMatchPhrases = [],
  397. exprMatches = [],
  398. exprMatchPhrases = [],
  399. exprBuild, exprFragment, exprFragPhrase, exprFragPhraseStr, unwantedWordsSearch,
  400. closeParens, e, f, b, fLength, m, mLength,
  401. success = false;
  402.  
  403. // The following parses the expression text into unique chunks within separate array elements
  404. e = parseExprArray.length;
  405. while (e-- > 0) {
  406. try {
  407. exprFragment = parseExprArray.shift();
  408. //console.info(exprFragment);
  409.  
  410. // Find operators that join individual expressions (AND|OR|!|parenthesis)
  411. if (/^(?:and|or|&&|\|\||!=|[=&|()!])$/i.test(exprFragment)) {
  412. exprMatches.push(exprFragment.toLowerCase());
  413. exprMatchPhrases.push(exprFragment.toLowerCase());
  414. }
  415.  
  416. // Identify elements that contain selection condition names
  417. if (
  418. /^country|^state|^city|^street|^(?:un|street[\s-]?)?name.*|^(?:road)(?:.?(?:type))?|^type|^round[a-z]*|^rotary|^ra|^toll(?:[-\s]?ro?a?d)?|^(?:speed[\s-]?(?:limits?)?|sl)|^dir[a-z]*|^elevation|^tun[a-z]*|^man[ually]*[\s-]?(?:lock[eds]*)?|^traf[fic]*[\s-]?(?:lock[eds]*)?|^auto-?(?:matic[ally]*)?[\s-]?(?:lock[eds]*)?|^speed|^sls?|^new|^changed|^chg[a-z]*|^(?:in|on|off|out|outside)(?: of)?[- ]?screen|^restrict[a-z]*|^clos[a-z]+|^created(?:[\s-]?by)?|^last(?:[\s-]?(?:update[ds]?|edite?d?s?)[\s-]?(?:by)?)?|^(?:update[ds]?|edite?d?s?)(?:[\s-]?by)?|^length|^id|^editable/i
  419. .test(exprFragment)) {
  420. condMatches.push(exprFragment.toLowerCase()); // lists specific selection conditions
  421. exprMatches.push(exprFragment.toLowerCase()); //same as condMatches, but includes operations as separate array elements
  422.  
  423. try {
  424. //search phrase fowards
  425. fLength = parseExprArray.length;
  426. f = 0;
  427. while (!(/^(and|or|&&|\|\||[&|)])$/i.test(parseExprArray[f])) && (++f < fLength)) {}
  428. //search phrase backwards
  429. b = exprHistory.length;
  430. while (!(/^(and|or|&&|\|\||[&|(])$/i.test(exprHistory[b - 1])) && (--b > 0)) {}
  431.  
  432. condMatchPhrases.push(exprHistory.slice(b).concat(exprFragment, parseExprArray.slice(0, f))); //list specific selection conditions and its criteria
  433.  
  434. unwantedWordsSearch = exprHistory.slice(b);
  435. if (unwantedWordsSearch && unwantedWordsSearch.length) {
  436. spliceOut = [];
  437. for (m = unwantedWordsSearch.length; m--;) {
  438. if (/\b(has|have|is|=|are|does)\b/i.test(unwantedWordsSearch[m])) {
  439. unwantedWordsSearch.splice(m,1);
  440. }
  441. }
  442. }
  443. if (/!|!=/.test(unwantedWordsSearch[0])) unwantedWordsSearch.splice(0,1);
  444.  
  445. exprMatchPhrases.push(unwantedWordsSearch.concat(parseExprArray.slice(0, f))); //excludes the match cond
  446.  
  447. //exprHistory.push(exprFragment);
  448. exprHistory = exprHistory.concat(exprFragment, parseExprArray.slice(0, f));
  449. parseExprArray = parseExprArray.slice(f);
  450. e -= f;
  451. } catch (err) {
  452. return {'Error parsing expression at ' + exprFragment, err};
  453. }
  454. } else {
  455. exprHistory.push(exprFragment);
  456. }
  457. } catch (err) {
  458. return {'Error parsing expression at ' + exprFragment, err};
  459. }
  460. } //while
  461.  
  462.  
  463. //---------------------------------------------------------------
  464. // Quick crude check for unmatched parentheses
  465. var nOpenParens = exprMatches.toString().match(/\(/g),
  466. nCloseParens = exprMatches.toString().match(/\)/g);
  467. if (!nOpenParens) nOpenParens = [];
  468. if (!nCloseParens) nCloseParens = [];
  469. if (nOpenParens.length !== nCloseParens.length) return 1;
  470. //---------------------------------------------------------------
  471.  
  472. closeParens = 0;
  473. mLength = exprMatchPhrases.length;
  474. for (m = 0; m < mLength; m++) {
  475. __EXPR_DEBUGINFO = {
  476. m: m,
  477. exprMatches: exprMatches[m],
  478. exprMatchPhrases: exprMatchPhrases[m]
  479. }; //reset for error debugging
  480.  
  481. exprFragment = exprMatches[m];
  482. exprFragPhrase = exprMatchPhrases[m];
  483. if (exprFragPhrase.constructor !== Array) exprFragPhrase = [exprFragPhrase];
  484.  
  485. exprBuild = _rsel.getNewExprBuild();
  486. exprBuild.cond = exprFragment;
  487.  
  488. //if (m===10) debugger;
  489.  
  490. if (closeParens === 1) closeParens = 2;
  491.  
  492. //============================================================
  493. // Where the magic happens... sort of.
  494. //============================================================
  495. switch (true) {
  496. case (exprFragment === '('):
  497. rselBtns.lfParens();
  498. break;
  499. case (exprFragment === ')'):
  500. rselBtns.rtParens();
  501. break;
  502. case /^(&|&&|and)$/.test(exprFragment):
  503. rselBtns.and();
  504. //console.info(exprFragment.toLowerCase());
  505. break;
  506. case /^(\||\|\||or)$/.test(exprFragment):
  507. //console.info(exprFragment.toLowerCase());
  508. rselBtns.or();
  509. break;
  510. case /no[\s-]alt/i.test(exprFragPhrase):
  511. rselCond.unnamed.op(true);
  512. rselCond.unnamed.opAlt(true);
  513. rselCond.unnamed.add();
  514. success = true;
  515. break;
  516. case /^(!|!=|not)$/.test(exprFragment):
  517. rselBtns.not();
  518. if (exprMatches[m + 1] !== '(') {
  519. rselBtns.lfParens();
  520. closeParens = 1;
  521. }
  522. break;
  523. case /^unnamed/.test(exprBuild.cond):
  524. rselCond.unnamed.op(true);
  525. rselCond.unnamed.opAlt(false);
  526. rselCond.unnamed.add();
  527. success = true;
  528. break;
  529.  
  530. // SPEED LIMITS
  531. case /^speed.*|^sls?/.test(exprBuild.cond):
  532. exprBuild.cond = exprBuild.cond.replace(/^sls?|^speed.*/, 'speed');
  533.  
  534. try {
  535. if (exprFragPhrase.length < 2 && /\bnot?\b|!|!=/i.test(exprFragPhrase[0])) {
  536. exprBuild.op = 'none';
  537. } else {
  538. exprFragPhrase = exprFragPhrase.join(' ');
  539.  
  540. if (/\bnot?\b|!|!=/i.test(exprFragPhrase)) rselBtns.not();
  541.  
  542. var optionText = _rsel.getSelectOptions(rselCond.speed.opOptNodes);
  543. optionText = RegExp(optionText.join('|'), 'i').exec(exprFragPhrase);
  544. if (optionText) exprBuild.op = optionText[0];
  545. else exprBuild.op = 'any';
  546. }
  547.  
  548. var speedVal = exprFragPhrase.match(/(\d+)\s?mph|(\d+)\s?km/i);
  549. if (speedVal && speedVal.length === 2) exprBuild.val = speedVal[1];
  550. } catch (err) {
  551. __EXPR_DEBUGINFO.exprBuild = exprBuild;
  552. return {__EXPR_DEBUGINFO, err};
  553. }
  554. success = addExpr(exprBuild);
  555. break;
  556.  
  557.  
  558. // BINARY CONDITIONS:
  559. case exprFragPhrase.length === 0 || //suggests binary
  560. /^(?:screen|roundabout|ra|toll|tun|new|changed|restr|editable)/.test(exprBuild.cond) || //binary selection conditions
  561. (/^(?:street[\s-]?)?name.*|^clos.*/i.test(exprBuild.cond) && exprFragPhrase.length <= 1): //selection conditions that have both binary and multiple options
  562.  
  563. exprFragPhrase = exprFragPhrase.join(' ');
  564.  
  565. exprBuild.cond = exprBuild.cond.replace(/^(?:street[\s-]?)?name.*/, 'name');
  566. exprBuild.cond = exprBuild.cond.replace(/^ra|^rotary|^round.*/, 'roundabout');
  567. exprBuild.cond = exprBuild.cond.replace(/^toll.*/, 'toll');
  568. exprBuild.cond = exprBuild.cond.replace(/^tun.*/, 'tunnel');
  569. exprBuild.cond = exprBuild.cond.replace(/^restr.*/, 'restriction');
  570. exprBuild.cond = exprBuild.cond.replace(/^(?:in|on)[- ]?screen/, 'onscreen');
  571. exprBuild.cond = exprBuild.cond.replace(/^(?:off|out|outside)(?: of)?[- ]?screen/, 'offscreen');
  572.  
  573. if (/\bnot?\b|!|!=/i.test(exprFragPhrase)) {
  574. exprBuild.op = false;
  575. } else {
  576. exprBuild.op = true;
  577. }
  578. try {
  579. switch (exprBuild.cond) {
  580. case 'name':
  581. try {
  582. if (/alt/i.test(exprFragPhrase)) {
  583. rselCond.unnamed.op(false);
  584. rselCond.unnamed.opAlt(true);
  585. rselCond.unnamed.add();
  586. } else {
  587. rselCond.unnamed.op(false);
  588. rselCond.unnamed.opAlt(false);
  589. rselCond.unnamed.add();
  590. }
  591. success = true;
  592. } catch (err) { return {__EXPR_DEBUGINFO, err}; }
  593. break;
  594. case 'closure':
  595. exprBuild.op2 = '---';
  596. success = addExpr(exprBuild);
  597. break;
  598. case 'onscreen':
  599. exprBuild.cond = 'screen';
  600. exprBuild.op = true;
  601. success = addExpr(exprBuild);
  602. break;
  603. case 'offscreen':
  604. exprBuild.cond = 'screen';
  605. exprBuild.op = false;
  606. success = addExpr(exprBuild);
  607. break;
  608. case 'roundabout':
  609. case 'toll':
  610. case 'tunnel':
  611. case 'new':
  612. case 'changed':
  613. case 'restriction':
  614. case 'editable':
  615. success = addExpr(exprBuild);
  616. break;
  617. } //switch
  618.  
  619. } catch (err) {
  620. __EXPR_DEBUGINFO.exprBuild = exprBuild;
  621. return {__EXPR_DEBUGINFO, err};
  622. }
  623. break;
  624. //--------------------------------------------------------------------
  625.  
  626. case /^closure/.test(exprBuild.cond):
  627. try {
  628. exprFragPhrase = exprFragPhrase.join().toLowerCase();
  629. exprBuild.op = !(/does\s?n['o]t|!|!=/.test(exprFragPhrase)); //checkbox
  630. exprBuild.op2 = /start|end/.exec(exprFragPhrase) + 's'; //starts/ends
  631. exprBuild.condmod = /before|after|\bin\b/.exec(exprFragPhrase) + ''; //in/before/after
  632. exprBuild.val = /\d+/.exec(exprFragPhrase) + ''; //days ago
  633. } catch (err) {
  634. __EXPR_DEBUGINFO.exprBuild = exprBuild;
  635. return {__EXPR_DEBUGINFO, err};
  636. }
  637. success = addExpr(exprBuild);
  638. break;
  639.  
  640. default:
  641. // CONDITION NAME MATCHING (TYPE OF SELECTION)
  642. try {
  643. if (/^(?:name.*|^str.*|^cit.*)/.test(exprBuild.cond)) {
  644. exprBuild.cond = exprBuild.cond.replace(/^name.*/, 'street');
  645. exprBuild.cond = exprBuild.cond.replace(/^str.*/, 'street');
  646. exprBuild.cond = exprBuild.cond.replace(/^cit.*/, 'city');
  647. var exprStart = exprFragPhrase.slice(0, -1), //don't include last element bc it should be the name itself
  648. prim, alt;
  649. if (exprStart) {
  650. exprStart = exprStart.toString().toLowerCase();
  651. prim = /\bpri?m?(?:ary|\.)?\b/i.test(exprStart);
  652. alt = /\balt(?:ern\w*|\.)?\b/i.test(exprStart);
  653. } else {
  654. prim = false;
  655. alt = false;
  656. }
  657. if (prim && alt) exprBuild.condmod = 2;
  658. else if (prim) exprBuild.condmod = 0;
  659. else if (alt) exprBuild.condmod = 1;
  660. else exprBuild.condmod = 0;
  661. } else {
  662. exprBuild.cond = exprBuild.cond.replace(/^traf.*|^auto.*/, 'trafic');
  663. exprBuild.cond = exprBuild.cond.replace(/^man.*/, 'manual');
  664. exprBuild.cond = exprBuild.cond.replace(/^dir.*/, 'direction');
  665. exprBuild.cond = exprBuild.cond.replace(/^(?:road)(?:.?(?:type))?|^type/, 'road');
  666. exprBuild.cond = exprBuild.cond.replace(/^last\s.*/, 'last');
  667. exprBuild.cond = exprBuild.cond.replace(/^create.*/, 'created');
  668. exprBuild.cond = exprBuild.cond.replace(/^update.*/, 'updated');
  669. }
  670. } catch (err) {
  671. __EXPR_DEBUGINFO.exprBuild = exprBuild;
  672. return {__EXPR_DEBUGINFO, err};
  673. }
  674.  
  675. // COMPARATOR OPERATION MATCHING
  676. try {
  677. // Convert natural lang representation to standard comparator operations
  678. exprFragPhraseStr = exprFragPhrase.join(' ').replace(/is less than|is fewer than/i, '<');
  679. exprFragPhraseStr = exprFragPhraseStr.replace(/is greater than/i, '>');
  680. exprFragPhraseStr = exprFragPhraseStr.replace(/is less or equal to|is less than or equal to|is fewer than or equal to|is fewer or equal to/i, '<=');
  681. exprFragPhraseStr = exprFragPhraseStr.replace(/is greater than or equal to|is greater or equal to/i, '>=');
  682. exprFragPhraseStr = exprFragPhraseStr.replace(/(?:does|has|is|was|were|are)(?:\s?n[o']t)(?:\sequal)?/i, '!=');
  683. exprFragPhraseStr = exprFragPhraseStr.replace(/(?:has|have|is|was|were|are)(?:\sequal)?|==/i, '=');
  684. exprFragPhraseStr = exprFragPhraseStr.replace(/(?:do(?:es)?\s?n[o']t\s|!\s?)contains?/i, '! contains');
  685. exprFragPhraseStr = exprFragPhraseStr.replace(/contains?/i, 'contains');
  686.  
  687. // Comparator operations with standard representation
  688. exprBuild.op = /(?:! )?contains|[!<>=~]{1,2}/i.exec(exprFragPhraseStr)+'';
  689. //console.info(exprBuild.op);
  690. } catch (err) {
  691. __EXPR_DEBUGINFO.exprBuild = exprBuild;
  692. return {__EXPR_DEBUGINFO, err};
  693. }
  694.  
  695. // SELECTION VALUE MATCHING
  696. try {
  697. if (/^length|^last/.test(exprBuild.cond)) {
  698. exprFragPhraseStr = exprFragPhraseStr.replace(/\btoday\b/,0);
  699. exprFragPhraseStr = exprFragPhraseStr.replace(/\byesterday\b/,1);
  700. exprBuild.val = exprFragPhraseStr.match(/\b\d+/)+''
  701. } else {
  702. var exprCondVal = exprFragPhrase.slice(-1)[0];
  703. // Remove surrounding paretheses and quotations
  704. if (/^[('"]+(.*?)['")]+$/.test(exprCondVal)) {
  705. exprBuild.val = exprCondVal.replace(/^[('"\s]+(.*?)[\s'")]+$/, '$1'); //.replace(/["()]/g,'').replace(/^'(.*)'$/,'$1');
  706. } else {
  707. try {
  708. exprBuild.val = exprFragPhraseStr.replace(new RegExp('(?:' + exprBuild.op + ')\\s(\\b(?:\\w\\s?)*\\b)','i'), '$1');
  709. } catch (err) {
  710. __EXPR_DEBUGINFO.exprBuild = exprBuild;
  711. return {2,__EXPR_DEBUGINFO};
  712. }
  713. }
  714.  
  715.  
  716. // Add flexility to value specification for direction selection
  717. // Also allow user to specify 'oneway' without direction and auto add expr for both directions
  718. if (/^direction/.test(exprBuild.cond)) {
  719. exprBuild.val = exprBuild.val.match(/A[<>-\s]*B|B[<>-\s]*A|^one[\s-]?ways?$|unknown/i)+''; //reduce to unique key words... last option will automatically input both one ways
  720. exprBuild.val = exprBuild.val.replace(/B[\s<-]*A/, 'A->B');
  721. exprBuild.val = exprBuild.val.replace(/A[\s<-]*B/, 'B->A');
  722. if (/^one[\s-]?ways?$/.test(exprBuild.val)) {
  723. exprBuild.val = 'A->B';
  724. exprBuild.val2 = 'B->A';
  725. }
  726. } else if (/^road/.test(exprBuild.cond)) {
  727. exprBuild.val = exprBuild.val.replace(/^fwy$/i,'^freeway');
  728. exprBuild.val = exprBuild.val.replace(/hwy/i,''); //not important bc not a unique keyword
  729. exprBuild.val = exprBuild.val.replace(/^MH$/,'^major');
  730. exprBuild.val = exprBuild.val.replace(/^mH$/,'^minor');
  731. exprBuild.val = exprBuild.val.replace(/^ps$|^prim.*/i,'^primary');
  732. exprBuild.val = exprBuild.val.replace(/^st.*/i,'^street');
  733. exprBuild.val = exprBuild.val.replace(/^dirt.*|.*4[\s-]?x[\s-]?4.*/i,'^dirt');
  734. exprBuild.val = exprBuild.val.replace(/^plr$|^pl$|^park.*/i,'^parking');
  735. exprBuild.val = exprBuild.val.replace(/^pr$|^pvtr$|^pvr$|^priv.*/i,'^private');
  736. exprBuild.val = exprBuild.val.replace(/^wt$|^walk.*|.*trl/i,'^walking');
  737. exprBuild.val = exprBuild.val.replace(/^pb$|^ped.*|.*b(?:oard)?w(?:alk)?/i,'^pedestrian');
  738. exprBuild.val = exprBuild.val.replace(/^sw$|^stair.*/i,'^stairway');
  739. exprBuild.val = exprBuild.val.replace(/^rr$|^rail.*/i,'^railroad');
  740. exprBuild.val = exprBuild.val.replace(/^rw$|^tw$|.*run.*|.*taxi.*/i,'^runway');
  741. }
  742. }
  743. success = addExpr(exprBuild);
  744.  
  745. } catch (err) {
  746. __EXPR_DEBUGINFO.exprBuild = exprBuild;
  747. return {__EXPR_DEBUGINFO, err};
  748. }
  749. } //switch
  750.  
  751. if (closeParens === 2) {
  752. rselBtns.rtParens();
  753. closeParens = 0;
  754. }
  755.  
  756. } //for each condition matched
  757. __EXPR_DEBUGINFO.exprBuild = exprBuild;
  758. if (!success) {
  759. return {__EXPR_DEBUGINFO}
  760. }
  761. } //updateExpr()
  762.