Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

1835 рядки
40 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. /**
  4. * Returns a new set representing the union of a and b.
  5. */
  6. function union(a, b) {
  7. var s = new Set(a);
  8. addAll(s, b);
  9. return s;
  10. }
  11. /**
  12. * Adds all items from the set b to a.
  13. */
  14. function addAll(a, b) {
  15. for (var x of b) {
  16. a.add(x);
  17. }
  18. }
  19. /**
  20. * Returns whether two sets are equal
  21. */
  22. function equal(a, b) {
  23. if (a === b) return true;
  24. if (a.size !== b.size) return false;
  25. for (var x of a) {
  26. if (!b.has(x)) {
  27. return false;
  28. }
  29. }
  30. return true;
  31. }
  32. /**
  33. * Base AST node
  34. */
  35. class Node {
  36. constructor() {
  37. Object.defineProperty(this, 'followpos', {
  38. value: new Set()
  39. });
  40. }
  41. calcFollowpos() {
  42. for (var key in this) {
  43. if (this[key] instanceof Node) {
  44. this[key].calcFollowpos();
  45. }
  46. }
  47. }
  48. }
  49. /**
  50. * Represents a variable reference
  51. */
  52. class Variable extends Node {
  53. constructor(name) {
  54. super();
  55. this.name = name;
  56. }
  57. copy() {
  58. return new Variable(this.name);
  59. }
  60. }
  61. /**
  62. * Represents a comment
  63. */
  64. class Comment extends Node {
  65. constructor(value) {
  66. super();
  67. this.value = value;
  68. }
  69. }
  70. /**
  71. * Represents an assignment statement.
  72. * e.g. `variable = expression;`
  73. */
  74. class Assignment extends Node {
  75. constructor(variable, expression) {
  76. super();
  77. this.variable = variable;
  78. this.expression = expression;
  79. }
  80. }
  81. /**
  82. * Represents an alternation.
  83. * e.g. `a | b`
  84. */
  85. class Alternation extends Node {
  86. constructor(a, b) {
  87. super();
  88. this.a = a;
  89. this.b = b;
  90. }
  91. get nullable() {
  92. return this.a.nullable || this.b.nullable;
  93. }
  94. get firstpos() {
  95. return union(this.a.firstpos, this.b.firstpos);
  96. }
  97. get lastpos() {
  98. return union(this.a.lastpos, this.b.lastpos);
  99. }
  100. copy() {
  101. return new Alternation(this.a.copy(), this.b.copy());
  102. }
  103. }
  104. /**
  105. * Represents a concatenation, or chain.
  106. * e.g. `a b c`
  107. */
  108. class Concatenation extends Node {
  109. constructor(a, b) {
  110. super();
  111. this.a = a;
  112. this.b = b;
  113. }
  114. get nullable() {
  115. return this.a.nullable && this.b.nullable;
  116. }
  117. get firstpos() {
  118. var s = this.a.firstpos;
  119. if (this.a.nullable) {
  120. s = union(s, this.b.firstpos);
  121. }
  122. return s;
  123. }
  124. get lastpos() {
  125. var s = this.b.lastpos;
  126. if (this.b.nullable) {
  127. s = union(s, this.a.lastpos);
  128. }
  129. return s;
  130. }
  131. calcFollowpos() {
  132. super.calcFollowpos();
  133. for (var n of this.a.lastpos) {
  134. addAll(n.followpos, this.b.firstpos);
  135. }
  136. }
  137. copy() {
  138. return new Concatenation(this.a.copy(), this.b.copy());
  139. }
  140. }
  141. /**
  142. * Represents a repetition.
  143. * e.g. `a+`, `b*`, or `c?`
  144. */
  145. class Repeat extends Node {
  146. constructor(expression, op) {
  147. super();
  148. this.expression = expression;
  149. this.op = op;
  150. }
  151. get nullable() {
  152. return this.op === '*' || this.op === '?';
  153. }
  154. get firstpos() {
  155. return this.expression.firstpos;
  156. }
  157. get lastpos() {
  158. return this.expression.lastpos;
  159. }
  160. calcFollowpos() {
  161. super.calcFollowpos();
  162. if (this.op === '*' || this.op === '+') {
  163. for (var n of this.lastpos) {
  164. addAll(n.followpos, this.firstpos);
  165. }
  166. }
  167. }
  168. copy() {
  169. return new Repeat(this.expression.copy(), this.op);
  170. }
  171. }
  172. function buildRepetition(expression, min = 0, max = Infinity) {
  173. if (min < 0 || min > max) {
  174. throw new Error("Invalid repetition range: ".concat(min, " ").concat(max));
  175. }
  176. var res = null;
  177. for (var i = 0; i < min; i++) {
  178. res = concat(res, expression.copy());
  179. }
  180. if (max === Infinity) {
  181. res = concat(res, new Repeat(expression.copy(), '*'));
  182. } else {
  183. for (var _i = min; _i < max; _i++) {
  184. res = concat(res, new Repeat(expression.copy(), '?'));
  185. }
  186. }
  187. return res;
  188. }
  189. function concat(a, b) {
  190. if (!a) {
  191. return b;
  192. }
  193. return new Concatenation(a, b);
  194. }
  195. /**
  196. * Base class for leaf nodes
  197. */
  198. class Leaf extends Node {
  199. get nullable() {
  200. return false;
  201. }
  202. get firstpos() {
  203. return new Set([this]);
  204. }
  205. get lastpos() {
  206. return new Set([this]);
  207. }
  208. }
  209. /**
  210. * Represents a literal value, e.g. a number
  211. */
  212. class Literal extends Leaf {
  213. constructor(value) {
  214. super();
  215. this.value = value;
  216. }
  217. copy() {
  218. return new Literal(this.value);
  219. }
  220. }
  221. /**
  222. * Marks the end of an expression
  223. */
  224. class EndMarker extends Leaf {}
  225. /**
  226. * Represents a tag
  227. * e.g. `a:(a b)`
  228. */
  229. class Tag extends Leaf {
  230. constructor(name) {
  231. super();
  232. this.name = name;
  233. }
  234. get nullable() {
  235. return true;
  236. }
  237. copy() {
  238. return new Tag(this.name);
  239. }
  240. }
  241. var nodes = /*#__PURE__*/Object.freeze({
  242. Node: Node,
  243. Variable: Variable,
  244. Comment: Comment,
  245. Assignment: Assignment,
  246. Alternation: Alternation,
  247. Concatenation: Concatenation,
  248. Repeat: Repeat,
  249. buildRepetition: buildRepetition,
  250. Literal: Literal,
  251. EndMarker: EndMarker,
  252. Tag: Tag
  253. });
  254. function peg$subclass(child, parent) {
  255. function ctor() {
  256. this.constructor = child;
  257. }
  258. ctor.prototype = parent.prototype;
  259. child.prototype = new ctor();
  260. }
  261. function peg$SyntaxError(message, expected, found, location) {
  262. this.message = message;
  263. this.expected = expected;
  264. this.found = found;
  265. this.location = location;
  266. this.name = "SyntaxError";
  267. if (typeof Error.captureStackTrace === "function") {
  268. Error.captureStackTrace(this, peg$SyntaxError);
  269. }
  270. }
  271. peg$subclass(peg$SyntaxError, Error);
  272. peg$SyntaxError.buildMessage = function (expected, found) {
  273. var DESCRIBE_EXPECTATION_FNS = {
  274. literal: function (expectation) {
  275. return "\"" + literalEscape(expectation.text) + "\"";
  276. },
  277. "class": function (expectation) {
  278. var escapedParts = "",
  279. i;
  280. for (i = 0; i < expectation.parts.length; i++) {
  281. escapedParts += expectation.parts[i] instanceof Array ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]);
  282. }
  283. return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
  284. },
  285. any: function (expectation) {
  286. return "any character";
  287. },
  288. end: function (expectation) {
  289. return "end of input";
  290. },
  291. other: function (expectation) {
  292. return expectation.description;
  293. }
  294. };
  295. function hex(ch) {
  296. return ch.charCodeAt(0).toString(16).toUpperCase();
  297. }
  298. function literalEscape(s) {
  299. return s.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
  300. return '\\x0' + hex(ch);
  301. }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
  302. return '\\x' + hex(ch);
  303. });
  304. }
  305. function classEscape(s) {
  306. return s.replace(/\\/g, '\\\\').replace(/\]/g, '\\]').replace(/\^/g, '\\^').replace(/-/g, '\\-').replace(/\0/g, '\\0').replace(/\t/g, '\\t').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/[\x00-\x0F]/g, function (ch) {
  307. return '\\x0' + hex(ch);
  308. }).replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
  309. return '\\x' + hex(ch);
  310. });
  311. }
  312. function describeExpectation(expectation) {
  313. return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
  314. }
  315. function describeExpected(expected) {
  316. var descriptions = new Array(expected.length),
  317. i,
  318. j;
  319. for (i = 0; i < expected.length; i++) {
  320. descriptions[i] = describeExpectation(expected[i]);
  321. }
  322. descriptions.sort();
  323. if (descriptions.length > 0) {
  324. for (i = 1, j = 1; i < descriptions.length; i++) {
  325. if (descriptions[i - 1] !== descriptions[i]) {
  326. descriptions[j] = descriptions[i];
  327. j++;
  328. }
  329. }
  330. descriptions.length = j;
  331. }
  332. switch (descriptions.length) {
  333. case 1:
  334. return descriptions[0];
  335. case 2:
  336. return descriptions[0] + " or " + descriptions[1];
  337. default:
  338. return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
  339. }
  340. }
  341. function describeFound(found) {
  342. return found ? "\"" + literalEscape(found) + "\"" : "end of input";
  343. }
  344. return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
  345. };
  346. function peg$parse(input, options) {
  347. options = options !== void 0 ? options : {};
  348. var peg$FAILED = {},
  349. peg$startRuleFunctions = {
  350. rules: peg$parserules
  351. },
  352. peg$startRuleFunction = peg$parserules,
  353. peg$c0 = function (s) {
  354. return s;
  355. },
  356. peg$c1 = "#",
  357. peg$c2 = peg$literalExpectation("#", false),
  358. peg$c3 = /^[^\r\n]/,
  359. peg$c4 = peg$classExpectation(["\r", "\n"], true, false),
  360. peg$c5 = /^[\r\n]/,
  361. peg$c6 = peg$classExpectation(["\r", "\n"], false, false),
  362. peg$c7 = function (v) {
  363. return new n.Comment(v.join(''));
  364. },
  365. peg$c8 = "=",
  366. peg$c9 = peg$literalExpectation("=", false),
  367. peg$c10 = ";",
  368. peg$c11 = peg$literalExpectation(";", false),
  369. peg$c12 = function (v, e) {
  370. return new n.Assignment(v, e);
  371. },
  372. peg$c13 = function (v) {
  373. return new n.Variable(v);
  374. },
  375. peg$c14 = "|",
  376. peg$c15 = peg$literalExpectation("|", false),
  377. peg$c16 = function (a, b) {
  378. return new n.Alternation(a, b);
  379. },
  380. peg$c17 = function (a, b) {
  381. return new n.Concatenation(a, b);
  382. },
  383. peg$c18 = ":",
  384. peg$c19 = peg$literalExpectation(":", false),
  385. peg$c20 = function (t, e) {
  386. return new n.Concatenation(e, new n.Tag(t));
  387. },
  388. peg$c21 = "*",
  389. peg$c22 = peg$literalExpectation("*", false),
  390. peg$c23 = function (t) {
  391. return new n.Repeat(t, '*');
  392. },
  393. peg$c24 = "?",
  394. peg$c25 = peg$literalExpectation("?", false),
  395. peg$c26 = function (t) {
  396. return new n.Repeat(t, '?');
  397. },
  398. peg$c27 = "+",
  399. peg$c28 = peg$literalExpectation("+", false),
  400. peg$c29 = function (t) {
  401. return new n.Repeat(t, '+');
  402. },
  403. peg$c30 = "{",
  404. peg$c31 = peg$literalExpectation("{", false),
  405. peg$c32 = "}",
  406. peg$c33 = peg$literalExpectation("}", false),
  407. peg$c34 = function (t, m) {
  408. return n.buildRepetition(t, m, m);
  409. },
  410. peg$c35 = ",",
  411. peg$c36 = peg$literalExpectation(",", false),
  412. peg$c37 = function (t, min) {
  413. return n.buildRepetition(t, min, Infinity);
  414. },
  415. peg$c38 = function (t, max) {
  416. return n.buildRepetition(t, 0, max);
  417. },
  418. peg$c39 = function (t, min, max) {
  419. return n.buildRepetition(t, min, max);
  420. },
  421. peg$c40 = function (x) {
  422. return new n.Literal(x);
  423. },
  424. peg$c41 = "(",
  425. peg$c42 = peg$literalExpectation("(", false),
  426. peg$c43 = ")",
  427. peg$c44 = peg$literalExpectation(")", false),
  428. peg$c45 = function (e) {
  429. return e;
  430. },
  431. peg$c47 = function (a, b) {
  432. return a + b.join('');
  433. },
  434. peg$c48 = "_",
  435. peg$c49 = peg$literalExpectation("_", false),
  436. peg$c50 = /^[a-zA-Z]/,
  437. peg$c51 = peg$classExpectation([["a", "z"], ["A", "Z"]], false, false),
  438. peg$c52 = /^[0-9]/,
  439. peg$c53 = peg$classExpectation([["0", "9"]], false, false),
  440. peg$c54 = function (num) {
  441. return parseInt(num.join(''));
  442. },
  443. peg$c55 = /^[ \t\r\n]/,
  444. peg$c56 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false),
  445. peg$currPos = 0,
  446. peg$posDetailsCache = [{
  447. line: 1,
  448. column: 1
  449. }],
  450. peg$maxFailPos = 0,
  451. peg$maxFailExpected = [],
  452. peg$result;
  453. if ("startRule" in options) {
  454. if (!(options.startRule in peg$startRuleFunctions)) {
  455. throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
  456. }
  457. peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
  458. }
  459. function peg$literalExpectation(text, ignoreCase) {
  460. return {
  461. type: "literal",
  462. text: text,
  463. ignoreCase: ignoreCase
  464. };
  465. }
  466. function peg$classExpectation(parts, inverted, ignoreCase) {
  467. return {
  468. type: "class",
  469. parts: parts,
  470. inverted: inverted,
  471. ignoreCase: ignoreCase
  472. };
  473. }
  474. function peg$endExpectation() {
  475. return {
  476. type: "end"
  477. };
  478. }
  479. function peg$computePosDetails(pos) {
  480. var details = peg$posDetailsCache[pos],
  481. p;
  482. if (details) {
  483. return details;
  484. } else {
  485. p = pos - 1;
  486. while (!peg$posDetailsCache[p]) {
  487. p--;
  488. }
  489. details = peg$posDetailsCache[p];
  490. details = {
  491. line: details.line,
  492. column: details.column
  493. };
  494. while (p < pos) {
  495. if (input.charCodeAt(p) === 10) {
  496. details.line++;
  497. details.column = 1;
  498. } else {
  499. details.column++;
  500. }
  501. p++;
  502. }
  503. peg$posDetailsCache[pos] = details;
  504. return details;
  505. }
  506. }
  507. function peg$computeLocation(startPos, endPos) {
  508. var startPosDetails = peg$computePosDetails(startPos),
  509. endPosDetails = peg$computePosDetails(endPos);
  510. return {
  511. start: {
  512. offset: startPos,
  513. line: startPosDetails.line,
  514. column: startPosDetails.column
  515. },
  516. end: {
  517. offset: endPos,
  518. line: endPosDetails.line,
  519. column: endPosDetails.column
  520. }
  521. };
  522. }
  523. function peg$fail(expected) {
  524. if (peg$currPos < peg$maxFailPos) {
  525. return;
  526. }
  527. if (peg$currPos > peg$maxFailPos) {
  528. peg$maxFailPos = peg$currPos;
  529. peg$maxFailExpected = [];
  530. }
  531. peg$maxFailExpected.push(expected);
  532. }
  533. function peg$buildStructuredError(expected, found, location) {
  534. return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
  535. }
  536. function peg$parserules() {
  537. var s0, s1;
  538. s0 = [];
  539. s1 = peg$parsestatement();
  540. if (s1 !== peg$FAILED) {
  541. while (s1 !== peg$FAILED) {
  542. s0.push(s1);
  543. s1 = peg$parsestatement();
  544. }
  545. } else {
  546. s0 = peg$FAILED;
  547. }
  548. return s0;
  549. }
  550. function peg$parsestatement() {
  551. var s0, s1, s2;
  552. s0 = peg$currPos;
  553. s1 = peg$parsestatement_type();
  554. if (s1 !== peg$FAILED) {
  555. s2 = peg$parse_();
  556. if (s2 !== peg$FAILED) {
  557. s1 = peg$c0(s1);
  558. s0 = s1;
  559. } else {
  560. peg$currPos = s0;
  561. s0 = peg$FAILED;
  562. }
  563. } else {
  564. peg$currPos = s0;
  565. s0 = peg$FAILED;
  566. }
  567. return s0;
  568. }
  569. function peg$parsestatement_type() {
  570. var s0;
  571. s0 = peg$parseassignment();
  572. if (s0 === peg$FAILED) {
  573. s0 = peg$parsecomment();
  574. }
  575. return s0;
  576. }
  577. function peg$parsecomment() {
  578. var s0, s1, s2, s3;
  579. s0 = peg$currPos;
  580. if (input.charCodeAt(peg$currPos) === 35) {
  581. s1 = peg$c1;
  582. peg$currPos++;
  583. } else {
  584. s1 = peg$FAILED;
  585. {
  586. peg$fail(peg$c2);
  587. }
  588. }
  589. if (s1 !== peg$FAILED) {
  590. s2 = [];
  591. if (peg$c3.test(input.charAt(peg$currPos))) {
  592. s3 = input.charAt(peg$currPos);
  593. peg$currPos++;
  594. } else {
  595. s3 = peg$FAILED;
  596. {
  597. peg$fail(peg$c4);
  598. }
  599. }
  600. while (s3 !== peg$FAILED) {
  601. s2.push(s3);
  602. if (peg$c3.test(input.charAt(peg$currPos))) {
  603. s3 = input.charAt(peg$currPos);
  604. peg$currPos++;
  605. } else {
  606. s3 = peg$FAILED;
  607. {
  608. peg$fail(peg$c4);
  609. }
  610. }
  611. }
  612. if (s2 !== peg$FAILED) {
  613. if (peg$c5.test(input.charAt(peg$currPos))) {
  614. s3 = input.charAt(peg$currPos);
  615. peg$currPos++;
  616. } else {
  617. s3 = peg$FAILED;
  618. {
  619. peg$fail(peg$c6);
  620. }
  621. }
  622. if (s3 !== peg$FAILED) {
  623. s1 = peg$c7(s2);
  624. s0 = s1;
  625. } else {
  626. peg$currPos = s0;
  627. s0 = peg$FAILED;
  628. }
  629. } else {
  630. peg$currPos = s0;
  631. s0 = peg$FAILED;
  632. }
  633. } else {
  634. peg$currPos = s0;
  635. s0 = peg$FAILED;
  636. }
  637. return s0;
  638. }
  639. function peg$parseassignment() {
  640. var s0, s1, s2, s3, s4, s5, s6, s7;
  641. s0 = peg$currPos;
  642. s1 = peg$parsevariable();
  643. if (s1 !== peg$FAILED) {
  644. s2 = peg$parse_();
  645. if (s2 !== peg$FAILED) {
  646. if (input.charCodeAt(peg$currPos) === 61) {
  647. s3 = peg$c8;
  648. peg$currPos++;
  649. } else {
  650. s3 = peg$FAILED;
  651. {
  652. peg$fail(peg$c9);
  653. }
  654. }
  655. if (s3 !== peg$FAILED) {
  656. s4 = peg$parse_();
  657. if (s4 !== peg$FAILED) {
  658. s5 = peg$parsealternation();
  659. if (s5 !== peg$FAILED) {
  660. s6 = peg$parse_();
  661. if (s6 !== peg$FAILED) {
  662. if (input.charCodeAt(peg$currPos) === 59) {
  663. s7 = peg$c10;
  664. peg$currPos++;
  665. } else {
  666. s7 = peg$FAILED;
  667. {
  668. peg$fail(peg$c11);
  669. }
  670. }
  671. if (s7 !== peg$FAILED) {
  672. s1 = peg$c12(s1, s5);
  673. s0 = s1;
  674. } else {
  675. peg$currPos = s0;
  676. s0 = peg$FAILED;
  677. }
  678. } else {
  679. peg$currPos = s0;
  680. s0 = peg$FAILED;
  681. }
  682. } else {
  683. peg$currPos = s0;
  684. s0 = peg$FAILED;
  685. }
  686. } else {
  687. peg$currPos = s0;
  688. s0 = peg$FAILED;
  689. }
  690. } else {
  691. peg$currPos = s0;
  692. s0 = peg$FAILED;
  693. }
  694. } else {
  695. peg$currPos = s0;
  696. s0 = peg$FAILED;
  697. }
  698. } else {
  699. peg$currPos = s0;
  700. s0 = peg$FAILED;
  701. }
  702. return s0;
  703. }
  704. function peg$parsevariable() {
  705. var s0, s1;
  706. s0 = peg$currPos;
  707. s1 = peg$parsename();
  708. if (s1 !== peg$FAILED) {
  709. s1 = peg$c13(s1);
  710. }
  711. s0 = s1;
  712. return s0;
  713. }
  714. function peg$parsealternation() {
  715. var s0, s1, s2, s3, s4, s5;
  716. s0 = peg$currPos;
  717. s1 = peg$parseconcatenation();
  718. if (s1 !== peg$FAILED) {
  719. s2 = peg$parse_();
  720. if (s2 !== peg$FAILED) {
  721. if (input.charCodeAt(peg$currPos) === 124) {
  722. s3 = peg$c14;
  723. peg$currPos++;
  724. } else {
  725. s3 = peg$FAILED;
  726. {
  727. peg$fail(peg$c15);
  728. }
  729. }
  730. if (s3 !== peg$FAILED) {
  731. s4 = peg$parse_();
  732. if (s4 !== peg$FAILED) {
  733. s5 = peg$parsealternation();
  734. if (s5 !== peg$FAILED) {
  735. s1 = peg$c16(s1, s5);
  736. s0 = s1;
  737. } else {
  738. peg$currPos = s0;
  739. s0 = peg$FAILED;
  740. }
  741. } else {
  742. peg$currPos = s0;
  743. s0 = peg$FAILED;
  744. }
  745. } else {
  746. peg$currPos = s0;
  747. s0 = peg$FAILED;
  748. }
  749. } else {
  750. peg$currPos = s0;
  751. s0 = peg$FAILED;
  752. }
  753. } else {
  754. peg$currPos = s0;
  755. s0 = peg$FAILED;
  756. }
  757. if (s0 === peg$FAILED) {
  758. s0 = peg$parseconcatenation();
  759. }
  760. return s0;
  761. }
  762. function peg$parseconcatenation() {
  763. var s0, s1, s2, s3;
  764. s0 = peg$currPos;
  765. s1 = peg$parserepeat();
  766. if (s1 !== peg$FAILED) {
  767. s2 = peg$parse_();
  768. if (s2 !== peg$FAILED) {
  769. s3 = peg$parseconcatenation();
  770. if (s3 !== peg$FAILED) {
  771. s1 = peg$c17(s1, s3);
  772. s0 = s1;
  773. } else {
  774. peg$currPos = s0;
  775. s0 = peg$FAILED;
  776. }
  777. } else {
  778. peg$currPos = s0;
  779. s0 = peg$FAILED;
  780. }
  781. } else {
  782. peg$currPos = s0;
  783. s0 = peg$FAILED;
  784. }
  785. if (s0 === peg$FAILED) {
  786. s0 = peg$parserepeat();
  787. }
  788. return s0;
  789. }
  790. function peg$parserepeat() {
  791. var s0, s1, s2, s3, s4, s5, s6;
  792. s0 = peg$currPos;
  793. s1 = peg$parsename();
  794. if (s1 !== peg$FAILED) {
  795. if (input.charCodeAt(peg$currPos) === 58) {
  796. s2 = peg$c18;
  797. peg$currPos++;
  798. } else {
  799. s2 = peg$FAILED;
  800. {
  801. peg$fail(peg$c19);
  802. }
  803. }
  804. if (s2 !== peg$FAILED) {
  805. s3 = peg$parserepeat();
  806. if (s3 !== peg$FAILED) {
  807. s1 = peg$c20(s1, s3);
  808. s0 = s1;
  809. } else {
  810. peg$currPos = s0;
  811. s0 = peg$FAILED;
  812. }
  813. } else {
  814. peg$currPos = s0;
  815. s0 = peg$FAILED;
  816. }
  817. } else {
  818. peg$currPos = s0;
  819. s0 = peg$FAILED;
  820. }
  821. if (s0 === peg$FAILED) {
  822. s0 = peg$currPos;
  823. s1 = peg$parseterm();
  824. if (s1 !== peg$FAILED) {
  825. if (input.charCodeAt(peg$currPos) === 42) {
  826. s2 = peg$c21;
  827. peg$currPos++;
  828. } else {
  829. s2 = peg$FAILED;
  830. {
  831. peg$fail(peg$c22);
  832. }
  833. }
  834. if (s2 !== peg$FAILED) {
  835. s1 = peg$c23(s1);
  836. s0 = s1;
  837. } else {
  838. peg$currPos = s0;
  839. s0 = peg$FAILED;
  840. }
  841. } else {
  842. peg$currPos = s0;
  843. s0 = peg$FAILED;
  844. }
  845. if (s0 === peg$FAILED) {
  846. s0 = peg$currPos;
  847. s1 = peg$parseterm();
  848. if (s1 !== peg$FAILED) {
  849. if (input.charCodeAt(peg$currPos) === 63) {
  850. s2 = peg$c24;
  851. peg$currPos++;
  852. } else {
  853. s2 = peg$FAILED;
  854. {
  855. peg$fail(peg$c25);
  856. }
  857. }
  858. if (s2 !== peg$FAILED) {
  859. s1 = peg$c26(s1);
  860. s0 = s1;
  861. } else {
  862. peg$currPos = s0;
  863. s0 = peg$FAILED;
  864. }
  865. } else {
  866. peg$currPos = s0;
  867. s0 = peg$FAILED;
  868. }
  869. if (s0 === peg$FAILED) {
  870. s0 = peg$currPos;
  871. s1 = peg$parseterm();
  872. if (s1 !== peg$FAILED) {
  873. if (input.charCodeAt(peg$currPos) === 43) {
  874. s2 = peg$c27;
  875. peg$currPos++;
  876. } else {
  877. s2 = peg$FAILED;
  878. {
  879. peg$fail(peg$c28);
  880. }
  881. }
  882. if (s2 !== peg$FAILED) {
  883. s1 = peg$c29(s1);
  884. s0 = s1;
  885. } else {
  886. peg$currPos = s0;
  887. s0 = peg$FAILED;
  888. }
  889. } else {
  890. peg$currPos = s0;
  891. s0 = peg$FAILED;
  892. }
  893. if (s0 === peg$FAILED) {
  894. s0 = peg$currPos;
  895. s1 = peg$parseterm();
  896. if (s1 !== peg$FAILED) {
  897. if (input.charCodeAt(peg$currPos) === 123) {
  898. s2 = peg$c30;
  899. peg$currPos++;
  900. } else {
  901. s2 = peg$FAILED;
  902. {
  903. peg$fail(peg$c31);
  904. }
  905. }
  906. if (s2 !== peg$FAILED) {
  907. s3 = peg$parsenumber();
  908. if (s3 !== peg$FAILED) {
  909. if (input.charCodeAt(peg$currPos) === 125) {
  910. s4 = peg$c32;
  911. peg$currPos++;
  912. } else {
  913. s4 = peg$FAILED;
  914. {
  915. peg$fail(peg$c33);
  916. }
  917. }
  918. if (s4 !== peg$FAILED) {
  919. s1 = peg$c34(s1, s3);
  920. s0 = s1;
  921. } else {
  922. peg$currPos = s0;
  923. s0 = peg$FAILED;
  924. }
  925. } else {
  926. peg$currPos = s0;
  927. s0 = peg$FAILED;
  928. }
  929. } else {
  930. peg$currPos = s0;
  931. s0 = peg$FAILED;
  932. }
  933. } else {
  934. peg$currPos = s0;
  935. s0 = peg$FAILED;
  936. }
  937. if (s0 === peg$FAILED) {
  938. s0 = peg$currPos;
  939. s1 = peg$parseterm();
  940. if (s1 !== peg$FAILED) {
  941. if (input.charCodeAt(peg$currPos) === 123) {
  942. s2 = peg$c30;
  943. peg$currPos++;
  944. } else {
  945. s2 = peg$FAILED;
  946. {
  947. peg$fail(peg$c31);
  948. }
  949. }
  950. if (s2 !== peg$FAILED) {
  951. s3 = peg$parsenumber();
  952. if (s3 !== peg$FAILED) {
  953. if (input.charCodeAt(peg$currPos) === 44) {
  954. s4 = peg$c35;
  955. peg$currPos++;
  956. } else {
  957. s4 = peg$FAILED;
  958. {
  959. peg$fail(peg$c36);
  960. }
  961. }
  962. if (s4 !== peg$FAILED) {
  963. if (input.charCodeAt(peg$currPos) === 125) {
  964. s5 = peg$c32;
  965. peg$currPos++;
  966. } else {
  967. s5 = peg$FAILED;
  968. {
  969. peg$fail(peg$c33);
  970. }
  971. }
  972. if (s5 !== peg$FAILED) {
  973. s1 = peg$c37(s1, s3);
  974. s0 = s1;
  975. } else {
  976. peg$currPos = s0;
  977. s0 = peg$FAILED;
  978. }
  979. } else {
  980. peg$currPos = s0;
  981. s0 = peg$FAILED;
  982. }
  983. } else {
  984. peg$currPos = s0;
  985. s0 = peg$FAILED;
  986. }
  987. } else {
  988. peg$currPos = s0;
  989. s0 = peg$FAILED;
  990. }
  991. } else {
  992. peg$currPos = s0;
  993. s0 = peg$FAILED;
  994. }
  995. if (s0 === peg$FAILED) {
  996. s0 = peg$currPos;
  997. s1 = peg$parseterm();
  998. if (s1 !== peg$FAILED) {
  999. if (input.charCodeAt(peg$currPos) === 123) {
  1000. s2 = peg$c30;
  1001. peg$currPos++;
  1002. } else {
  1003. s2 = peg$FAILED;
  1004. {
  1005. peg$fail(peg$c31);
  1006. }
  1007. }
  1008. if (s2 !== peg$FAILED) {
  1009. if (input.charCodeAt(peg$currPos) === 44) {
  1010. s3 = peg$c35;
  1011. peg$currPos++;
  1012. } else {
  1013. s3 = peg$FAILED;
  1014. {
  1015. peg$fail(peg$c36);
  1016. }
  1017. }
  1018. if (s3 !== peg$FAILED) {
  1019. s4 = peg$parsenumber();
  1020. if (s4 !== peg$FAILED) {
  1021. if (input.charCodeAt(peg$currPos) === 125) {
  1022. s5 = peg$c32;
  1023. peg$currPos++;
  1024. } else {
  1025. s5 = peg$FAILED;
  1026. {
  1027. peg$fail(peg$c33);
  1028. }
  1029. }
  1030. if (s5 !== peg$FAILED) {
  1031. s1 = peg$c38(s1, s4);
  1032. s0 = s1;
  1033. } else {
  1034. peg$currPos = s0;
  1035. s0 = peg$FAILED;
  1036. }
  1037. } else {
  1038. peg$currPos = s0;
  1039. s0 = peg$FAILED;
  1040. }
  1041. } else {
  1042. peg$currPos = s0;
  1043. s0 = peg$FAILED;
  1044. }
  1045. } else {
  1046. peg$currPos = s0;
  1047. s0 = peg$FAILED;
  1048. }
  1049. } else {
  1050. peg$currPos = s0;
  1051. s0 = peg$FAILED;
  1052. }
  1053. if (s0 === peg$FAILED) {
  1054. s0 = peg$currPos;
  1055. s1 = peg$parseterm();
  1056. if (s1 !== peg$FAILED) {
  1057. if (input.charCodeAt(peg$currPos) === 123) {
  1058. s2 = peg$c30;
  1059. peg$currPos++;
  1060. } else {
  1061. s2 = peg$FAILED;
  1062. {
  1063. peg$fail(peg$c31);
  1064. }
  1065. }
  1066. if (s2 !== peg$FAILED) {
  1067. s3 = peg$parsenumber();
  1068. if (s3 !== peg$FAILED) {
  1069. if (input.charCodeAt(peg$currPos) === 44) {
  1070. s4 = peg$c35;
  1071. peg$currPos++;
  1072. } else {
  1073. s4 = peg$FAILED;
  1074. {
  1075. peg$fail(peg$c36);
  1076. }
  1077. }
  1078. if (s4 !== peg$FAILED) {
  1079. s5 = peg$parsenumber();
  1080. if (s5 !== peg$FAILED) {
  1081. if (input.charCodeAt(peg$currPos) === 125) {
  1082. s6 = peg$c32;
  1083. peg$currPos++;
  1084. } else {
  1085. s6 = peg$FAILED;
  1086. {
  1087. peg$fail(peg$c33);
  1088. }
  1089. }
  1090. if (s6 !== peg$FAILED) {
  1091. s1 = peg$c39(s1, s3, s5);
  1092. s0 = s1;
  1093. } else {
  1094. peg$currPos = s0;
  1095. s0 = peg$FAILED;
  1096. }
  1097. } else {
  1098. peg$currPos = s0;
  1099. s0 = peg$FAILED;
  1100. }
  1101. } else {
  1102. peg$currPos = s0;
  1103. s0 = peg$FAILED;
  1104. }
  1105. } else {
  1106. peg$currPos = s0;
  1107. s0 = peg$FAILED;
  1108. }
  1109. } else {
  1110. peg$currPos = s0;
  1111. s0 = peg$FAILED;
  1112. }
  1113. } else {
  1114. peg$currPos = s0;
  1115. s0 = peg$FAILED;
  1116. }
  1117. if (s0 === peg$FAILED) {
  1118. s0 = peg$parseterm();
  1119. }
  1120. }
  1121. }
  1122. }
  1123. }
  1124. }
  1125. }
  1126. }
  1127. return s0;
  1128. }
  1129. function peg$parseterm() {
  1130. var s0, s1, s2, s3;
  1131. s0 = peg$parsevariable();
  1132. if (s0 === peg$FAILED) {
  1133. s0 = peg$currPos;
  1134. s1 = peg$parsenumber();
  1135. if (s1 !== peg$FAILED) {
  1136. s1 = peg$c40(s1);
  1137. }
  1138. s0 = s1;
  1139. if (s0 === peg$FAILED) {
  1140. s0 = peg$currPos;
  1141. if (input.charCodeAt(peg$currPos) === 40) {
  1142. s1 = peg$c41;
  1143. peg$currPos++;
  1144. } else {
  1145. s1 = peg$FAILED;
  1146. {
  1147. peg$fail(peg$c42);
  1148. }
  1149. }
  1150. if (s1 !== peg$FAILED) {
  1151. s2 = peg$parsealternation();
  1152. if (s2 !== peg$FAILED) {
  1153. if (input.charCodeAt(peg$currPos) === 41) {
  1154. s3 = peg$c43;
  1155. peg$currPos++;
  1156. } else {
  1157. s3 = peg$FAILED;
  1158. {
  1159. peg$fail(peg$c44);
  1160. }
  1161. }
  1162. if (s3 !== peg$FAILED) {
  1163. s1 = peg$c45(s2);
  1164. s0 = s1;
  1165. } else {
  1166. peg$currPos = s0;
  1167. s0 = peg$FAILED;
  1168. }
  1169. } else {
  1170. peg$currPos = s0;
  1171. s0 = peg$FAILED;
  1172. }
  1173. } else {
  1174. peg$currPos = s0;
  1175. s0 = peg$FAILED;
  1176. }
  1177. }
  1178. }
  1179. return s0;
  1180. }
  1181. function peg$parsename() {
  1182. var s0, s1, s2, s3;
  1183. s0 = peg$currPos;
  1184. s1 = peg$parsename_start_char();
  1185. if (s1 !== peg$FAILED) {
  1186. s2 = [];
  1187. s3 = peg$parsename_char();
  1188. while (s3 !== peg$FAILED) {
  1189. s2.push(s3);
  1190. s3 = peg$parsename_char();
  1191. }
  1192. if (s2 !== peg$FAILED) {
  1193. s1 = peg$c47(s1, s2);
  1194. s0 = s1;
  1195. } else {
  1196. peg$currPos = s0;
  1197. s0 = peg$FAILED;
  1198. }
  1199. } else {
  1200. peg$currPos = s0;
  1201. s0 = peg$FAILED;
  1202. }
  1203. return s0;
  1204. }
  1205. function peg$parsename_start_char() {
  1206. var s0;
  1207. if (input.charCodeAt(peg$currPos) === 95) {
  1208. s0 = peg$c48;
  1209. peg$currPos++;
  1210. } else {
  1211. s0 = peg$FAILED;
  1212. {
  1213. peg$fail(peg$c49);
  1214. }
  1215. }
  1216. if (s0 === peg$FAILED) {
  1217. if (peg$c50.test(input.charAt(peg$currPos))) {
  1218. s0 = input.charAt(peg$currPos);
  1219. peg$currPos++;
  1220. } else {
  1221. s0 = peg$FAILED;
  1222. {
  1223. peg$fail(peg$c51);
  1224. }
  1225. }
  1226. }
  1227. return s0;
  1228. }
  1229. function peg$parsename_char() {
  1230. var s0;
  1231. s0 = peg$parsename_start_char();
  1232. if (s0 === peg$FAILED) {
  1233. if (peg$c52.test(input.charAt(peg$currPos))) {
  1234. s0 = input.charAt(peg$currPos);
  1235. peg$currPos++;
  1236. } else {
  1237. s0 = peg$FAILED;
  1238. {
  1239. peg$fail(peg$c53);
  1240. }
  1241. }
  1242. }
  1243. return s0;
  1244. }
  1245. function peg$parsenumber() {
  1246. var s0, s1, s2;
  1247. s0 = peg$currPos;
  1248. s1 = [];
  1249. if (peg$c52.test(input.charAt(peg$currPos))) {
  1250. s2 = input.charAt(peg$currPos);
  1251. peg$currPos++;
  1252. } else {
  1253. s2 = peg$FAILED;
  1254. {
  1255. peg$fail(peg$c53);
  1256. }
  1257. }
  1258. if (s2 !== peg$FAILED) {
  1259. while (s2 !== peg$FAILED) {
  1260. s1.push(s2);
  1261. if (peg$c52.test(input.charAt(peg$currPos))) {
  1262. s2 = input.charAt(peg$currPos);
  1263. peg$currPos++;
  1264. } else {
  1265. s2 = peg$FAILED;
  1266. {
  1267. peg$fail(peg$c53);
  1268. }
  1269. }
  1270. }
  1271. } else {
  1272. s1 = peg$FAILED;
  1273. }
  1274. if (s1 !== peg$FAILED) {
  1275. s1 = peg$c54(s1);
  1276. }
  1277. s0 = s1;
  1278. return s0;
  1279. }
  1280. function peg$parse_() {
  1281. var s0, s1;
  1282. s0 = [];
  1283. if (peg$c55.test(input.charAt(peg$currPos))) {
  1284. s1 = input.charAt(peg$currPos);
  1285. peg$currPos++;
  1286. } else {
  1287. s1 = peg$FAILED;
  1288. {
  1289. peg$fail(peg$c56);
  1290. }
  1291. }
  1292. while (s1 !== peg$FAILED) {
  1293. s0.push(s1);
  1294. if (peg$c55.test(input.charAt(peg$currPos))) {
  1295. s1 = input.charAt(peg$currPos);
  1296. peg$currPos++;
  1297. } else {
  1298. s1 = peg$FAILED;
  1299. {
  1300. peg$fail(peg$c56);
  1301. }
  1302. }
  1303. }
  1304. return s0;
  1305. }
  1306. var n = nodes;
  1307. peg$result = peg$startRuleFunction();
  1308. if (peg$result !== peg$FAILED && peg$currPos === input.length) {
  1309. return peg$result;
  1310. } else {
  1311. if (peg$result !== peg$FAILED && peg$currPos < input.length) {
  1312. peg$fail(peg$endExpectation());
  1313. }
  1314. throw peg$buildStructuredError(peg$maxFailExpected, peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, peg$maxFailPos < input.length ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) : peg$computeLocation(peg$maxFailPos, peg$maxFailPos));
  1315. }
  1316. }
  1317. var grammar = {
  1318. SyntaxError: peg$SyntaxError,
  1319. parse: peg$parse
  1320. };
  1321. /**
  1322. * Processes a list of statements into a symbol table
  1323. */
  1324. class SymbolTable {
  1325. constructor(statements, externalSymbols = {}) {
  1326. this.variables = {};
  1327. this.symbols = {};
  1328. this.main = null;
  1329. this.size = 0;
  1330. this.addExternalSymbols(externalSymbols);
  1331. this.process(statements);
  1332. }
  1333. addExternalSymbols(externalSymbols) {
  1334. for (var key in externalSymbols) {
  1335. this.variables[key] = new Literal(externalSymbols[key]);
  1336. this.symbols[key] = externalSymbols[key];
  1337. this.size++;
  1338. }
  1339. }
  1340. process(statements) {
  1341. for (var statement of statements) {
  1342. if (statement instanceof Assignment) {
  1343. this.variables[statement.variable.name] = this.processExpression(statement.expression);
  1344. if (statement.expression instanceof Literal) {
  1345. this.symbols[statement.variable.name] = statement.expression.value;
  1346. this.size++;
  1347. }
  1348. }
  1349. }
  1350. this.main = this.variables.main;
  1351. if (!this.main) {
  1352. throw new Error('No main variable declaration found');
  1353. }
  1354. }
  1355. processExpression(expr) {
  1356. // Process children
  1357. for (var key in expr) {
  1358. if (expr[key] instanceof Node) {
  1359. expr[key] = this.processExpression(expr[key]);
  1360. }
  1361. } // Replace variable references with their values
  1362. if (expr instanceof Variable) {
  1363. var value = this.variables[expr.name];
  1364. if (value == null) throw new Error("Undeclared indentifier ".concat(expr.name));
  1365. expr = this.processExpression(value.copy());
  1366. }
  1367. return expr;
  1368. }
  1369. }
  1370. var END_MARKER = new EndMarker();
  1371. /**
  1372. * This is an implementation of the direct regular expression to DFA algorithm described
  1373. * in section 3.9.5 of "Compilers: Principles, Techniques, and Tools" by Aho,
  1374. * Lam, Sethi, and Ullman. http://dragonbook.stanford.edu
  1375. * There is a PDF of the book here:
  1376. * http://www.informatik.uni-bremen.de/agbkb/lehre/ccfl/Material/ALSUdragonbook.pdf
  1377. */
  1378. function buildDFA(root, numSymbols) {
  1379. root = new Concatenation(root, END_MARKER);
  1380. root.calcFollowpos();
  1381. var failState = new State(new Set(), numSymbols);
  1382. var initialState = new State(root.firstpos, numSymbols);
  1383. var dstates = [failState, initialState]; // while there is an unmarked state S in dstates
  1384. while (1) {
  1385. var s = null;
  1386. for (var j = 1; j < dstates.length; j++) {
  1387. if (!dstates[j].marked) {
  1388. s = dstates[j];
  1389. break;
  1390. }
  1391. }
  1392. if (s == null) {
  1393. break;
  1394. } // mark S
  1395. s.marked = true; // for each input symbol a
  1396. for (var a = 0; a < numSymbols; a++) {
  1397. // let U be the union of followpos(p) for all
  1398. // p in S that correspond to a
  1399. var u = new Set();
  1400. for (var p of s.positions) {
  1401. if (p instanceof Literal && p.value === a) {
  1402. addAll(u, p.followpos);
  1403. }
  1404. }
  1405. if (u.size === 0) {
  1406. continue;
  1407. } // if U is not in dstates
  1408. var ux = -1;
  1409. for (var i = 0; i < dstates.length; i++) {
  1410. if (equal(u, dstates[i].positions)) {
  1411. ux = i;
  1412. break;
  1413. }
  1414. }
  1415. if (ux === -1) {
  1416. // Add U as an unmarked state to dstates
  1417. dstates.push(new State(u, numSymbols));
  1418. ux = dstates.length - 1;
  1419. }
  1420. s.transitions[a] = ux;
  1421. }
  1422. }
  1423. return dstates;
  1424. }
  1425. class State {
  1426. constructor(positions, len) {
  1427. this.positions = positions;
  1428. this.transitions = new Uint16Array(len);
  1429. this.accepting = positions.has(END_MARKER);
  1430. this.marked = false;
  1431. this.tags = new Set();
  1432. for (var pos of positions) {
  1433. if (pos instanceof Tag) {
  1434. this.tags.add(pos.name);
  1435. }
  1436. }
  1437. }
  1438. }
  1439. var INITIAL_STATE = 1;
  1440. var FAIL_STATE = 0;
  1441. /**
  1442. * A StateMachine represents a deterministic finite automaton.
  1443. * It can perform matches over a sequence of values, similar to a regular expression.
  1444. */
  1445. class StateMachine {
  1446. constructor(dfa) {
  1447. this.stateTable = dfa.stateTable;
  1448. this.accepting = dfa.accepting;
  1449. this.tags = dfa.tags;
  1450. }
  1451. /**
  1452. * Returns an iterable object that yields pattern matches over the input sequence.
  1453. * Matches are of the form [startIndex, endIndex, tags].
  1454. */
  1455. match(str) {
  1456. var self = this;
  1457. return {
  1458. *[Symbol.iterator]() {
  1459. var state = INITIAL_STATE;
  1460. var startRun = null;
  1461. var lastAccepting = null;
  1462. var lastState = null;
  1463. for (var p = 0; p < str.length; p++) {
  1464. var c = str[p];
  1465. lastState = state;
  1466. state = self.stateTable[state][c];
  1467. if (state === FAIL_STATE) {
  1468. // yield the last match if any
  1469. if (startRun != null && lastAccepting != null && lastAccepting >= startRun) {
  1470. yield [startRun, lastAccepting, self.tags[lastState]];
  1471. } // reset the state as if we started over from the initial state
  1472. state = self.stateTable[INITIAL_STATE][c];
  1473. startRun = null;
  1474. } // start a run if not in the failure state
  1475. if (state !== FAIL_STATE && startRun == null) {
  1476. startRun = p;
  1477. } // if accepting, mark the potential match end
  1478. if (self.accepting[state]) {
  1479. lastAccepting = p;
  1480. } // reset the state to the initial state if we get into the failure state
  1481. if (state === FAIL_STATE) {
  1482. state = INITIAL_STATE;
  1483. }
  1484. } // yield the last match if any
  1485. if (startRun != null && lastAccepting != null && lastAccepting >= startRun) {
  1486. yield [startRun, lastAccepting, self.tags[state]];
  1487. }
  1488. }
  1489. };
  1490. }
  1491. /**
  1492. * For each match over the input sequence, action functions matching
  1493. * the tag definitions in the input pattern are called with the startIndex,
  1494. * endIndex, and sub-match sequence.
  1495. */
  1496. apply(str, actions) {
  1497. for (var [start, end, tags] of this.match(str)) {
  1498. for (var tag of tags) {
  1499. if (typeof actions[tag] === 'function') {
  1500. actions[tag](start, end, str.slice(start, end + 1));
  1501. }
  1502. }
  1503. }
  1504. }
  1505. }
  1506. function parse(string, externalSymbols) {
  1507. var ast = grammar.parse(string);
  1508. return new SymbolTable(ast, externalSymbols);
  1509. }
  1510. function build(symbolTable) {
  1511. var states = buildDFA(symbolTable.main, symbolTable.size);
  1512. return new StateMachine({
  1513. stateTable: states.map(s => Array.from(s.transitions)),
  1514. accepting: states.map(s => s.accepting),
  1515. tags: states.map(s => Array.from(s.tags))
  1516. });
  1517. }
  1518. function compile(string, externalSymbols) {
  1519. return build(parse(string, externalSymbols));
  1520. }
  1521. exports.build = build;
  1522. exports.default = compile;
  1523. exports.parse = parse;
  1524. //# sourceMappingURL=compile.js.map