relationExpressionParser.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  1. /*
  2. * Generated by PEG.js 0.10.0.
  3. *
  4. * http://pegjs.org/
  5. */
  6. 'use strict';
  7. function peg$subclass(child, parent) {
  8. function ctor() {
  9. this.constructor = child;
  10. }
  11. ctor.prototype = parent.prototype;
  12. child.prototype = new ctor();
  13. }
  14. function peg$SyntaxError(message, expected, found, location) {
  15. this.message = message;
  16. this.expected = expected;
  17. this.found = found;
  18. this.location = location;
  19. this.name = 'SyntaxError';
  20. if (typeof Error.captureStackTrace === 'function') {
  21. Error.captureStackTrace(this, peg$SyntaxError);
  22. }
  23. }
  24. peg$subclass(peg$SyntaxError, Error);
  25. peg$SyntaxError.buildMessage = function(expected, found) {
  26. var DESCRIBE_EXPECTATION_FNS = {
  27. literal: function(expectation) {
  28. return '"' + literalEscape(expectation.text) + '"';
  29. },
  30. class: function(expectation) {
  31. var escapedParts = '',
  32. i;
  33. for (i = 0; i < expectation.parts.length; i++) {
  34. escapedParts +=
  35. expectation.parts[i] instanceof Array
  36. ? classEscape(expectation.parts[i][0]) + '-' + classEscape(expectation.parts[i][1])
  37. : classEscape(expectation.parts[i]);
  38. }
  39. return '[' + (expectation.inverted ? '^' : '') + escapedParts + ']';
  40. },
  41. any: function(expectation) {
  42. return 'any character';
  43. },
  44. end: function(expectation) {
  45. return 'end of input';
  46. },
  47. other: function(expectation) {
  48. return expectation.description;
  49. }
  50. };
  51. function hex(ch) {
  52. return ch
  53. .charCodeAt(0)
  54. .toString(16)
  55. .toUpperCase();
  56. }
  57. function literalEscape(s) {
  58. return s
  59. .replace(/\\/g, '\\\\')
  60. .replace(/"/g, '\\"')
  61. .replace(/\0/g, '\\0')
  62. .replace(/\t/g, '\\t')
  63. .replace(/\n/g, '\\n')
  64. .replace(/\r/g, '\\r')
  65. .replace(/[\x00-\x0F]/g, function(ch) {
  66. return '\\x0' + hex(ch);
  67. })
  68. .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) {
  69. return '\\x' + hex(ch);
  70. });
  71. }
  72. function classEscape(s) {
  73. return s
  74. .replace(/\\/g, '\\\\')
  75. .replace(/\]/g, '\\]')
  76. .replace(/\^/g, '\\^')
  77. .replace(/-/g, '\\-')
  78. .replace(/\0/g, '\\0')
  79. .replace(/\t/g, '\\t')
  80. .replace(/\n/g, '\\n')
  81. .replace(/\r/g, '\\r')
  82. .replace(/[\x00-\x0F]/g, function(ch) {
  83. return '\\x0' + hex(ch);
  84. })
  85. .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) {
  86. return '\\x' + hex(ch);
  87. });
  88. }
  89. function describeExpectation(expectation) {
  90. return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
  91. }
  92. function describeExpected(expected) {
  93. var descriptions = new Array(expected.length),
  94. i,
  95. j;
  96. for (i = 0; i < expected.length; i++) {
  97. descriptions[i] = describeExpectation(expected[i]);
  98. }
  99. descriptions.sort();
  100. if (descriptions.length > 0) {
  101. for (i = 1, j = 1; i < descriptions.length; i++) {
  102. if (descriptions[i - 1] !== descriptions[i]) {
  103. descriptions[j] = descriptions[i];
  104. j++;
  105. }
  106. }
  107. descriptions.length = j;
  108. }
  109. switch (descriptions.length) {
  110. case 1:
  111. return descriptions[0];
  112. case 2:
  113. return descriptions[0] + ' or ' + descriptions[1];
  114. default:
  115. return (
  116. descriptions.slice(0, -1).join(', ') + ', or ' + descriptions[descriptions.length - 1]
  117. );
  118. }
  119. }
  120. function describeFound(found) {
  121. return found ? '"' + literalEscape(found) + '"' : 'end of input';
  122. }
  123. return 'Expected ' + describeExpected(expected) + ' but ' + describeFound(found) + ' found.';
  124. };
  125. function peg$parse(input, options) {
  126. options = options !== void 0 ? options : {};
  127. var peg$FAILED = {},
  128. peg$startRuleFunctions = { start: peg$parsestart },
  129. peg$startRuleFunction = peg$parsestart,
  130. peg$c0 = function(expr) {
  131. let node = {
  132. $name: null,
  133. $relation: null,
  134. $modify: [],
  135. $recursive: false,
  136. $allRecursive: false
  137. };
  138. if (expr.$name === '*') {
  139. node.$allRecursive = true;
  140. } else {
  141. node[expr.$name] = expr;
  142. }
  143. return node;
  144. },
  145. peg$c1 = function(list) {
  146. let node = {
  147. $name: null,
  148. $relation: null,
  149. $modify: [],
  150. $recursive: false,
  151. $allRecursive: false
  152. };
  153. list.forEach(expr => {
  154. node[expr.$name] = expr;
  155. });
  156. return node;
  157. },
  158. peg$c2 = function(name, args, alias, list) {
  159. let node = {
  160. $name: alias || name,
  161. $relation: name,
  162. $modify: args || [],
  163. $recursive: false,
  164. $allRecursive: false
  165. };
  166. list.forEach(expr => {
  167. node[expr.$name] = expr;
  168. });
  169. return node;
  170. },
  171. peg$c3 = function(name, args, alias, expr) {
  172. let node = {
  173. $name: alias || name,
  174. $relation: name,
  175. $modify: args || [],
  176. $recursive: false,
  177. $allRecursive: false
  178. };
  179. if (expr) {
  180. const match = /^\^(\d*)$/.exec(expr.$name);
  181. if (match) {
  182. if (match[1]) {
  183. node.$recursive = parseInt(match[1], 10);
  184. } else {
  185. node.$recursive = true;
  186. }
  187. } else if (expr.$name === '*') {
  188. node.$allRecursive = true;
  189. } else {
  190. node[expr.$name] = expr;
  191. }
  192. }
  193. return node;
  194. },
  195. peg$c4 = 'as',
  196. peg$c5 = peg$literalExpectation('as', false),
  197. peg$c6 = function(alias) {
  198. return alias;
  199. },
  200. peg$c7 = function(name) {
  201. return name.join('');
  202. },
  203. peg$c8 = /^[^[\](),. \t\r\n]/,
  204. peg$c9 = peg$classExpectation(
  205. ['[', ']', '(', ')', ',', '.', ' ', '\t', '\r', '\n'],
  206. true,
  207. false
  208. ),
  209. peg$c10 = '(',
  210. peg$c11 = peg$literalExpectation('(', false),
  211. peg$c12 = ')',
  212. peg$c13 = peg$literalExpectation(')', false),
  213. peg$c14 = function(args) {
  214. return args;
  215. },
  216. peg$c15 = ',',
  217. peg$c16 = peg$literalExpectation(',', false),
  218. peg$c17 = function(arg) {
  219. return arg;
  220. },
  221. peg$c18 = /^[ \t\r\n]/,
  222. peg$c19 = peg$classExpectation([' ', '\t', '\r', '\n'], false, false),
  223. peg$c20 = '.',
  224. peg$c21 = peg$literalExpectation('.', false),
  225. peg$c22 = function(list) {
  226. return list;
  227. },
  228. peg$c23 = '[',
  229. peg$c24 = peg$literalExpectation('[', false),
  230. peg$c25 = ']',
  231. peg$c26 = peg$literalExpectation(']', false),
  232. peg$c27 = function(items) {
  233. return items;
  234. },
  235. peg$c28 = function(expr) {
  236. return expr;
  237. },
  238. peg$c29 = function(sub) {
  239. return sub;
  240. },
  241. peg$currPos = 0,
  242. peg$savedPos = 0,
  243. peg$posDetailsCache = [{ line: 1, column: 1 }],
  244. peg$maxFailPos = 0,
  245. peg$maxFailExpected = [],
  246. peg$silentFails = 0,
  247. peg$result;
  248. if ('startRule' in options) {
  249. if (!(options.startRule in peg$startRuleFunctions)) {
  250. throw new Error('Can\'t start parsing from rule "' + options.startRule + '".');
  251. }
  252. peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
  253. }
  254. function text() {
  255. return input.substring(peg$savedPos, peg$currPos);
  256. }
  257. function location() {
  258. return peg$computeLocation(peg$savedPos, peg$currPos);
  259. }
  260. function expected(description, location) {
  261. location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
  262. throw peg$buildStructuredError(
  263. [peg$otherExpectation(description)],
  264. input.substring(peg$savedPos, peg$currPos),
  265. location
  266. );
  267. }
  268. function error(message, location) {
  269. location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
  270. throw peg$buildSimpleError(message, location);
  271. }
  272. function peg$literalExpectation(text, ignoreCase) {
  273. return { type: 'literal', text: text, ignoreCase: ignoreCase };
  274. }
  275. function peg$classExpectation(parts, inverted, ignoreCase) {
  276. return { type: 'class', parts: parts, inverted: inverted, ignoreCase: ignoreCase };
  277. }
  278. function peg$anyExpectation() {
  279. return { type: 'any' };
  280. }
  281. function peg$endExpectation() {
  282. return { type: 'end' };
  283. }
  284. function peg$otherExpectation(description) {
  285. return { type: 'other', description: description };
  286. }
  287. function peg$computePosDetails(pos) {
  288. var details = peg$posDetailsCache[pos],
  289. p;
  290. if (details) {
  291. return details;
  292. } else {
  293. p = pos - 1;
  294. while (!peg$posDetailsCache[p]) {
  295. p--;
  296. }
  297. details = peg$posDetailsCache[p];
  298. details = {
  299. line: details.line,
  300. column: details.column
  301. };
  302. while (p < pos) {
  303. if (input.charCodeAt(p) === 10) {
  304. details.line++;
  305. details.column = 1;
  306. } else {
  307. details.column++;
  308. }
  309. p++;
  310. }
  311. peg$posDetailsCache[pos] = details;
  312. return details;
  313. }
  314. }
  315. function peg$computeLocation(startPos, endPos) {
  316. var startPosDetails = peg$computePosDetails(startPos),
  317. endPosDetails = peg$computePosDetails(endPos);
  318. return {
  319. start: {
  320. offset: startPos,
  321. line: startPosDetails.line,
  322. column: startPosDetails.column
  323. },
  324. end: {
  325. offset: endPos,
  326. line: endPosDetails.line,
  327. column: endPosDetails.column
  328. }
  329. };
  330. }
  331. function peg$fail(expected) {
  332. if (peg$currPos < peg$maxFailPos) {
  333. return;
  334. }
  335. if (peg$currPos > peg$maxFailPos) {
  336. peg$maxFailPos = peg$currPos;
  337. peg$maxFailExpected = [];
  338. }
  339. peg$maxFailExpected.push(expected);
  340. }
  341. function peg$buildSimpleError(message, location) {
  342. return new peg$SyntaxError(message, null, null, location);
  343. }
  344. function peg$buildStructuredError(expected, found, location) {
  345. return new peg$SyntaxError(
  346. peg$SyntaxError.buildMessage(expected, found),
  347. expected,
  348. found,
  349. location
  350. );
  351. }
  352. function peg$parsestart() {
  353. var s0, s1;
  354. s0 = peg$currPos;
  355. s1 = peg$parseexpression();
  356. if (s1 !== peg$FAILED) {
  357. peg$savedPos = s0;
  358. s1 = peg$c0(s1);
  359. }
  360. s0 = s1;
  361. if (s0 === peg$FAILED) {
  362. s0 = peg$currPos;
  363. s1 = peg$parselistExpression();
  364. if (s1 !== peg$FAILED) {
  365. peg$savedPos = s0;
  366. s1 = peg$c1(s1);
  367. }
  368. s0 = s1;
  369. }
  370. return s0;
  371. }
  372. function peg$parseexpression() {
  373. var s0, s1, s2, s3, s4;
  374. s0 = peg$currPos;
  375. s1 = peg$parsename();
  376. if (s1 !== peg$FAILED) {
  377. s2 = peg$parseargs();
  378. if (s2 === peg$FAILED) {
  379. s2 = null;
  380. }
  381. if (s2 !== peg$FAILED) {
  382. s3 = peg$parsealias();
  383. if (s3 === peg$FAILED) {
  384. s3 = null;
  385. }
  386. if (s3 !== peg$FAILED) {
  387. s4 = peg$parsesubListExpression();
  388. if (s4 !== peg$FAILED) {
  389. peg$savedPos = s0;
  390. s1 = peg$c2(s1, s2, s3, s4);
  391. s0 = s1;
  392. } else {
  393. peg$currPos = s0;
  394. s0 = peg$FAILED;
  395. }
  396. } else {
  397. peg$currPos = s0;
  398. s0 = peg$FAILED;
  399. }
  400. } else {
  401. peg$currPos = s0;
  402. s0 = peg$FAILED;
  403. }
  404. } else {
  405. peg$currPos = s0;
  406. s0 = peg$FAILED;
  407. }
  408. if (s0 === peg$FAILED) {
  409. s0 = peg$currPos;
  410. s1 = peg$parsename();
  411. if (s1 !== peg$FAILED) {
  412. s2 = peg$parseargs();
  413. if (s2 === peg$FAILED) {
  414. s2 = null;
  415. }
  416. if (s2 !== peg$FAILED) {
  417. s3 = peg$parsealias();
  418. if (s3 === peg$FAILED) {
  419. s3 = null;
  420. }
  421. if (s3 !== peg$FAILED) {
  422. s4 = peg$parsesubExpression();
  423. if (s4 === peg$FAILED) {
  424. s4 = null;
  425. }
  426. if (s4 !== peg$FAILED) {
  427. peg$savedPos = s0;
  428. s1 = peg$c3(s1, s2, s3, s4);
  429. s0 = s1;
  430. } else {
  431. peg$currPos = s0;
  432. s0 = peg$FAILED;
  433. }
  434. } else {
  435. peg$currPos = s0;
  436. s0 = peg$FAILED;
  437. }
  438. } else {
  439. peg$currPos = s0;
  440. s0 = peg$FAILED;
  441. }
  442. } else {
  443. peg$currPos = s0;
  444. s0 = peg$FAILED;
  445. }
  446. }
  447. return s0;
  448. }
  449. function peg$parsealias() {
  450. var s0, s1, s2, s3, s4;
  451. s0 = peg$currPos;
  452. s1 = [];
  453. s2 = peg$parsews();
  454. if (s2 !== peg$FAILED) {
  455. while (s2 !== peg$FAILED) {
  456. s1.push(s2);
  457. s2 = peg$parsews();
  458. }
  459. } else {
  460. s1 = peg$FAILED;
  461. }
  462. if (s1 !== peg$FAILED) {
  463. if (input.substr(peg$currPos, 2) === peg$c4) {
  464. s2 = peg$c4;
  465. peg$currPos += 2;
  466. } else {
  467. s2 = peg$FAILED;
  468. if (peg$silentFails === 0) {
  469. peg$fail(peg$c5);
  470. }
  471. }
  472. if (s2 !== peg$FAILED) {
  473. s3 = [];
  474. s4 = peg$parsews();
  475. if (s4 !== peg$FAILED) {
  476. while (s4 !== peg$FAILED) {
  477. s3.push(s4);
  478. s4 = peg$parsews();
  479. }
  480. } else {
  481. s3 = peg$FAILED;
  482. }
  483. if (s3 !== peg$FAILED) {
  484. s4 = peg$parsename();
  485. if (s4 !== peg$FAILED) {
  486. peg$savedPos = s0;
  487. s1 = peg$c6(s4);
  488. s0 = s1;
  489. } else {
  490. peg$currPos = s0;
  491. s0 = peg$FAILED;
  492. }
  493. } else {
  494. peg$currPos = s0;
  495. s0 = peg$FAILED;
  496. }
  497. } else {
  498. peg$currPos = s0;
  499. s0 = peg$FAILED;
  500. }
  501. } else {
  502. peg$currPos = s0;
  503. s0 = peg$FAILED;
  504. }
  505. return s0;
  506. }
  507. function peg$parsename() {
  508. var s0, s1, s2;
  509. s0 = peg$currPos;
  510. s1 = [];
  511. s2 = peg$parsechar();
  512. if (s2 !== peg$FAILED) {
  513. while (s2 !== peg$FAILED) {
  514. s1.push(s2);
  515. s2 = peg$parsechar();
  516. }
  517. } else {
  518. s1 = peg$FAILED;
  519. }
  520. if (s1 !== peg$FAILED) {
  521. peg$savedPos = s0;
  522. s1 = peg$c7(s1);
  523. }
  524. s0 = s1;
  525. return s0;
  526. }
  527. function peg$parsechar() {
  528. var s0;
  529. if (peg$c8.test(input.charAt(peg$currPos))) {
  530. s0 = input.charAt(peg$currPos);
  531. peg$currPos++;
  532. } else {
  533. s0 = peg$FAILED;
  534. if (peg$silentFails === 0) {
  535. peg$fail(peg$c9);
  536. }
  537. }
  538. return s0;
  539. }
  540. function peg$parseargs() {
  541. var s0, s1, s2, s3, s4, s5;
  542. s0 = peg$currPos;
  543. s1 = [];
  544. s2 = peg$parsews();
  545. while (s2 !== peg$FAILED) {
  546. s1.push(s2);
  547. s2 = peg$parsews();
  548. }
  549. if (s1 !== peg$FAILED) {
  550. if (input.charCodeAt(peg$currPos) === 40) {
  551. s2 = peg$c10;
  552. peg$currPos++;
  553. } else {
  554. s2 = peg$FAILED;
  555. if (peg$silentFails === 0) {
  556. peg$fail(peg$c11);
  557. }
  558. }
  559. if (s2 !== peg$FAILED) {
  560. s3 = [];
  561. s4 = peg$parseargListItem();
  562. while (s4 !== peg$FAILED) {
  563. s3.push(s4);
  564. s4 = peg$parseargListItem();
  565. }
  566. if (s3 !== peg$FAILED) {
  567. s4 = [];
  568. s5 = peg$parsews();
  569. while (s5 !== peg$FAILED) {
  570. s4.push(s5);
  571. s5 = peg$parsews();
  572. }
  573. if (s4 !== peg$FAILED) {
  574. if (input.charCodeAt(peg$currPos) === 41) {
  575. s5 = peg$c12;
  576. peg$currPos++;
  577. } else {
  578. s5 = peg$FAILED;
  579. if (peg$silentFails === 0) {
  580. peg$fail(peg$c13);
  581. }
  582. }
  583. if (s5 !== peg$FAILED) {
  584. peg$savedPos = s0;
  585. s1 = peg$c14(s3);
  586. s0 = s1;
  587. } else {
  588. peg$currPos = s0;
  589. s0 = peg$FAILED;
  590. }
  591. } else {
  592. peg$currPos = s0;
  593. s0 = peg$FAILED;
  594. }
  595. } else {
  596. peg$currPos = s0;
  597. s0 = peg$FAILED;
  598. }
  599. } else {
  600. peg$currPos = s0;
  601. s0 = peg$FAILED;
  602. }
  603. } else {
  604. peg$currPos = s0;
  605. s0 = peg$FAILED;
  606. }
  607. return s0;
  608. }
  609. function peg$parseargListItem() {
  610. var s0, s1, s2, s3, s4;
  611. s0 = peg$currPos;
  612. s1 = [];
  613. s2 = peg$parsews();
  614. while (s2 !== peg$FAILED) {
  615. s1.push(s2);
  616. s2 = peg$parsews();
  617. }
  618. if (s1 !== peg$FAILED) {
  619. s2 = peg$parsename();
  620. if (s2 !== peg$FAILED) {
  621. s3 = [];
  622. s4 = peg$parsews();
  623. while (s4 !== peg$FAILED) {
  624. s3.push(s4);
  625. s4 = peg$parsews();
  626. }
  627. if (s3 !== peg$FAILED) {
  628. if (input.charCodeAt(peg$currPos) === 44) {
  629. s4 = peg$c15;
  630. peg$currPos++;
  631. } else {
  632. s4 = peg$FAILED;
  633. if (peg$silentFails === 0) {
  634. peg$fail(peg$c16);
  635. }
  636. }
  637. if (s4 === peg$FAILED) {
  638. s4 = null;
  639. }
  640. if (s4 !== peg$FAILED) {
  641. peg$savedPos = s0;
  642. s1 = peg$c17(s2);
  643. s0 = s1;
  644. } else {
  645. peg$currPos = s0;
  646. s0 = peg$FAILED;
  647. }
  648. } else {
  649. peg$currPos = s0;
  650. s0 = peg$FAILED;
  651. }
  652. } else {
  653. peg$currPos = s0;
  654. s0 = peg$FAILED;
  655. }
  656. } else {
  657. peg$currPos = s0;
  658. s0 = peg$FAILED;
  659. }
  660. return s0;
  661. }
  662. function peg$parsews() {
  663. var s0;
  664. if (peg$c18.test(input.charAt(peg$currPos))) {
  665. s0 = input.charAt(peg$currPos);
  666. peg$currPos++;
  667. } else {
  668. s0 = peg$FAILED;
  669. if (peg$silentFails === 0) {
  670. peg$fail(peg$c19);
  671. }
  672. }
  673. return s0;
  674. }
  675. function peg$parsesubListExpression() {
  676. var s0, s1, s2, s3;
  677. s0 = peg$currPos;
  678. s1 = [];
  679. s2 = peg$parsews();
  680. while (s2 !== peg$FAILED) {
  681. s1.push(s2);
  682. s2 = peg$parsews();
  683. }
  684. if (s1 !== peg$FAILED) {
  685. if (input.charCodeAt(peg$currPos) === 46) {
  686. s2 = peg$c20;
  687. peg$currPos++;
  688. } else {
  689. s2 = peg$FAILED;
  690. if (peg$silentFails === 0) {
  691. peg$fail(peg$c21);
  692. }
  693. }
  694. if (s2 !== peg$FAILED) {
  695. s3 = peg$parselistExpression();
  696. if (s3 !== peg$FAILED) {
  697. peg$savedPos = s0;
  698. s1 = peg$c22(s3);
  699. s0 = s1;
  700. } else {
  701. peg$currPos = s0;
  702. s0 = peg$FAILED;
  703. }
  704. } else {
  705. peg$currPos = s0;
  706. s0 = peg$FAILED;
  707. }
  708. } else {
  709. peg$currPos = s0;
  710. s0 = peg$FAILED;
  711. }
  712. return s0;
  713. }
  714. function peg$parselistExpression() {
  715. var s0, s1, s2, s3, s4, s5, s6, s7;
  716. s0 = peg$currPos;
  717. s1 = [];
  718. s2 = peg$parsews();
  719. while (s2 !== peg$FAILED) {
  720. s1.push(s2);
  721. s2 = peg$parsews();
  722. }
  723. if (s1 !== peg$FAILED) {
  724. if (input.charCodeAt(peg$currPos) === 91) {
  725. s2 = peg$c23;
  726. peg$currPos++;
  727. } else {
  728. s2 = peg$FAILED;
  729. if (peg$silentFails === 0) {
  730. peg$fail(peg$c24);
  731. }
  732. }
  733. if (s2 !== peg$FAILED) {
  734. s3 = [];
  735. s4 = peg$parselistExpressionItem();
  736. while (s4 !== peg$FAILED) {
  737. s3.push(s4);
  738. s4 = peg$parselistExpressionItem();
  739. }
  740. if (s3 !== peg$FAILED) {
  741. s4 = [];
  742. s5 = peg$parsews();
  743. while (s5 !== peg$FAILED) {
  744. s4.push(s5);
  745. s5 = peg$parsews();
  746. }
  747. if (s4 !== peg$FAILED) {
  748. if (input.charCodeAt(peg$currPos) === 93) {
  749. s5 = peg$c25;
  750. peg$currPos++;
  751. } else {
  752. s5 = peg$FAILED;
  753. if (peg$silentFails === 0) {
  754. peg$fail(peg$c26);
  755. }
  756. }
  757. if (s5 !== peg$FAILED) {
  758. s6 = [];
  759. s7 = peg$parsews();
  760. while (s7 !== peg$FAILED) {
  761. s6.push(s7);
  762. s7 = peg$parsews();
  763. }
  764. if (s6 !== peg$FAILED) {
  765. peg$savedPos = s0;
  766. s1 = peg$c27(s3);
  767. s0 = s1;
  768. } else {
  769. peg$currPos = s0;
  770. s0 = peg$FAILED;
  771. }
  772. } else {
  773. peg$currPos = s0;
  774. s0 = peg$FAILED;
  775. }
  776. } else {
  777. peg$currPos = s0;
  778. s0 = peg$FAILED;
  779. }
  780. } else {
  781. peg$currPos = s0;
  782. s0 = peg$FAILED;
  783. }
  784. } else {
  785. peg$currPos = s0;
  786. s0 = peg$FAILED;
  787. }
  788. } else {
  789. peg$currPos = s0;
  790. s0 = peg$FAILED;
  791. }
  792. return s0;
  793. }
  794. function peg$parselistExpressionItem() {
  795. var s0, s1, s2, s3, s4;
  796. s0 = peg$currPos;
  797. s1 = [];
  798. s2 = peg$parsews();
  799. while (s2 !== peg$FAILED) {
  800. s1.push(s2);
  801. s2 = peg$parsews();
  802. }
  803. if (s1 !== peg$FAILED) {
  804. s2 = peg$parseexpression();
  805. if (s2 !== peg$FAILED) {
  806. s3 = [];
  807. s4 = peg$parsews();
  808. while (s4 !== peg$FAILED) {
  809. s3.push(s4);
  810. s4 = peg$parsews();
  811. }
  812. if (s3 !== peg$FAILED) {
  813. if (input.charCodeAt(peg$currPos) === 44) {
  814. s4 = peg$c15;
  815. peg$currPos++;
  816. } else {
  817. s4 = peg$FAILED;
  818. if (peg$silentFails === 0) {
  819. peg$fail(peg$c16);
  820. }
  821. }
  822. if (s4 === peg$FAILED) {
  823. s4 = null;
  824. }
  825. if (s4 !== peg$FAILED) {
  826. peg$savedPos = s0;
  827. s1 = peg$c28(s2);
  828. s0 = s1;
  829. } else {
  830. peg$currPos = s0;
  831. s0 = peg$FAILED;
  832. }
  833. } else {
  834. peg$currPos = s0;
  835. s0 = peg$FAILED;
  836. }
  837. } else {
  838. peg$currPos = s0;
  839. s0 = peg$FAILED;
  840. }
  841. } else {
  842. peg$currPos = s0;
  843. s0 = peg$FAILED;
  844. }
  845. return s0;
  846. }
  847. function peg$parsesubExpression() {
  848. var s0, s1, s2, s3, s4, s5, s6;
  849. s0 = peg$currPos;
  850. s1 = [];
  851. s2 = peg$parsews();
  852. while (s2 !== peg$FAILED) {
  853. s1.push(s2);
  854. s2 = peg$parsews();
  855. }
  856. if (s1 !== peg$FAILED) {
  857. if (input.charCodeAt(peg$currPos) === 46) {
  858. s2 = peg$c20;
  859. peg$currPos++;
  860. } else {
  861. s2 = peg$FAILED;
  862. if (peg$silentFails === 0) {
  863. peg$fail(peg$c21);
  864. }
  865. }
  866. if (s2 !== peg$FAILED) {
  867. s3 = [];
  868. s4 = peg$parsews();
  869. while (s4 !== peg$FAILED) {
  870. s3.push(s4);
  871. s4 = peg$parsews();
  872. }
  873. if (s3 !== peg$FAILED) {
  874. s4 = peg$parseexpression();
  875. if (s4 !== peg$FAILED) {
  876. s5 = [];
  877. s6 = peg$parsews();
  878. while (s6 !== peg$FAILED) {
  879. s5.push(s6);
  880. s6 = peg$parsews();
  881. }
  882. if (s5 !== peg$FAILED) {
  883. peg$savedPos = s0;
  884. s1 = peg$c29(s4);
  885. s0 = s1;
  886. } else {
  887. peg$currPos = s0;
  888. s0 = peg$FAILED;
  889. }
  890. } else {
  891. peg$currPos = s0;
  892. s0 = peg$FAILED;
  893. }
  894. } else {
  895. peg$currPos = s0;
  896. s0 = peg$FAILED;
  897. }
  898. } else {
  899. peg$currPos = s0;
  900. s0 = peg$FAILED;
  901. }
  902. } else {
  903. peg$currPos = s0;
  904. s0 = peg$FAILED;
  905. }
  906. return s0;
  907. }
  908. peg$result = peg$startRuleFunction();
  909. if (peg$result !== peg$FAILED && peg$currPos === input.length) {
  910. return peg$result;
  911. } else {
  912. if (peg$result !== peg$FAILED && peg$currPos < input.length) {
  913. peg$fail(peg$endExpectation());
  914. }
  915. throw peg$buildStructuredError(
  916. peg$maxFailExpected,
  917. peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
  918. peg$maxFailPos < input.length
  919. ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
  920. : peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
  921. );
  922. }
  923. }
  924. module.exports = {
  925. SyntaxError: peg$SyntaxError,
  926. parse: peg$parse
  927. };