UNPKG

100 kBJavaScriptView Raw
1var __commonJS = (callback, module2) => () => {
2 if (!module2) {
3 module2 = {exports: {}};
4 callback(module2.exports, module2);
5 }
6 return module2.exports;
7};
8
9// vendor/jison/util/typal.js
10var require_typal = __commonJS((exports2) => {
11 var typal2 = function() {
12 var create = Object.create || function(o2) {
13 function F() {
14 }
15 F.prototype = o2;
16 return new F();
17 };
18 var position = /^(before|after)/;
19 function layerMethod(k, fun) {
20 var pos = k.match(position)[0], key = k.replace(position, ""), prop = this[key];
21 if (pos === "after") {
22 this[key] = function() {
23 var ret = prop.apply(this, arguments);
24 var args = [].slice.call(arguments);
25 args.splice(0, 0, ret);
26 fun.apply(this, args);
27 return ret;
28 };
29 } else if (pos === "before") {
30 this[key] = function() {
31 fun.apply(this, arguments);
32 var ret = prop.apply(this, arguments);
33 return ret;
34 };
35 }
36 }
37 function typal_mix() {
38 var self2 = this;
39 for (var i = 0, o2, k; i < arguments.length; i++) {
40 o2 = arguments[i];
41 if (!o2)
42 continue;
43 if (Object.prototype.hasOwnProperty.call(o2, "constructor"))
44 this.constructor = o2.constructor;
45 if (Object.prototype.hasOwnProperty.call(o2, "toString"))
46 this.toString = o2.toString;
47 for (k in o2) {
48 if (Object.prototype.hasOwnProperty.call(o2, k)) {
49 if (k.match(position) && typeof this[k.replace(position, "")] === "function")
50 layerMethod.call(this, k, o2[k]);
51 else
52 this[k] = o2[k];
53 }
54 }
55 }
56 return this;
57 }
58 return {
59 mix: typal_mix,
60 beget: function typal_beget() {
61 return arguments.length ? typal_mix.apply(create(this), arguments) : create(this);
62 },
63 construct: function typal_construct() {
64 var o2 = typal_mix.apply(create(this), arguments);
65 var constructor = o2.constructor;
66 var Klass = o2.constructor = function() {
67 return constructor.apply(this, arguments);
68 };
69 Klass.prototype = o2;
70 Klass.mix = typal_mix;
71 return Klass;
72 },
73 constructor: function typal_constructor() {
74 return this;
75 }
76 };
77 }();
78 if (typeof exports2 !== "undefined")
79 exports2.typal = typal2;
80});
81
82// vendor/jison/util/set.js
83var require_set = __commonJS((exports2) => {
84 var typal2 = require_typal().typal;
85 var setMixin = {
86 constructor: function Set_constructor(set, raw) {
87 this._items = [];
88 if (set && set.constructor === Array)
89 this._items = raw ? set : set.slice(0);
90 else if (arguments.length)
91 this._items = [].slice.call(arguments, 0);
92 },
93 concat: function concat(setB) {
94 this._items.push.apply(this._items, setB._items || setB);
95 return this;
96 },
97 eq: function eq(set) {
98 return this._items.length === set._items.length && this.subset(set);
99 },
100 indexOf: function indexOf(item) {
101 if (item && item.eq) {
102 for (var k = 0; k < this._items.length; k++)
103 if (item.eq(this._items[k]))
104 return k;
105 return -1;
106 }
107 return this._items.indexOf(item);
108 },
109 union: function union(set) {
110 return new Set2(this._items).concat(this.complement(set));
111 },
112 intersection: function intersection(set) {
113 return this.filter(function(elm) {
114 return set.contains(elm);
115 });
116 },
117 complement: function complement(set) {
118 var that = this;
119 return set.filter(function sub_complement(elm) {
120 return !that.contains(elm);
121 });
122 },
123 subset: function subset(set) {
124 var cont = true;
125 for (var i = 0; i < this._items.length && cont; i++) {
126 cont = cont && set.contains(this._items[i]);
127 }
128 return cont;
129 },
130 superset: function superset(set) {
131 return set.subset(this);
132 },
133 joinSet: function joinSet(set) {
134 return this.concat(this.complement(set));
135 },
136 contains: function contains(item) {
137 return this.indexOf(item) !== -1;
138 },
139 item: function item(v, val) {
140 return this._items[v];
141 },
142 i: function i(v, val) {
143 return this._items[v];
144 },
145 first: function first() {
146 return this._items[0];
147 },
148 last: function last() {
149 return this._items[this._items.length - 1];
150 },
151 size: function size() {
152 return this._items.length;
153 },
154 isEmpty: function isEmpty() {
155 return this._items.length === 0;
156 },
157 copy: function copy() {
158 return new Set2(this._items);
159 },
160 toString: function toString() {
161 return this._items.toString();
162 }
163 };
164 "push shift unshift forEach some every join sort".split(" ").forEach(function(e, i) {
165 setMixin[e] = function() {
166 return Array.prototype[e].apply(this._items, arguments);
167 };
168 setMixin[e].name = e;
169 });
170 "filter slice map".split(" ").forEach(function(e, i) {
171 setMixin[e] = function() {
172 return new Set2(Array.prototype[e].apply(this._items, arguments), true);
173 };
174 setMixin[e].name = e;
175 });
176 var Set2 = typal2.construct(setMixin).mix({
177 union: function(a, b) {
178 var ar = {};
179 for (var k = a.length - 1; k >= 0; --k) {
180 ar[a[k]] = true;
181 }
182 for (var i = b.length - 1; i >= 0; --i) {
183 if (!ar[b[i]]) {
184 a.push(b[i]);
185 }
186 }
187 return a;
188 }
189 });
190 if (typeof exports2 !== "undefined")
191 exports2.Set = Set2;
192});
193
194// vendor/jison/jison.js
195var require_jison = __commonJS((exports, module) => {
196 var typal = require_typal().typal;
197 var Set = require_set().Set;
198 var Jison = exports.Jison = exports;
199 if (typeof console !== "undefined" && console.log) {
200 Jison.print = console.log;
201 } else if (typeof puts !== "undefined") {
202 Jison.print = function print2() {
203 puts([].join.call(arguments, " "));
204 };
205 } else if (typeof print !== "undefined") {
206 Jison.print = print;
207 } else {
208 Jison.print = function print2() {
209 };
210 }
211 Jison.Parser = function() {
212 function each(obj, func) {
213 if (obj.forEach) {
214 obj.forEach(func);
215 } else {
216 var p;
217 for (p in obj) {
218 if (obj.hasOwnProperty(p)) {
219 func.call(obj, obj[p], p, obj);
220 }
221 }
222 }
223 }
224 var Nonterminal = typal.construct({
225 constructor: function Nonterminal(symbol) {
226 this.symbol = symbol;
227 this.productions = new Set();
228 this.first = [];
229 this.follows = [];
230 this.nullable = false;
231 },
232 toString: function Nonterminal_toString() {
233 var str = this.symbol + "\n";
234 str += this.nullable ? "nullable" : "not nullable";
235 str += "\nFirsts: " + this.first.join(", ");
236 str += "\nFollows: " + this.first.join(", ");
237 str += "\nProductions:\n " + this.productions.join("\n ");
238 return str;
239 }
240 });
241 var Production = typal.construct({
242 constructor: function Production(symbol, handle, id) {
243 this.symbol = symbol;
244 this.handle = handle;
245 this.nullable = false;
246 this.id = id;
247 this.first = [];
248 this.precedence = 0;
249 },
250 toString: function Production_toString() {
251 return this.symbol + " -> " + this.handle.join(" ");
252 }
253 });
254 var generator = typal.beget();
255 generator.constructor = function Jison_Generator(grammar2, opt) {
256 var options = typal.mix.call({}, grammar2.options, opt);
257 this.terms = {};
258 this.operators = {};
259 this.productions = [];
260 this.conflicts = 0;
261 this.resolutions = [];
262 this.options = options;
263 this.parseParams = grammar2.parseParams;
264 this.yy = {};
265 if (grammar2.actionInclude) {
266 if (typeof grammar2.actionInclude === "function") {
267 grammar2.actionInclude = String(grammar2.actionInclude).replace(/^\s*function \(\) \{/, "").replace(/\}\s*$/, "");
268 }
269 this.actionInclude = grammar2.actionInclude;
270 }
271 this.moduleInclude = grammar2.moduleInclude || "";
272 this.DEBUG = options.debug || false;
273 if (this.DEBUG)
274 this.mix(generatorDebug);
275 this.processGrammar(grammar2);
276 };
277 generator.processGrammar = function processGrammarDef(grammar2) {
278 var bnf = grammar2.bnf, tokens2 = grammar2.tokens, nonterminals = this.nonterminals = {}, productions = this.productions, self2 = this;
279 if (tokens2) {
280 if (typeof tokens2 === "string") {
281 tokens2 = tokens2.trim().split(" ");
282 } else {
283 tokens2 = tokens2.slice(0);
284 }
285 }
286 var symbols = this.symbols = [];
287 var operators2 = this.operators = processOperators(grammar2.operators);
288 this.buildProductions(bnf, productions, nonterminals, symbols, operators2);
289 if (tokens2 && this.terminals.length !== tokens2.length) {
290 self2.trace("Warning: declared tokens differ from tokens found in rules.");
291 self2.trace(this.terminals);
292 self2.trace(tokens2);
293 }
294 this.augmentGrammar(grammar2);
295 };
296 generator.augmentGrammar = function augmentGrammar(grammar2) {
297 if (this.productions.length === 0) {
298 throw new Error("Grammar error: must have at least one rule.");
299 }
300 this.startSymbol = grammar2.start || grammar2.startSymbol || this.productions[0].symbol;
301 if (!this.nonterminals[this.startSymbol]) {
302 throw new Error("Grammar error: startSymbol must be a non-terminal found in your grammar.");
303 }
304 this.EOF = "$end";
305 var acceptProduction = new Production("$accept", [this.startSymbol, "$end"], 0);
306 this.productions.unshift(acceptProduction);
307 this.symbols.unshift("$accept", this.EOF);
308 this.symbols_.$accept = 0;
309 this.symbols_[this.EOF] = 1;
310 this.terminals.unshift(this.EOF);
311 this.nonterminals.$accept = new Nonterminal("$accept");
312 this.nonterminals.$accept.productions.push(acceptProduction);
313 this.nonterminals[this.startSymbol].follows.push(this.EOF);
314 };
315 function processOperators(ops) {
316 if (!ops)
317 return {};
318 var operators2 = {};
319 for (var i = 0, k, prec; prec = ops[i]; i++) {
320 for (k = 1; k < prec.length; k++) {
321 operators2[prec[k]] = {precedence: i + 1, assoc: prec[0]};
322 }
323 }
324 return operators2;
325 }
326 generator.buildProductions = function buildProductions(bnf, productions, nonterminals, symbols, operators2) {
327 var actions = [
328 "/* self == yyval */",
329 this.actionInclude || "",
330 "var $0 = $$.length - 1;",
331 "switch (yystate) {"
332 ];
333 var actionGroups = {};
334 var prods, symbol;
335 var productions_ = [0];
336 var symbolId = 1;
337 var symbols_ = {};
338 var her = false;
339 function addSymbol(s) {
340 if (s && !symbols_[s]) {
341 symbols_[s] = ++symbolId;
342 symbols.push(s);
343 }
344 }
345 addSymbol("error");
346 for (symbol in bnf) {
347 if (!bnf.hasOwnProperty(symbol))
348 continue;
349 addSymbol(symbol);
350 nonterminals[symbol] = new Nonterminal(symbol);
351 if (typeof bnf[symbol] === "string") {
352 prods = bnf[symbol].split(/\s*\|\s*/g);
353 } else {
354 prods = bnf[symbol].slice(0);
355 }
356 prods.forEach(buildProduction);
357 }
358 for (var action in actionGroups)
359 actions.push(actionGroups[action].join(" "), action, "break;");
360 var sym, terms = [], terms_ = {};
361 each(symbols_, function(id, sym2) {
362 if (!nonterminals[sym2]) {
363 terms.push(sym2);
364 terms_[id] = sym2;
365 }
366 });
367 this.hasErrorRecovery = her;
368 this.terminals = terms;
369 this.terminals_ = terms_;
370 this.symbols_ = symbols_;
371 this.productions_ = productions_;
372 actions.push("}");
373 actions = actions.join("\n").replace(/YYABORT/g, "return false").replace(/YYACCEPT/g, "return true");
374 var yyvalParam = "this";
375 var parameters = "self, yytext, yy, yystate /* action[1] */, $$ /* vstack */";
376 if (this.parseParams)
377 parameters += ", " + this.parseParams.join(", ");
378 this.performAction = "function performAction(" + parameters + ") {\n" + actions + "\n}";
379 function buildProduction(handle) {
380 var r, rhs, i;
381 if (handle.constructor === Array) {
382 rhs = typeof handle[0] === "string" ? handle[0].trim().split(" ") : handle[0].slice(0);
383 for (i = 0; i < rhs.length; i++) {
384 if (rhs[i] === "error")
385 her = true;
386 if (!symbols_[rhs[i]]) {
387 addSymbol(rhs[i]);
388 }
389 }
390 if (typeof handle[1] === "string" || handle.length == 3) {
391 var label = "case " + (productions.length + 1) + ":", action2 = handle[1];
392 if (action2.match(/[$@][a-zA-Z][a-zA-Z0-9_]*/)) {
393 var count = {}, names = {};
394 for (i = 0; i < rhs.length; i++) {
395 var rhs_i = rhs[i].match(/\[[a-zA-Z][a-zA-Z0-9_-]*\]/);
396 if (rhs_i) {
397 rhs_i = rhs_i[0].substr(1, rhs_i[0].length - 2);
398 rhs[i] = rhs[i].substr(0, rhs[i].indexOf("["));
399 } else {
400 rhs_i = rhs[i];
401 }
402 if (names[rhs_i]) {
403 names[rhs_i + ++count[rhs_i]] = i + 1;
404 } else {
405 names[rhs_i] = i + 1;
406 names[rhs_i + "1"] = i + 1;
407 count[rhs_i] = 1;
408 }
409 }
410 action2 = action2.replace(/\$([a-zA-Z][a-zA-Z0-9_]*)/g, function(str, pl) {
411 return names[pl] ? "$" + names[pl] : str;
412 }).replace(/@([a-zA-Z][a-zA-Z0-9_]*)/g, function(str, pl) {
413 return names[pl] ? "@" + names[pl] : str;
414 });
415 }
416 action2 = action2.replace(/([^'"])\$\$|^\$\$/g, "$1self.$").replace(/@[0$]/g, "self._$").replace(/\$(-?\d+)/g, function(_, n) {
417 return "$$[$0" + (parseInt(n, 10) - rhs.length || "") + "]";
418 }).replace(/@(-?\d+)/g, function(_, n) {
419 return "_$[$0" + (n - rhs.length || "") + "]";
420 });
421 if (action2 in actionGroups)
422 actionGroups[action2].push(label);
423 else
424 actionGroups[action2] = [label];
425 rhs = rhs.map(function(e, i2) {
426 return e.replace(/\[[a-zA-Z_][a-zA-Z0-9_-]*\]/g, "");
427 });
428 r = new Production(symbol, rhs, productions.length + 1);
429 if (handle[2] && operators2[handle[2].prec]) {
430 r.precedence = operators2[handle[2].prec].precedence;
431 }
432 } else {
433 rhs = rhs.map(function(e, i2) {
434 return e.replace(/\[[a-zA-Z_][a-zA-Z0-9_-]*\]/g, "");
435 });
436 r = new Production(symbol, rhs, productions.length + 1);
437 if (operators2[handle[1].prec]) {
438 r.precedence = operators2[handle[1].prec].precedence;
439 }
440 }
441 } else {
442 handle = handle.replace(/\[[a-zA-Z_][a-zA-Z0-9_-]*\]/g, "");
443 rhs = handle.trim().split(" ");
444 for (i = 0; i < rhs.length; i++) {
445 if (rhs[i] === "error")
446 her = true;
447 if (!symbols_[rhs[i]]) {
448 addSymbol(rhs[i]);
449 }
450 }
451 r = new Production(symbol, rhs, productions.length + 1);
452 }
453 if (r.precedence === 0) {
454 for (i = r.handle.length - 1; i >= 0; i--) {
455 if (!(r.handle[i] in nonterminals) && r.handle[i] in operators2) {
456 r.precedence = operators2[r.handle[i]].precedence;
457 }
458 }
459 }
460 productions.push(r);
461 productions_.push([symbols_[r.symbol], r.handle[0] === "" ? 0 : r.handle.length]);
462 nonterminals[symbol].productions.push(r);
463 }
464 };
465 generator.createParser = function createParser() {
466 throw new Error("Calling abstract method.");
467 };
468 generator.trace = function trace() {
469 };
470 generator.warn = function warn() {
471 var args = Array.prototype.slice.call(arguments, 0);
472 Jison.print.call(null, args.join(""));
473 };
474 generator.error = function error(msg) {
475 throw new Error(msg);
476 };
477 var generatorDebug = {
478 trace: function trace() {
479 Jison.print.apply(null, arguments);
480 },
481 beforeprocessGrammar: function() {
482 this.trace("Processing grammar.");
483 },
484 afteraugmentGrammar: function() {
485 var trace = this.trace;
486 each(this.symbols, function(sym, i) {
487 trace(sym + "(" + i + ")");
488 });
489 }
490 };
491 var lookaheadMixin = {};
492 lookaheadMixin.computeLookaheads = function computeLookaheads() {
493 if (this.DEBUG)
494 this.mix(lookaheadDebug);
495 this.computeLookaheads = function() {
496 };
497 this.nullableSets();
498 this.firstSets();
499 this.followSets();
500 };
501 lookaheadMixin.followSets = function followSets() {
502 var productions = this.productions, nonterminals = this.nonterminals, self2 = this, cont = true;
503 while (cont) {
504 cont = false;
505 productions.forEach(function Follow_prod_forEach(production, k) {
506 var q;
507 var ctx = !!self2.go_;
508 var set = [], oldcount;
509 for (var i = 0, t; t = production.handle[i]; ++i) {
510 if (!nonterminals[t])
511 continue;
512 if (ctx)
513 q = self2.go_(production.symbol, production.handle.slice(0, i));
514 var bool = !ctx || q === parseInt(self2.nterms_[t], 10);
515 if (i === production.handle.length + 1 && bool) {
516 set = nonterminals[production.symbol].follows;
517 } else {
518 var part = production.handle.slice(i + 1);
519 set = self2.first(part);
520 if (self2.nullable(part) && bool) {
521 set.push.apply(set, nonterminals[production.symbol].follows);
522 }
523 }
524 oldcount = nonterminals[t].follows.length;
525 Set.union(nonterminals[t].follows, set);
526 if (oldcount !== nonterminals[t].follows.length) {
527 cont = true;
528 }
529 }
530 });
531 }
532 };
533 lookaheadMixin.first = function first(symbol) {
534 if (symbol === "") {
535 return [];
536 } else if (symbol instanceof Array) {
537 var firsts = [];
538 for (var i = 0, t; t = symbol[i]; ++i) {
539 if (!this.nonterminals[t]) {
540 if (firsts.indexOf(t) === -1)
541 firsts.push(t);
542 } else {
543 Set.union(firsts, this.nonterminals[t].first);
544 }
545 if (!this.nullable(t))
546 break;
547 }
548 return firsts;
549 } else if (!this.nonterminals[symbol]) {
550 return [symbol];
551 } else {
552 return this.nonterminals[symbol].first;
553 }
554 };
555 lookaheadMixin.firstSets = function firstSets() {
556 var productions = this.productions, nonterminals = this.nonterminals, self2 = this, cont = true, symbol, firsts;
557 while (cont) {
558 cont = false;
559 productions.forEach(function FirstSets_forEach(production, k) {
560 var firsts2 = self2.first(production.handle);
561 if (firsts2.length !== production.first.length) {
562 production.first = firsts2;
563 cont = true;
564 }
565 });
566 for (symbol in nonterminals) {
567 firsts = [];
568 nonterminals[symbol].productions.forEach(function(production) {
569 Set.union(firsts, production.first);
570 });
571 if (firsts.length !== nonterminals[symbol].first.length) {
572 nonterminals[symbol].first = firsts;
573 cont = true;
574 }
575 }
576 }
577 };
578 lookaheadMixin.nullableSets = function nullableSets() {
579 var firsts = this.firsts = {}, nonterminals = this.nonterminals, self2 = this, cont = true;
580 while (cont) {
581 cont = false;
582 this.productions.forEach(function(production2, k) {
583 if (!production2.nullable) {
584 for (var i2 = 0, n = 0, t; t = production2.handle[i2]; ++i2) {
585 if (self2.nullable(t))
586 n++;
587 }
588 if (n === i2) {
589 production2.nullable = cont = true;
590 }
591 }
592 });
593 for (var symbol in nonterminals) {
594 if (!this.nullable(symbol)) {
595 for (var i = 0, production; production = nonterminals[symbol].productions.item(i); i++) {
596 if (production.nullable)
597 nonterminals[symbol].nullable = cont = true;
598 }
599 }
600 }
601 }
602 };
603 lookaheadMixin.nullable = function nullable(symbol) {
604 if (symbol === "") {
605 return true;
606 } else if (symbol instanceof Array) {
607 for (var i = 0, t; t = symbol[i]; ++i) {
608 if (!this.nullable(t))
609 return false;
610 }
611 return true;
612 } else if (!this.nonterminals[symbol]) {
613 return false;
614 } else {
615 return this.nonterminals[symbol].nullable;
616 }
617 };
618 var lookaheadDebug = {
619 beforenullableSets: function() {
620 this.trace("Computing Nullable sets.");
621 },
622 beforefirstSets: function() {
623 this.trace("Computing First sets.");
624 },
625 beforefollowSets: function() {
626 this.trace("Computing Follow sets.");
627 },
628 afterfollowSets: function() {
629 var trace = this.trace;
630 each(this.nonterminals, function(nt, t) {
631 trace(nt, "\n");
632 });
633 }
634 };
635 var lrGeneratorMixin = {};
636 lrGeneratorMixin.buildTable = function buildTable() {
637 if (this.DEBUG)
638 this.mix(lrGeneratorDebug);
639 this.states = this.canonicalCollection();
640 this.table = this.parseTable(this.states);
641 this.defaultActions = findDefaults(this.table);
642 };
643 lrGeneratorMixin.Item = typal.construct({
644 constructor: function Item(production, dot, f, predecessor) {
645 this.production = production;
646 this.dotPosition = dot || 0;
647 this.follows = f || [];
648 this.predecessor = predecessor;
649 this.id = parseInt(production.id + "a" + this.dotPosition, 36);
650 this.markedSymbol = this.production.handle[this.dotPosition];
651 },
652 remainingHandle: function() {
653 return this.production.handle.slice(this.dotPosition + 1);
654 },
655 eq: function(e) {
656 return e.id === this.id;
657 },
658 handleToString: function() {
659 var handle = this.production.handle.slice(0);
660 handle[this.dotPosition] = "." + (handle[this.dotPosition] || "");
661 return handle.join(" ");
662 },
663 toString: function() {
664 var temp = this.production.handle.slice(0);
665 temp[this.dotPosition] = "." + (temp[this.dotPosition] || "");
666 return this.production.symbol + " -> " + temp.join(" ") + (this.follows.length === 0 ? "" : " #lookaheads= " + this.follows.join(" "));
667 }
668 });
669 lrGeneratorMixin.ItemSet = Set.prototype.construct({
670 afterconstructor: function() {
671 this.reductions = [];
672 this.goes = {};
673 this.edges = {};
674 this.shifts = false;
675 this.inadequate = false;
676 this.hash_ = {};
677 for (var i = this._items.length - 1; i >= 0; i--) {
678 this.hash_[this._items[i].id] = true;
679 }
680 },
681 concat: function concat(set) {
682 var a = set._items || set;
683 for (var i = a.length - 1; i >= 0; i--) {
684 this.hash_[a[i].id] = true;
685 }
686 this._items.push.apply(this._items, a);
687 return this;
688 },
689 push: function(item) {
690 this.hash_[item.id] = true;
691 return this._items.push(item);
692 },
693 contains: function(item) {
694 return this.hash_[item.id];
695 },
696 valueOf: function toValue() {
697 var v = this._items.map(function(a) {
698 return a.id;
699 }).sort().join("|");
700 this.valueOf = function toValue_inner() {
701 return v;
702 };
703 return v;
704 }
705 });
706 lrGeneratorMixin.closureOperation = function closureOperation(itemSet) {
707 var closureSet = new this.ItemSet();
708 var self2 = this;
709 var set = itemSet, itemQueue, syms = {};
710 do {
711 itemQueue = new Set();
712 closureSet.concat(set);
713 set.forEach(function CO_set_forEach(item) {
714 var symbol = item.markedSymbol;
715 if (symbol && self2.nonterminals[symbol]) {
716 if (!syms[symbol]) {
717 self2.nonterminals[symbol].productions.forEach(function CO_nt_forEach(production) {
718 var newItem = new self2.Item(production, 0);
719 if (!closureSet.contains(newItem))
720 itemQueue.push(newItem);
721 });
722 syms[symbol] = true;
723 }
724 } else if (!symbol) {
725 closureSet.reductions.push(item);
726 closureSet.inadequate = closureSet.reductions.length > 1 || closureSet.shifts;
727 } else {
728 closureSet.shifts = true;
729 closureSet.inadequate = closureSet.reductions.length > 0;
730 }
731 });
732 set = itemQueue;
733 } while (!itemQueue.isEmpty());
734 return closureSet;
735 };
736 lrGeneratorMixin.gotoOperation = function gotoOperation(itemSet, symbol) {
737 var gotoSet = new this.ItemSet(), self2 = this;
738 itemSet.forEach(function goto_forEach(item, n) {
739 if (item.markedSymbol === symbol) {
740 gotoSet.push(new self2.Item(item.production, item.dotPosition + 1, item.follows, n));
741 }
742 });
743 return gotoSet.isEmpty() ? gotoSet : this.closureOperation(gotoSet);
744 };
745 lrGeneratorMixin.canonicalCollection = function canonicalCollection() {
746 var item1 = new this.Item(this.productions[0], 0, [this.EOF]);
747 var firstState = this.closureOperation(new this.ItemSet(item1)), states = new Set(firstState), marked = 0, self2 = this, itemSet;
748 states.has = {};
749 states.has[firstState] = 0;
750 while (marked !== states.size()) {
751 itemSet = states.item(marked);
752 marked++;
753 itemSet.forEach(function CC_itemSet_forEach(item) {
754 if (item.markedSymbol && item.markedSymbol !== self2.EOF)
755 self2.canonicalCollectionInsert(item.markedSymbol, itemSet, states, marked - 1);
756 });
757 }
758 return states;
759 };
760 lrGeneratorMixin.canonicalCollectionInsert = function canonicalCollectionInsert(symbol, itemSet, states, stateNum) {
761 var g = this.gotoOperation(itemSet, symbol);
762 if (!g.predecessors)
763 g.predecessors = {};
764 if (!g.isEmpty()) {
765 var gv = g.valueOf(), i = states.has[gv];
766 if (i === -1 || typeof i === "undefined") {
767 states.has[gv] = states.size();
768 itemSet.edges[symbol] = states.size();
769 states.push(g);
770 g.predecessors[symbol] = [stateNum];
771 } else {
772 itemSet.edges[symbol] = i;
773 states.item(i).predecessors[symbol].push(stateNum);
774 }
775 }
776 };
777 var NONASSOC = 0;
778 lrGeneratorMixin.parseTable = function parseTable(itemSets) {
779 var states = [], nonterminals = this.nonterminals, operators2 = this.operators, conflictedStates = {}, self2 = this, s = 1, r = 2, a = 3;
780 itemSets.forEach(function(itemSet, k) {
781 var state = states[k] = {};
782 var action, stackSymbol;
783 for (stackSymbol in itemSet.edges) {
784 itemSet.forEach(function(item, j) {
785 if (item.markedSymbol == stackSymbol) {
786 var gotoState = itemSet.edges[stackSymbol];
787 if (nonterminals[stackSymbol]) {
788 state[self2.symbols_[stackSymbol]] = gotoState;
789 } else {
790 state[self2.symbols_[stackSymbol]] = [s, gotoState];
791 }
792 }
793 });
794 }
795 itemSet.forEach(function(item, j) {
796 if (item.markedSymbol == self2.EOF) {
797 state[self2.symbols_[self2.EOF]] = [a];
798 }
799 });
800 var allterms = self2.lookAheads ? false : self2.terminals;
801 itemSet.reductions.forEach(function(item, j) {
802 var terminals = allterms || self2.lookAheads(itemSet, item);
803 terminals.forEach(function(stackSymbol2) {
804 action = state[self2.symbols_[stackSymbol2]];
805 var op = operators2[stackSymbol2];
806 if (action || action && action.length) {
807 var sol = resolveConflict(item.production, op, [r, item.production.id], action[0] instanceof Array ? action[0] : action);
808 self2.resolutions.push([k, stackSymbol2, sol]);
809 if (sol.bydefault) {
810 self2.conflicts++;
811 if (!self2.DEBUG) {
812 self2.warn("Conflict in grammar: multiple actions possible when lookahead token is ", stackSymbol2, " in state ", k, "\n- ", printAction(sol.r, self2), "\n- ", printAction(sol.s, self2));
813 conflictedStates[k] = true;
814 }
815 if (self2.options.noDefaultResolve) {
816 if (!(action[0] instanceof Array))
817 action = [action];
818 action.push(sol.r);
819 }
820 } else {
821 action = sol.action;
822 }
823 } else {
824 action = [r, item.production.id];
825 }
826 if (action && action.length) {
827 state[self2.symbols_[stackSymbol2]] = action;
828 } else if (action === NONASSOC) {
829 state[self2.symbols_[stackSymbol2]] = void 0;
830 }
831 });
832 });
833 });
834 if (!self2.DEBUG && self2.conflicts > 0) {
835 self2.warn("\nStates with conflicts:");
836 each(conflictedStates, function(val, state) {
837 self2.warn("State " + state);
838 self2.warn(" ", itemSets.item(state).join("\n "));
839 });
840 }
841 return states;
842 };
843 function findDefaults(states) {
844 var defaults = {};
845 states.forEach(function(state, k) {
846 var i = 0;
847 for (var act in state) {
848 if ({}.hasOwnProperty.call(state, act))
849 i++;
850 }
851 if (i === 1 && state[act][0] === 2) {
852 defaults[k] = state[act];
853 }
854 });
855 return defaults;
856 }
857 function resolveConflict(production, op, reduce, shift) {
858 var sln = {production, operator: op, r: reduce, s: shift}, s = 1, r = 2, a = 3;
859 if (shift[0] === r) {
860 sln.msg = "Resolve R/R conflict (use first production declared in grammar.)";
861 sln.action = shift[1] < reduce[1] ? shift : reduce;
862 if (shift[1] !== reduce[1])
863 sln.bydefault = true;
864 return sln;
865 }
866 if (production.precedence === 0 || !op) {
867 sln.msg = "Resolve S/R conflict (shift by default.)";
868 sln.bydefault = true;
869 sln.action = shift;
870 } else if (production.precedence < op.precedence) {
871 sln.msg = "Resolve S/R conflict (shift for higher precedent operator.)";
872 sln.action = shift;
873 } else if (production.precedence === op.precedence) {
874 if (op.assoc === "right") {
875 sln.msg = "Resolve S/R conflict (shift for right associative operator.)";
876 sln.action = shift;
877 } else if (op.assoc === "left") {
878 sln.msg = "Resolve S/R conflict (reduce for left associative operator.)";
879 sln.action = reduce;
880 } else if (op.assoc === "nonassoc") {
881 sln.msg = "Resolve S/R conflict (no action for non-associative operator.)";
882 sln.action = NONASSOC;
883 }
884 } else {
885 sln.msg = "Resolve conflict (reduce for higher precedent production.)";
886 sln.action = reduce;
887 }
888 return sln;
889 }
890 lrGeneratorMixin.generate = function parser_generate(opt) {
891 opt = typal.mix.call({}, this.options, opt);
892 var code = "";
893 if (!opt.moduleName || !opt.moduleName.match(/^[A-Za-z_$][A-Za-z0-9_$]*$/)) {
894 opt.moduleName = "parser";
895 }
896 switch (opt.moduleType) {
897 case "js":
898 code = this.generateModule(opt);
899 break;
900 case "amd":
901 code = this.generateAMDModule(opt);
902 break;
903 default:
904 code = this.generateCommonJSModule(opt);
905 break;
906 }
907 return code;
908 };
909 lrGeneratorMixin.generateAMDModule = function generateAMDModule(opt) {
910 opt = typal.mix.call({}, this.options, opt);
911 var module2 = this.generateModule_();
912 var out = "\n\ndefine(function(require){\n" + module2.commonCode + "\nvar parser = " + module2.moduleCode + "\n" + this.moduleInclude + (this.lexer && this.lexer.generateModule ? "\n" + this.lexer.generateModule() + "\nparser.lexer = lexer;" : "") + "\nreturn parser;\n});";
913 return out;
914 };
915 lrGeneratorMixin.generateCommonJSModule = function generateCommonJSModule(opt) {
916 opt = typal.mix.call({}, this.options, opt);
917 var moduleName = opt.moduleName || "parser";
918 var out = this.generateModule(opt) + "\n\n\nif (typeof require !== 'undefined' && typeof exports !== 'undefined') {\nexports.parser = " + moduleName + ";\nexports.Parser = " + moduleName + ".Parser;\nexports.parse = function () { return " + moduleName + ".parse.apply(" + moduleName + ", arguments); };\n}";
919 return out;
920 };
921 lrGeneratorMixin.generateModule = function generateModule(opt) {
922 opt = typal.mix.call({}, this.options, opt);
923 var moduleName = opt.moduleName || "parser";
924 var out = "/* parser generated by jison-fork */\n";
925 out += (moduleName.match(/\./) ? moduleName : "var " + moduleName) + " = " + this.generateModuleExpr();
926 return out;
927 };
928 lrGeneratorMixin.generateModuleExpr = function generateModuleExpr() {
929 var out = "";
930 var module2 = this.generateModule_();
931 out += "(function(){\n";
932 out += module2.commonCode;
933 out += "\nvar parser = " + module2.moduleCode;
934 out += "\n" + this.moduleInclude;
935 if (this.lexer && this.lexer.generateModule) {
936 out += this.lexer.generateModule();
937 out += "\nparser.lexer = lexer;";
938 }
939 out += "\nfunction Parser () {\n this.yy = {};\n}\nParser.prototype = parser;parser.Parser = Parser;\nreturn new Parser;\n})();";
940 return out;
941 };
942 function addTokenStack(fn) {
943 var parseFn = fn;
944 return fn;
945 }
946 function tokenStackLex() {
947 var token;
948 token = tstack.pop() || lexer.lex() || EOF;
949 if (typeof token !== "number") {
950 if (token instanceof Array) {
951 tstack = token;
952 token = tstack.pop();
953 }
954 token = self.symbols_[token] || token;
955 }
956 return token;
957 }
958 lrGeneratorMixin.generateModule_ = function generateModule_() {
959 var parseFn = String(parser.parse);
960 nextVariableId = 0;
961 var tableCode = this.generateTableCode(this.table);
962 var commonCode = tableCode.commonCode;
963 var moduleCode = "{";
964 moduleCode += [
965 "trace: " + String(this.trace || parser.trace),
966 "yy: {}",
967 "symbols_: " + JSON.stringify(this.symbols_),
968 "terminals_: " + JSON.stringify(this.terminals_).replace(/"([0-9]+)":/g, "$1:"),
969 "productions_: " + JSON.stringify(this.productions_),
970 "performAction: " + String(this.performAction),
971 "table: " + tableCode.moduleCode,
972 "defaultActions: " + JSON.stringify(this.defaultActions).replace(/"([0-9]+)":/g, "$1:"),
973 "parseError: " + String(this.parseError || (this.hasErrorRecovery ? traceParseError : parser.parseError)),
974 "parse: " + parseFn
975 ].join(",\n");
976 moduleCode += "};";
977 return {commonCode, moduleCode};
978 };
979 lrGeneratorMixin.generateTableCode = function(table) {
980 var moduleCode = JSON.stringify(table);
981 var variables = [createObjectCode];
982 moduleCode = moduleCode.replace(/"([0-9]+)"(?=:)/g, "$1");
983 moduleCode = moduleCode.replace(/\{\d+:[^\}]+,\d+:[^\}]+\}/g, function(object) {
984 var value, frequentValue, key, keys = {}, keyCount, maxKeyCount = 0, keyValue, keyValues = [], keyValueMatcher = /(\d+):([^:]+)(?=,\d+:|\})/g;
985 while (keyValue = keyValueMatcher.exec(object)) {
986 key = keyValue[1];
987 value = keyValue[2];
988 keyCount = 1;
989 if (!(value in keys)) {
990 keys[value] = [key];
991 } else {
992 keyCount = keys[value].push(key);
993 }
994 if (keyCount > maxKeyCount) {
995 maxKeyCount = keyCount;
996 frequentValue = value;
997 }
998 }
999 if (maxKeyCount > 1) {
1000 for (value in keys) {
1001 if (value !== frequentValue) {
1002 for (var k = keys[value], i = 0, l = k.length; i < l; i++) {
1003 keyValues.push(k[i] + ":" + value);
1004 }
1005 }
1006 }
1007 keyValues = keyValues.length ? ",{" + keyValues.join(",") + "}" : "";
1008 object = "o([" + keys[frequentValue].join(",") + "]," + frequentValue + keyValues + ")";
1009 }
1010 return object;
1011 });
1012 var list;
1013 var lists = {};
1014 var listMatcher = /\[[0-9,]+\]/g;
1015 while (list = listMatcher.exec(moduleCode)) {
1016 lists[list] = (lists[list] || 0) + 1;
1017 }
1018 moduleCode = moduleCode.replace(listMatcher, function(list2) {
1019 var listId = lists[list2];
1020 if (typeof listId === "number") {
1021 if (listId === 1) {
1022 lists[list2] = listId = list2;
1023 } else {
1024 lists[list2] = listId = createVariable();
1025 variables.push(listId + "=" + list2);
1026 }
1027 }
1028 return listId;
1029 });
1030 return {
1031 commonCode: "var " + variables.join(",") + ";",
1032 moduleCode
1033 };
1034 };
1035 var createObjectCode = "o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o}";
1036 function createVariable() {
1037 var id = nextVariableId++;
1038 var name = "$V";
1039 do {
1040 name += variableTokens[id % variableTokensLength];
1041 id = ~~(id / variableTokensLength);
1042 } while (id !== 0);
1043 return name;
1044 }
1045 var nextVariableId = 0;
1046 var variableTokens = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$";
1047 var variableTokensLength = variableTokens.length;
1048 function printAction(a, gen) {
1049 var s = a[0] == 1 ? "shift token (then go to state " + a[1] + ")" : a[0] == 2 ? "reduce by rule: " + gen.productions[a[1]] : "accept";
1050 return s;
1051 }
1052 var lrGeneratorDebug = {
1053 beforeparseTable: function() {
1054 this.trace("Building parse table.");
1055 },
1056 afterparseTable: function() {
1057 var self2 = this;
1058 if (this.conflicts > 0) {
1059 this.resolutions.forEach(function(r, i) {
1060 if (r[2].bydefault) {
1061 self2.warn("Conflict at state: ", r[0], ", token: ", r[1], "\n ", printAction(r[2].r, self2), "\n ", printAction(r[2].s, self2));
1062 }
1063 });
1064 this.trace("\n" + this.conflicts + " Conflict(s) found in grammar.");
1065 }
1066 this.trace("Done.");
1067 },
1068 aftercanonicalCollection: function(states) {
1069 var trace = this.trace;
1070 trace("\nItem sets\n------");
1071 states.forEach(function(state, i) {
1072 trace("\nitem set", i, "\n" + state.join("\n"), "\ntransitions -> ", JSON.stringify(state.edges));
1073 });
1074 }
1075 };
1076 var parser = typal.beget();
1077 lrGeneratorMixin.createParser = function createParser() {
1078 var p = eval(this.generateModuleExpr());
1079 p.productions = this.productions;
1080 var self = this;
1081 function bind(method) {
1082 return function() {
1083 self.lexer = p.lexer;
1084 return self[method].apply(self, arguments);
1085 };
1086 }
1087 p.generate = bind("generate");
1088 p.generateAMDModule = bind("generateAMDModule");
1089 p.generateModule = bind("generateModule");
1090 p.generateCommonJSModule = bind("generateCommonJSModule");
1091 return p;
1092 };
1093 parser.trace = generator.trace;
1094 parser.warn = generator.warn;
1095 parser.error = generator.error;
1096 function traceParseError(err, hash) {
1097 this.trace(err);
1098 }
1099 function parseError(str, hash) {
1100 if (hash.recoverable) {
1101 this.trace(str);
1102 } else {
1103 throw new Error(str);
1104 }
1105 }
1106 parser.parseError = lrGeneratorMixin.parseError = parseError;
1107 parser.parse = function parse(input, script = null) {
1108 var self2 = this, stack = [0], tstack2 = [], vstack = [null], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF2 = 1;
1109 var lexer2 = Object.create(this.lexer);
1110 var yy = this.yy;
1111 lexer2.setInput(input, yy);
1112 if (typeof yy.parseError === "function") {
1113 this.parseError = yy.parseError;
1114 } else {
1115 this.parseError = Object.getPrototypeOf(this).parseError;
1116 }
1117 function popStack(n) {
1118 stack.length = stack.length - 2 * n;
1119 vstack.length = vstack.length - n;
1120 }
1121 var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
1122 function handleError() {
1123 var error_rule_depth;
1124 var errStr = "";
1125 function locateNearestErrorRecoveryRule(state2) {
1126 var stack_probe = stack.length - 1;
1127 var depth = 0;
1128 for (; ; ) {
1129 if (TERROR.toString() in table[state2]) {
1130 return depth;
1131 }
1132 if (state2 === 0 || stack_probe < 2) {
1133 return false;
1134 }
1135 stack_probe -= 2;
1136 state2 = stack[stack_probe];
1137 ++depth;
1138 }
1139 }
1140 if (!recovering) {
1141 error_rule_depth = locateNearestErrorRecoveryRule(state);
1142 expected = [];
1143 var tsym = lexer2.yytext;
1144 var lastToken = tsym;
1145 var tok = self2.terminals_[symbol] || symbol;
1146 let tidx = lexer2.tokens.indexOf(tsym);
1147 let ttok = tsym;
1148 while (ttok && ttok._loc == -1) {
1149 ttok = lexer2.tokens[--tidx];
1150 }
1151 var tloc = ttok ? ttok._loc : -1;
1152 var tend = tloc > -1 ? tloc + (ttok._len || 0) : -1;
1153 var tpos = tloc != -1 ? "[" + ttok._loc + ":" + ttok._len + "]" : "[0:0]";
1154 if (lexer2.showPosition) {
1155 errStr = "Parse error at " + tpos + ":\n" + lexer2.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + tok + "'";
1156 } else {
1157 errStr = "Unexpected " + (symbol == EOF2 ? "end of input" : "'" + tok + "'");
1158 }
1159 if (script) {
1160 let err = script.addDiagnostic("error", {
1161 message: errStr,
1162 source: "imba-parser",
1163 range: script.rangeAt(tloc, tend)
1164 });
1165 err.raise();
1166 }
1167 self2.parseError(errStr, {
1168 lexer: lexer2,
1169 text: lexer2.match,
1170 token: tok,
1171 offset: tloc,
1172 length: tend - tloc,
1173 start: {offset: tloc},
1174 end: {offset: tend},
1175 line: lexer2.yylineno,
1176 expected,
1177 recoverable: error_rule_depth !== false
1178 });
1179 } else if (preErrorSymbol !== EOF2) {
1180 error_rule_depth = locateNearestErrorRecoveryRule(state);
1181 }
1182 if (recovering == 3) {
1183 if (symbol === EOF2 || preErrorSymbol === EOF2) {
1184 throw new Error(errStr || "Parsing halted while starting to recover from another error.");
1185 }
1186 yytext = lexer2.yytext;
1187 }
1188 if (error_rule_depth === false) {
1189 throw new Error(errStr || "Parsing halted. No suitable error recovery rule available.");
1190 }
1191 popStack(error_rule_depth);
1192 preErrorSymbol = symbol == TERROR ? null : symbol;
1193 symbol = TERROR;
1194 state = stack[stack.length - 1];
1195 action = table[state] && table[state][TERROR];
1196 recovering = 3;
1197 }
1198 var __sym = this.symbols_;
1199 var __prod = this.productions_;
1200 while (true) {
1201 state = stack[stack.length - 1];
1202 if (symbol === null || typeof symbol == "undefined") {
1203 symbol = __sym[lexer2.lex()] || EOF2;
1204 }
1205 action = table[state] && table[state][symbol];
1206 _handle_error:
1207 if (typeof action === "undefined" || !action.length || !action[0]) {
1208 handleError();
1209 }
1210 switch (action[0]) {
1211 case 1:
1212 stack.push(symbol);
1213 stack.push(action[1]);
1214 vstack.push(lexer2.yytext);
1215 symbol = null;
1216 if (!preErrorSymbol) {
1217 yytext = lexer2.yytext;
1218 if (recovering > 0) {
1219 recovering--;
1220 }
1221 } else {
1222 symbol = preErrorSymbol;
1223 preErrorSymbol = null;
1224 }
1225 break;
1226 case 2:
1227 len = __prod[action[1]][1];
1228 yyval.$ = vstack[vstack.length - len];
1229 r = this.performAction(yyval, yytext, yy, action[1], vstack);
1230 if (typeof r !== "undefined") {
1231 return r;
1232 }
1233 while (len > 0) {
1234 stack.pop();
1235 stack.pop();
1236 vstack.pop();
1237 len--;
1238 }
1239 stack.push(__prod[action[1]][0]);
1240 newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
1241 stack.push(newState);
1242 vstack.push(yyval.$);
1243 break;
1244 case 3:
1245 return true;
1246 }
1247 }
1248 return true;
1249 };
1250 parser.init = function parser_init(dict) {
1251 this.table = dict.table;
1252 this.defaultActions = dict.defaultActions;
1253 this.performAction = dict.performAction;
1254 this.productions_ = dict.productions_;
1255 this.symbols_ = dict.symbols_;
1256 this.terminals_ = dict.terminals_;
1257 };
1258 var lr0 = generator.beget(lookaheadMixin, lrGeneratorMixin, {
1259 type: "LR(0)",
1260 afterconstructor: function lr0_afterconstructor() {
1261 this.buildTable();
1262 }
1263 });
1264 var LR0Generator = exports.LR0Generator = lr0.construct();
1265 var lalr = generator.beget(lookaheadMixin, lrGeneratorMixin, {
1266 type: "LALR(1)",
1267 afterconstructor: function(grammar2, options) {
1268 if (this.DEBUG)
1269 this.mix(lrGeneratorDebug, lalrGeneratorDebug);
1270 options = options || {};
1271 this.states = this.canonicalCollection();
1272 this.terms_ = {};
1273 var newg = this.newg = typal.beget(lookaheadMixin, {
1274 oldg: this,
1275 trace: this.trace,
1276 nterms_: {},
1277 DEBUG: false,
1278 go_: function(r, B) {
1279 r = r.split(":")[0];
1280 B = B.map(function(b) {
1281 return b.slice(b.indexOf(":") + 1);
1282 });
1283 return this.oldg.go(r, B);
1284 }
1285 });
1286 newg.nonterminals = {};
1287 newg.productions = [];
1288 this.inadequateStates = [];
1289 this.onDemandLookahead = options.onDemandLookahead || false;
1290 this.buildNewGrammar();
1291 newg.computeLookaheads();
1292 this.unionLookaheads();
1293 this.table = this.parseTable(this.states);
1294 this.defaultActions = findDefaults(this.table);
1295 },
1296 lookAheads: function LALR_lookaheads(state, item) {
1297 return !!this.onDemandLookahead && !state.inadequate ? this.terminals : item.follows;
1298 },
1299 go: function LALR_go(p, w) {
1300 var q = parseInt(p, 10);
1301 for (var i = 0; i < w.length; i++) {
1302 q = this.states.item(q).edges[w[i]] || q;
1303 }
1304 return q;
1305 },
1306 goPath: function LALR_goPath(p, w) {
1307 var q = parseInt(p, 10), t, path = [];
1308 for (var i = 0; i < w.length; i++) {
1309 t = w[i] ? q + ":" + w[i] : "";
1310 if (t)
1311 this.newg.nterms_[t] = q;
1312 path.push(t);
1313 q = this.states.item(q).edges[w[i]] || q;
1314 this.terms_[t] = w[i];
1315 }
1316 return {path, endState: q};
1317 },
1318 buildNewGrammar: function LALR_buildNewGrammar() {
1319 var self2 = this, newg = this.newg;
1320 this.states.forEach(function(state, i) {
1321 state.forEach(function(item) {
1322 if (item.dotPosition === 0) {
1323 var symbol = i + ":" + item.production.symbol;
1324 self2.terms_[symbol] = item.production.symbol;
1325 newg.nterms_[symbol] = i;
1326 if (!newg.nonterminals[symbol])
1327 newg.nonterminals[symbol] = new Nonterminal(symbol);
1328 var pathInfo = self2.goPath(i, item.production.handle);
1329 var p = new Production(symbol, pathInfo.path, newg.productions.length);
1330 newg.productions.push(p);
1331 newg.nonterminals[symbol].productions.push(p);
1332 var handle = item.production.handle.join(" ");
1333 var goes = self2.states.item(pathInfo.endState).goes;
1334 if (!goes[handle])
1335 goes[handle] = [];
1336 goes[handle].push(symbol);
1337 }
1338 });
1339 if (state.inadequate)
1340 self2.inadequateStates.push(i);
1341 });
1342 },
1343 unionLookaheads: function LALR_unionLookaheads() {
1344 var self2 = this, newg = this.newg, states = !!this.onDemandLookahead ? this.inadequateStates : this.states;
1345 states.forEach(function union_states_forEach(i) {
1346 var state = typeof i === "number" ? self2.states.item(i) : i, follows = [];
1347 if (state.reductions.length)
1348 state.reductions.forEach(function union_reduction_forEach(item) {
1349 var follows2 = {};
1350 for (var k = 0; k < item.follows.length; k++) {
1351 follows2[item.follows[k]] = true;
1352 }
1353 state.goes[item.production.handle.join(" ")].forEach(function reduction_goes_forEach(symbol) {
1354 newg.nonterminals[symbol].follows.forEach(function goes_follows_forEach(symbol2) {
1355 var terminal = self2.terms_[symbol2];
1356 if (!follows2[terminal]) {
1357 follows2[terminal] = true;
1358 item.follows.push(terminal);
1359 }
1360 });
1361 });
1362 });
1363 });
1364 }
1365 });
1366 var LALRGenerator = exports.LALRGenerator = lalr.construct();
1367 var lalrGeneratorDebug = {
1368 trace: function trace() {
1369 Jison.print.apply(null, arguments);
1370 },
1371 beforebuildNewGrammar: function() {
1372 this.trace(this.states.size() + " states.");
1373 this.trace("Building lookahead grammar.");
1374 },
1375 beforeunionLookaheads: function() {
1376 this.trace("Computing lookaheads.");
1377 }
1378 };
1379 var lrLookaheadGenerator = generator.beget(lookaheadMixin, lrGeneratorMixin, {
1380 afterconstructor: function lr_aftercontructor() {
1381 this.computeLookaheads();
1382 this.buildTable();
1383 }
1384 });
1385 var SLRGenerator = exports.SLRGenerator = lrLookaheadGenerator.construct({
1386 type: "SLR(1)",
1387 lookAheads: function SLR_lookAhead(state, item) {
1388 return this.nonterminals[item.production.symbol].follows;
1389 }
1390 });
1391 var lr1 = lrLookaheadGenerator.beget({
1392 type: "Canonical LR(1)",
1393 lookAheads: function LR_lookAheads(state, item) {
1394 return item.follows;
1395 },
1396 Item: lrGeneratorMixin.Item.prototype.construct({
1397 afterconstructor: function() {
1398 this.id = this.production.id + "a" + this.dotPosition + "a" + this.follows.sort().join(",");
1399 },
1400 eq: function(e) {
1401 return e.id === this.id;
1402 }
1403 }),
1404 closureOperation: function LR_ClosureOperation(itemSet) {
1405 var closureSet = new this.ItemSet();
1406 var self2 = this;
1407 var set = itemSet, itemQueue, syms = {};
1408 do {
1409 itemQueue = new Set();
1410 closureSet.concat(set);
1411 set.forEach(function(item) {
1412 var symbol = item.markedSymbol;
1413 var b, r;
1414 if (symbol && self2.nonterminals[symbol]) {
1415 r = item.remainingHandle();
1416 b = self2.first(item.remainingHandle());
1417 if (b.length === 0 || item.production.nullable || self2.nullable(r)) {
1418 b = b.concat(item.follows);
1419 }
1420 self2.nonterminals[symbol].productions.forEach(function(production) {
1421 var newItem = new self2.Item(production, 0, b);
1422 if (!closureSet.contains(newItem) && !itemQueue.contains(newItem)) {
1423 itemQueue.push(newItem);
1424 }
1425 });
1426 } else if (!symbol) {
1427 closureSet.reductions.push(item);
1428 }
1429 });
1430 set = itemQueue;
1431 } while (!itemQueue.isEmpty());
1432 return closureSet;
1433 }
1434 });
1435 var LR1Generator = exports.LR1Generator = lr1.construct();
1436 var ll = generator.beget(lookaheadMixin, {
1437 type: "LL(1)",
1438 afterconstructor: function ll_aftercontructor() {
1439 this.computeLookaheads();
1440 this.table = this.parseTable(this.productions);
1441 },
1442 parseTable: function llParseTable(productions) {
1443 var table = {}, self2 = this;
1444 productions.forEach(function(production, i) {
1445 var row = table[production.symbol] || {};
1446 var tokens2 = production.first;
1447 if (self2.nullable(production.handle)) {
1448 Set.union(tokens2, self2.nonterminals[production.symbol].follows);
1449 }
1450 tokens2.forEach(function(token) {
1451 if (row[token]) {
1452 row[token].push(i);
1453 self2.conflicts++;
1454 } else {
1455 row[token] = [i];
1456 }
1457 });
1458 table[production.symbol] = row;
1459 });
1460 return table;
1461 }
1462 });
1463 var LLGenerator = exports.LLGenerator = ll.construct();
1464 Jison.Generator = function Jison_Generator(g, options) {
1465 var opt = typal.mix.call({}, g.options, options);
1466 switch (opt.type) {
1467 case "lr0":
1468 return new LR0Generator(g, opt);
1469 case "slr":
1470 return new SLRGenerator(g, opt);
1471 case "lr":
1472 return new LR1Generator(g, opt);
1473 case "ll":
1474 return new LLGenerator(g, opt);
1475 default:
1476 return new LALRGenerator(g, opt);
1477 }
1478 };
1479 return function Parser2(g, options) {
1480 var gen = Jison.Generator(g, options);
1481 return gen.createParser();
1482 };
1483 }();
1484});
1485
1486// src/compiler/grammar.imba1
1487function iter$(a) {
1488 return a ? a.toArray ? a.toArray() : a : [];
1489}
1490var jison = require_jison();
1491var Parser = jison.Parser;
1492var unwrap = /^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/;
1493var o = function(patternString, action, options) {
1494 var match;
1495 patternString = patternString.replace(/\s{2,}/g, " ");
1496 var patternCount = patternString.split(" ").length;
1497 if (!action) {
1498 return [patternString, "$$ = $1;", options];
1499 }
1500 ;
1501 if (match = unwrap.exec(action)) {
1502 action = match[1];
1503 } else {
1504 action = "(" + action + "())";
1505 }
1506 ;
1507 action = action.replace(/\bA(\d+)/g, "$$$1");
1508 action = action.replace(/\bnew /g, "$&yy.");
1509 action = action.replace(/\b(?:Block\.wrap|extend)\b/g, "yy.$&");
1510 action = action.replace(/\bAST\b/g, "yy");
1511 return [patternString, "$$ = " + action + ";", options];
1512};
1513var grammar = {
1514 Root: [
1515 o("", function() {
1516 return new Root([]);
1517 }),
1518 o("Body", function() {
1519 return new Root(A1);
1520 }),
1521 o("Block TERMINATOR")
1522 ],
1523 Body: [
1524 o("BODYSTART", function() {
1525 return new Block([]);
1526 }),
1527 o("Line", function() {
1528 return new Block([]).add(A1);
1529 }),
1530 o("Body Terminator Line", function() {
1531 return A1.break(A2).add(A3);
1532 }),
1533 o("Body Terminator", function() {
1534 return A1.break(A2);
1535 })
1536 ],
1537 Terminator: [
1538 o("TERMINATOR", function() {
1539 return new Terminator(A1);
1540 })
1541 ],
1542 Type: [
1543 o("TYPE", function() {
1544 return new TypeAnnotation(A1);
1545 })
1546 ],
1547 Block: [
1548 o("EMPTY_BLOCK", function() {
1549 return new Block([]);
1550 }),
1551 o("INDENT OUTDENT", function() {
1552 return new Block([]).indented(A1, A2);
1553 }),
1554 o("INDENT Body OUTDENT", function() {
1555 return A2.indented(A1, A3);
1556 }),
1557 o("INDENT TERMINATOR Body OUTDENT", function() {
1558 return A3.prebreak(A2).indented(A1, A4);
1559 })
1560 ],
1561 Line: [
1562 o("CSSDeclaration"),
1563 o("Expression"),
1564 o("VarDecl", function() {
1565 return A1.option("block", true);
1566 }),
1567 o("Comment"),
1568 o("Statement"),
1569 o("Decorators"),
1570 o("ImportDeclaration"),
1571 o("ExportDeclaration")
1572 ],
1573 Statement: [
1574 o("Return"),
1575 o("Throw"),
1576 o("STATEMENT", function() {
1577 return new Literal(A1);
1578 }),
1579 o("BREAK", function() {
1580 return new BreakStatement(A1);
1581 }),
1582 o("BREAK CALL_START Expression CALL_END", function() {
1583 return new BreakStatement(A1, A3);
1584 }),
1585 o("CONTINUE", function() {
1586 return new ContinueStatement(A1);
1587 }),
1588 o("CONTINUE CALL_START Expression CALL_END", function() {
1589 return new ContinueStatement(A1, A3);
1590 }),
1591 o("DEBUGGER", function() {
1592 return new DebuggerStatement(A1);
1593 })
1594 ],
1595 ExtendObject: [
1596 o("EXTEND Identifier ClassBody", function() {
1597 return new ExtendDeclaration(A2, null, A3).set({instanceOnly: true, extension: A1});
1598 })
1599 ],
1600 ExportDeclaration: [
1601 o("EXPORT { ImportSpecifierList }", function() {
1602 return new ExportNamedDeclaration(A1, [A3]);
1603 }),
1604 o("EXPORT { ImportSpecifierList } FROM String", function() {
1605 return new ExportNamedDeclaration(A1, [A3], A6);
1606 }),
1607 o("EXPORT EXPORT_ALL FROM String", function() {
1608 return new ExportAllDeclaration(A1, [new ExportAllSpecifier(A2)], A4);
1609 }),
1610 o("EXPORT EXPORT_ALL AS Identifier FROM String", function() {
1611 return new ExportAllDeclaration(A1, [new ExportAllSpecifier(A2, A4)], A6);
1612 }),
1613 o("EXPORT Exportable", function() {
1614 return new Export(A2).set({keyword: A1});
1615 }),
1616 o("EXPORT DEFAULT DefaultExportable", function() {
1617 return new Export(A3).set({keyword: A1, default: A2});
1618 })
1619 ],
1620 Exportable: [
1621 o("MethodDeclaration"),
1622 o("Class"),
1623 o("CSSDeclaration"),
1624 o("TagDeclaration"),
1625 o("VarAssign")
1626 ],
1627 DefaultExportable: [
1628 o("Expression")
1629 ],
1630 ImportOrExport: [
1631 o("IMPORT"),
1632 o("EXPORT")
1633 ],
1634 ImportDefaultSpecifier: [
1635 o("Identifier", function() {
1636 return new ImportDefaultSpecifier(A1);
1637 })
1638 ],
1639 ImportDeclaration: [
1640 o("IMPORT String", function() {
1641 return new ImportDeclaration(A1, null, A2);
1642 }),
1643 o("IMPORT ImportDefaultSpecifier FROM String", function() {
1644 return new ImportDeclaration(A1, [A2], A4);
1645 }),
1646 o("IMPORT TYPEIMPORT ImportDefaultSpecifier FROM String", function() {
1647 return new ImportTypeDeclaration(A1, [A3], A5);
1648 }),
1649 o("IMPORT ImportNamespaceSpecifier FROM String", function() {
1650 return new ImportDeclaration(A1, [A2], A4);
1651 }),
1652 o("IMPORT { } FROM String", function() {
1653 return new ImportDeclaration(A1, null, A5);
1654 }),
1655 o("IMPORT { ImportSpecifierList } FROM String", function() {
1656 return new ImportDeclaration(A1, [A3], A6);
1657 }),
1658 o("IMPORT TYPEIMPORT { ImportSpecifierList } FROM String", function() {
1659 return new ImportTypeDeclaration(A1, [A4], A7);
1660 }),
1661 o("IMPORT ImportDefaultSpecifier IMPORT_COMMA ImportNamespaceSpecifier FROM String", function() {
1662 return new ImportDeclaration(A1, [A2, A4], A6);
1663 }),
1664 o("IMPORT ImportDefaultSpecifier IMPORT_COMMA { ImportSpecifierList } FROM String", function() {
1665 return new ImportDeclaration(A1, [A2, A5], A8);
1666 })
1667 ],
1668 ImportFrom: [
1669 o("STRING")
1670 ],
1671 ImportNamespaceSpecifier: [
1672 o("IMPORT_ALL AS Identifier", function() {
1673 return new ImportNamespaceSpecifier(new Literal(A1), A3);
1674 })
1675 ],
1676 ImportSpecifierList: [
1677 o("ImportSpecifier", function() {
1678 return new ESMSpecifierList([]).add(A1);
1679 }),
1680 o("ImportSpecifierList , ImportSpecifier", function() {
1681 return A1.add(A3);
1682 }),
1683 o("ImportSpecifierList OptComma TERMINATOR ImportSpecifier", function() {
1684 return A1.add(A4);
1685 }),
1686 o("INDENT ImportSpecifierList OptComma OUTDENT", function() {
1687 return A2;
1688 }),
1689 o("INDENT ImportSpecifierList OptComma TERMINATOR OUTDENT", function() {
1690 return A2;
1691 }),
1692 o("ImportSpecifierList OptComma INDENT ImportSpecifierList OptComma OUTDENT", function() {
1693 return A1.concat(A4);
1694 })
1695 ],
1696 ImportSpecifier: [
1697 o("Identifier", function() {
1698 return new ImportSpecifier(A1);
1699 }),
1700 o("DecoratorIdentifier", function() {
1701 return new ImportSpecifier(A1);
1702 }),
1703 o("MixinIdentifier", function() {
1704 return new ImportSpecifier(A1);
1705 }),
1706 o("Identifier AS Identifier", function() {
1707 return new ImportSpecifier(A1, A3);
1708 }),
1709 o("DEFAULT", function() {
1710 return new ImportSpecifier(new Literal(A1));
1711 }),
1712 o("DEFAULT AS Identifier", function() {
1713 return new ImportSpecifier(new Literal(A1), A3);
1714 })
1715 ],
1716 Require: [
1717 o("REQUIRE RequireArg", function() {
1718 return new Require(A2).set({keyword: A1});
1719 })
1720 ],
1721 RequireArg: [
1722 o("Literal"),
1723 o("Parenthetical"),
1724 o("")
1725 ],
1726 Expression: [
1727 o("Await"),
1728 o("Value"),
1729 o("Code"),
1730 o("Operation"),
1731 o("Assign"),
1732 o("If"),
1733 o("Ternary"),
1734 o("Try"),
1735 o("While"),
1736 o("For"),
1737 o("Switch"),
1738 o("ExtendObject"),
1739 o("Class"),
1740 o("TagDeclaration"),
1741 o("Tag")
1742 ],
1743 ExpressionBlock: [
1744 o("Expression"),
1745 o("INDENT ExpressionBlock Outdent", function() {
1746 return A2.indented(A1, A3);
1747 })
1748 ],
1749 Identifier: [
1750 o("IDENTIFIER", function() {
1751 return new Identifier(A1);
1752 })
1753 ],
1754 SymbolIdentifier: [
1755 o("SYMBOLID", function() {
1756 return new SymbolIdentifier(A1);
1757 })
1758 ],
1759 DecoratorIdentifier: [
1760 o("DECORATOR", function() {
1761 return new DecoratorIdentifier(A1);
1762 })
1763 ],
1764 MixinIdentifier: [
1765 o("MIXIN", function() {
1766 return new MixinIdentifier(A1);
1767 })
1768 ],
1769 Key: [
1770 o("KEY", function() {
1771 return new Identifier(A1);
1772 })
1773 ],
1774 Argvar: [
1775 o("ARGVAR", function() {
1776 return new Argvar(A1);
1777 })
1778 ],
1779 Symbol: [
1780 o("SYMBOL", function() {
1781 return new Symbol(A1);
1782 })
1783 ],
1784 Decorator: [
1785 o("DecoratorIdentifier", function() {
1786 return new Decorator(A1);
1787 }),
1788 o("DecoratorIdentifier ( )", function() {
1789 return new Decorator(A1);
1790 }),
1791 o("DecoratorIdentifier ( ArgList )", function() {
1792 return new Decorator(A1).set({params: A3});
1793 }),
1794 o("Decorator . Identifier", function() {
1795 return A1.add(A3);
1796 })
1797 ],
1798 Decorators: [
1799 o("Decorator", function() {
1800 return [A1];
1801 }),
1802 o("Decorators Decorator", function() {
1803 return A1.concat(A2);
1804 })
1805 ],
1806 AlphaNumeric: [
1807 o("NUMBER UNIT", function() {
1808 return new NumWithUnit(A1, A2);
1809 }),
1810 o("NUMBER", function() {
1811 return new Num(A1);
1812 }),
1813 o("STRING", function() {
1814 return new Str(A1);
1815 }),
1816 o("Symbol"),
1817 o("InterpolatedString")
1818 ],
1819 String: [
1820 o("STRING", function() {
1821 return new Str(A1);
1822 })
1823 ],
1824 InterpolatedString: [
1825 o("STRING_START", function() {
1826 return new InterpolatedString([], {open: A1});
1827 }),
1828 o("InterpolatedString NEOSTRING", function() {
1829 return A1.add(A2);
1830 }),
1831 o("InterpolatedString Interpolation", function() {
1832 return A2 ? A1.add(A2) : A1;
1833 }),
1834 o("InterpolatedString STRING_END", function() {
1835 return A1.option("close", A2);
1836 })
1837 ],
1838 Interpolation: [
1839 o("{{ }}", function() {
1840 return null;
1841 }),
1842 o("{{ Expression }}", function() {
1843 return A2;
1844 })
1845 ],
1846 Literal: [
1847 o("AlphaNumeric"),
1848 o("JS", function() {
1849 return new Literal(A1);
1850 }),
1851 o("REGEX", function() {
1852 return new RegExp(A1);
1853 }),
1854 o("BOOL", function() {
1855 return new Bool(A1);
1856 }),
1857 o("TRUE", function() {
1858 return new True(A1);
1859 }),
1860 o("FALSE", function() {
1861 return new False(A1);
1862 }),
1863 o("NULL", function() {
1864 return new Nil(A1);
1865 }),
1866 o("UNDEFINED", function() {
1867 return new Undefined(A1);
1868 })
1869 ],
1870 Return: [
1871 o("RETURN Expression", function() {
1872 return new Return(A2).set({keyword: A1});
1873 }),
1874 o("RETURN Arguments", function() {
1875 return new Return(A2).set({keyword: A1});
1876 }),
1877 o("RETURN", function() {
1878 return new Return().set({keyword: A1});
1879 })
1880 ],
1881 Selector: [
1882 o("SELECTOR_START", function() {
1883 return new Selector([], {type: A1, open: A1});
1884 }),
1885 o("Selector SELECTOR_PART", function() {
1886 return A1.add(A2);
1887 }),
1888 o("Selector { Expression }", function() {
1889 return A1.add(A3);
1890 }),
1891 o("Selector SELECTOR_END", function() {
1892 return A1.option("close", A2);
1893 })
1894 ],
1895 Tag: [
1896 o("TAG_START TagOptions TAG_END", function() {
1897 return A2.set({open: A1, close: A3});
1898 }),
1899 o("TAG_START TagOptions TAG_END TagBody", function() {
1900 return A2.set({body: A4, open: A1, close: A3});
1901 })
1902 ],
1903 TagTypeName: [
1904 o("Self", function() {
1905 return A1;
1906 }),
1907 o("IDENTIFIER", function() {
1908 return new TagTypeIdentifier(A1);
1909 }),
1910 o("TAG_TYPE", function() {
1911 return new TagTypeIdentifier(A1);
1912 }),
1913 o("TagIdentifier", function() {
1914 return new ExpressionNode(A1);
1915 }),
1916 o("", function() {
1917 return new TagTypeIdentifier("div");
1918 })
1919 ],
1920 StyleBlockDeclaration: [
1921 o("CSS CSS_SEL StyleBody CSS_END", function() {
1922 return new StyleRuleSet(A2, A3);
1923 })
1924 ],
1925 CSSDeclaration: [
1926 o("StyleBlockDeclaration", function() {
1927 return A1.set({toplevel: true});
1928 }),
1929 o("GLOBAL CSSDeclaration", function() {
1930 return A2.set({global: A1});
1931 }),
1932 o("LOCAL CSSDeclaration", function() {
1933 return A2.set({local: A1});
1934 })
1935 ],
1936 StyleBlockBody: [
1937 o("INDENT Terminator OUTDENT", function() {
1938 return new StyleBody([]).indented(A1, A3);
1939 }),
1940 o("INDENT StyleBody Outdent", function() {
1941 return A2.indented(A1, A3);
1942 })
1943 ],
1944 OptStyleBody: [
1945 o("", function() {
1946 return new StyleBody([]);
1947 }),
1948 o("StyleBody")
1949 ],
1950 StyleBody: [
1951 o("StyleNode", function() {
1952 return new StyleBody([A1]);
1953 }),
1954 o("StyleBody StyleDeclaration", function() {
1955 return A1.add(A2);
1956 }),
1957 o("StyleBody Terminator StyleNode", function() {
1958 return A1.add(A3);
1959 }),
1960 o("INDENT StyleBody Outdent", function() {
1961 return A2.indented(A1, A3);
1962 })
1963 ],
1964 StyleNode: [
1965 o("StyleDeclaration"),
1966 o("CSS_SEL StyleBlockBody CSS_END", function() {
1967 return new StyleRuleSet(A1, A2);
1968 })
1969 ],
1970 StyleDeclaration: [
1971 o("StyleProperty : StyleExpressions", function() {
1972 return new StyleDeclaration(A1, A3.set({parens: false}));
1973 })
1974 ],
1975 StyleProperty: [
1976 o("CSSPROP", function() {
1977 return new StyleProperty([A1]);
1978 })
1979 ],
1980 StyleOperator: [
1981 o("MATH"),
1982 o("+"),
1983 o("-")
1984 ],
1985 StyleExpressions: [
1986 o("StyleExpression", function() {
1987 return new StyleExpressions([A1]);
1988 }),
1989 o("StyleExpressions , StyleExpression", function() {
1990 return A1.add(A3);
1991 })
1992 ],
1993 StyleExpression: [
1994 o("StyleTerm", function() {
1995 return new StyleExpression().add(A1);
1996 }),
1997 o("StyleExpression StyleOperator", function() {
1998 return A1.add(A2);
1999 }),
2000 o("StyleExpression StyleTerm", function() {
2001 return A1.add(A2);
2002 }),
2003 o("StyleExpression / StyleTerm", function() {
2004 return A1.addParam(A3, A2);
2005 })
2006 ],
2007 StyleValue: [
2008 o("StyleTerm"),
2009 o("StyleOperation")
2010 ],
2011 StyleOperation: [
2012 o("StyleTerm StyleOperator StyleTerm", function() {
2013 return new StyleOperation([A1, A2, A3]);
2014 }),
2015 o("StyleOperation StyleOperator StyleTerm", function() {
2016 return A1.add([A2, A3]);
2017 })
2018 ],
2019 StyleFunctionArgs: [
2020 o("StyleFunctionArg", function() {
2021 return new StyleExpressions([A1]);
2022 }),
2023 o("StyleFunctionArgs , StyleFunctionArg", function() {
2024 return A1.add(A3);
2025 })
2026 ],
2027 StyleFunctionArg: [
2028 o("StyleTerm", function() {
2029 return new StyleExpression().add(A1);
2030 }),
2031 o("StyleFunctionArg StyleOperator", function() {
2032 return A1.add(A2);
2033 }),
2034 o("StyleFunctionArg StyleTerm", function() {
2035 return A1.add(A2);
2036 }),
2037 o("StyleFunctionArg / StyleTerm", function() {
2038 return A1.addParam(A3, A2);
2039 })
2040 ],
2041 StyleTermPlaceholder: [
2042 o("{ Expression }", function() {
2043 return new StyleInterpolationExpression(A2).setEnds(A1, A3);
2044 }),
2045 o("StyleTermPlaceholder CSSUNIT", function() {
2046 return A1.set({unit: A2});
2047 })
2048 ],
2049 StyleParens: [
2050 o("( StyleValue )", function() {
2051 return new StyleParens(A2).setEnds(A1, A3);
2052 }),
2053 o("StyleParens CSSUNIT", function() {
2054 return A1.set({unit: A2});
2055 })
2056 ],
2057 StyleTerm: [
2058 o("StyleParens"),
2059 o("CSSVAR", function() {
2060 return new StyleVar(A1);
2061 }),
2062 o("DIMENSION", function() {
2063 return new StyleDimension(A1);
2064 }),
2065 o("COLOR", function() {
2066 return new StyleColor(A1);
2067 }),
2068 o("PERCENTAGE", function() {
2069 return new StyleDimension(A1);
2070 }),
2071 o("NUMBER", function() {
2072 return new StyleNumber(A1);
2073 }),
2074 o("String", function() {
2075 return A1;
2076 }),
2077 o("StyleTermPlaceholder", function() {
2078 return A1;
2079 }),
2080 o("CSSURL", function() {
2081 return new StyleURL(A1);
2082 }),
2083 o("CSSFUNCTION ( StyleFunctionArgs )", function() {
2084 return new StyleFunction(A1, A3);
2085 }),
2086 o("CSSIDENTIFIER", function() {
2087 return new StyleIdentifier(A1);
2088 }),
2089 o("COMPARE StyleTerm", function() {
2090 return A2.set({op: A1});
2091 })
2092 ],
2093 TagOptions: [
2094 o("TagTypeName TAG_REF", function() {
2095 return new Tag({type: A1, reference: A2});
2096 }),
2097 o("TagTypeName", function() {
2098 return new Tag({type: A1});
2099 }),
2100 o("TagOptions TAG_ID", function() {
2101 return A1.addPart(A2, AST.TagId);
2102 }),
2103 o("TagOptions TAG_SYMBOL_ID", function() {
2104 return A1.addPart(new IdentifierExpression(A2.cloneSlice(1)), AST.TagId);
2105 }),
2106 o("TagOptions SYMBOL_ID", function() {
2107 return A1.addPart(new IdentifierExpression(A2.cloneSlice(1)), AST.TagId);
2108 }),
2109 o("TagOptions TAG_FLAG", function() {
2110 return A1.addPart(A2, AST.TagFlag);
2111 }),
2112 o("TagOptions TAG_ATTR", function() {
2113 return A1.addPart(A2, AST.TagAttr);
2114 }),
2115 o("TagOptions TAG_ON", function() {
2116 return A1.addPart(A2, AST.TagHandler);
2117 }),
2118 o("TagOptions STYLE_START STYLE_END", function() {
2119 return A1;
2120 }),
2121 o("TagOptions STYLE_START StyleBody STYLE_END", function() {
2122 return A1.addPart(new StyleRuleSet(null, A3), AST.TagFlag);
2123 }),
2124 o("TagOptions T. STYLE_START StyleBody STYLE_END", function() {
2125 return A1.addPart(new StyleRuleSet(null, A4), AST.TagFlag);
2126 }),
2127 o("TagOptions MIXIN", function() {
2128 return A1.addPart(new MixinIdentifier(A2), AST.TagFlag);
2129 }),
2130 o("TagOptions T: TagIdentifier", function() {
2131 return A1.addPart(A3, AST.TagHandler);
2132 }),
2133 o("TagOptions T@ TagIdentifier", function() {
2134 return A1.addPart(A3, AST.TagHandler);
2135 }),
2136 o("TagOptions T. @ TAG_LITERAL", function() {
2137 return A1.addPart(A4.prepend("_"), AST.TagFlag);
2138 }),
2139 o("TagOptions T. UNARY TAG_LITERAL", function() {
2140 return A1.addPart(A4.prepend("!"), AST.TagFlag);
2141 }),
2142 o("TagOptions T. TagIdentifier", function() {
2143 return A1.addPart(A3, AST.TagFlag);
2144 }),
2145 o("TagOptions # TagIdentifier", function() {
2146 return A1.addPart(A3, AST.TagId);
2147 }),
2148 o("TagOptions TAG_WS TagIdentifier", function() {
2149 return A1.addPart(A2, AST.TagSep).addPart(A3, AST.TagAttr);
2150 }),
2151 o("TagOptions ( )", function() {
2152 return A1.addPart(new ArgList([]), AST.TagArgList);
2153 }),
2154 o("TagOptions ( ArgList )", function() {
2155 return A1.addPart(A3, AST.TagArgList);
2156 }),
2157 o("TagOptions CALL_START CALL_END", function() {
2158 return A1.addPart(null, AST.TagArgList);
2159 }),
2160 o("TagOptions CALL_START ArgList CALL_END", function() {
2161 return A1.addPart(A3, AST.TagArgList);
2162 }),
2163 o("TagOptions TAG_WS", function() {
2164 return A1.addPart(A2, AST.TagSep);
2165 }),
2166 o("TagOptions Comment", function() {
2167 return A1;
2168 }),
2169 o("TagOptions TERMINATOR", function() {
2170 return A1;
2171 }),
2172 o("TagOptions = TagAttrValue", function() {
2173 return A1.addPart(A3, AST.TagAttrValue, A2);
2174 })
2175 ],
2176 TagIdentifier: [
2177 o("TAG_LITERAL", function() {
2178 return new IdentifierExpression(A1);
2179 }),
2180 o("{ Expression }", function() {
2181 return new IdentifierExpression(A2);
2182 }),
2183 o("TagIdentifier TAG_LITERAL", function() {
2184 return A1.add(A2);
2185 }),
2186 o("TagIdentifier { Expression }", function() {
2187 return A1.add(A3);
2188 })
2189 ],
2190 TagFlag: [
2191 o("%", function() {
2192 return new TagFlag();
2193 }),
2194 o("TagFlag TagPartIdentifier", function() {
2195 return A1.add(A2);
2196 })
2197 ],
2198 TagAttrValue: [
2199 o("VALUE_START Expression VALUE_END", function() {
2200 return A2;
2201 })
2202 ],
2203 TagBody: [
2204 o("INDENT OUTDENT", function() {
2205 return new TagBody([]).indented(A1, A2);
2206 }),
2207 o("INDENT TagBodyList OUTDENT", function() {
2208 return A2.indented(A1, A3);
2209 }),
2210 o("CALL_START TagBodyList CALL_END", function() {
2211 return A2;
2212 }),
2213 o("Tag", function() {
2214 return new TagBody([A1]);
2215 })
2216 ],
2217 TagBodyList: [
2218 o("TagBodyItem", function() {
2219 return new TagBody([]).add(A1);
2220 }),
2221 o("TagBodyList , TagBodyItem", function() {
2222 return A1.add(A3);
2223 }),
2224 o("TagBodyList OptComma Terminator TagBodyItem", function() {
2225 return A1.add(A3).add(A4);
2226 }),
2227 o("TagBodyList OptComma TERMINATOR SEPARATOR Terminator TagBodyItem", function() {
2228 return A1.add(A5).add(A6);
2229 }),
2230 o("INDENT TagBodyList OptComma Outdent", function() {
2231 return A2.indented(A1, A4);
2232 }),
2233 o("TagBodyList OptComma INDENT TagBodyList OptComma Outdent", function() {
2234 return A1.concat(A4);
2235 })
2236 ],
2237 TagBodyItem: [
2238 o("Expression"),
2239 o("... Expression", function() {
2240 return new Splat(A2).set({keyword: A1});
2241 }),
2242 o("Splat"),
2243 o("LOGIC"),
2244 o("Comment"),
2245 o("TagHandler"),
2246 o("StyleBlockDeclaration", function() {
2247 return A1.set({inTagTree: true});
2248 })
2249 ],
2250 TagHandler: [
2251 o("DECORATOR", function() {
2252 return new TagHandler(new IdentifierExpression(A1.cloneSlice(1, "TAG_LITERAL")));
2253 }),
2254 o("TagHandler . IDENTIFIER", function() {
2255 return A1.add(A3);
2256 }),
2257 o("TagHandler CALL_START ArgList CALL_END", function() {
2258 return A1.add(A3, A2.generated ? AST.TagHandlerCallback : AST.TagArgList, A2, A4);
2259 })
2260 ],
2261 TagDeclaration: [
2262 o("TagDeclarationBlock", function() {
2263 return A1;
2264 }),
2265 o("EXTEND TagDeclarationBlock", function() {
2266 return A2.set({extension: true});
2267 }),
2268 o("LOCAL TagDeclarationBlock", function() {
2269 return A2.set({local: true});
2270 }),
2271 o("GLOBAL TagDeclarationBlock", function() {
2272 return A2.set({global: A1});
2273 })
2274 ],
2275 TagDeclarationBlock: [
2276 o("TAG TagType", function() {
2277 return new TagDeclaration(A2).set({keyword: A1});
2278 }),
2279 o("TAG TagType ClassBody", function() {
2280 return new TagDeclaration(A2, null, A3).set({keyword: A1});
2281 }),
2282 o("TAG TagType COMPARE TagType", function() {
2283 return new TagDeclaration(A2, A4).set({keyword: A1});
2284 }),
2285 o("TAG TagType COMPARE TagType ClassBody", function() {
2286 return new TagDeclaration(A2, A4, A5).set({keyword: A1});
2287 })
2288 ],
2289 TagType: [
2290 o("TAG_TYPE", function() {
2291 return new TagTypeIdentifier(A1);
2292 })
2293 ],
2294 TagId: [
2295 o("# IDENTIFIER", function() {
2296 return new TagIdRef(A2);
2297 })
2298 ],
2299 Assign: [
2300 o("VarAssign"),
2301 o("Assignable = Expression", function() {
2302 return new Assign(A2, A1, A3);
2303 }),
2304 o("Assignable = INDENT Expression Outdent", function() {
2305 return new Assign(A2, A1, A4.indented(A3, A5));
2306 })
2307 ],
2308 AssignObj: [
2309 o("... Expression", function() {
2310 return new ObjRestAttr(A2).set({spread: A1});
2311 }),
2312 o("MethodDeclaration", function() {
2313 return A1.set({inObject: true});
2314 }),
2315 o("ObjAssignable", function() {
2316 return new ObjAttr(A1);
2317 }),
2318 o("ObjAssignable : Expression", function() {
2319 return new ObjAttr(A1, A3);
2320 }),
2321 o("ObjAssignable : INDENT Expression Outdent", function() {
2322 return new ObjAttr(A1, A4.indented(A3, A5));
2323 }),
2324 o("SimpleObjAssignable = Expression", function() {
2325 return new ObjAttr(A1, null, A3);
2326 }),
2327 o("SimpleObjAssignable = INDENT Expression Outdent", function() {
2328 return new ObjAttr(A1, null, A4.indented(A3, A5));
2329 }),
2330 o("Comment")
2331 ],
2332 SimpleObjAssignable: [
2333 o("Identifier"),
2334 o("Identifier Type", function() {
2335 return A1.set({datatype: A2});
2336 }),
2337 o("SymbolIdentifier"),
2338 o("Key")
2339 ],
2340 ObjAssignable: [
2341 o("SimpleObjAssignable"),
2342 o("[ Expression ]", function() {
2343 return new IdentifierExpression(A2);
2344 }),
2345 o("( Expression )", function() {
2346 return new IdentifierExpression(A2);
2347 }),
2348 o("AlphaNumeric")
2349 ],
2350 Comment: [
2351 o("HERECOMMENT", function() {
2352 return new Comment(A1, true);
2353 }),
2354 o("COMMENT", function() {
2355 return new Comment(A1, false);
2356 })
2357 ],
2358 Code: [
2359 o("Method"),
2360 o("Do"),
2361 o("Begin")
2362 ],
2363 Begin: [
2364 o("BEGIN Block", function() {
2365 return new Begin(A2);
2366 })
2367 ],
2368 Do: [
2369 o("DO Block", function() {
2370 return new Lambda([], A2, null, null, {bound: true, keyword: A1});
2371 }),
2372 o("DO BLOCK_PARAM_START ParamList BLOCK_PARAM_END Block", function() {
2373 return new Lambda(A3, A5, null, null, {bound: true, keyword: A1});
2374 })
2375 ],
2376 Method: [
2377 o("MethodDeclaration", function() {
2378 return A1;
2379 }),
2380 o("GLOBAL MethodDeclaration", function() {
2381 return A2.set({global: A1});
2382 }),
2383 o("STATIC MethodDeclaration", function() {
2384 return A2.set({static: A1});
2385 })
2386 ],
2387 MethodDeclaration: [
2388 o("DEF MethodScope MethodScopeType MethodIdentifier MethodParams MethodBody", function() {
2389 return new MethodDeclaration(A5, A6, A4, A2, A3).set({def: A1, keyword: A1, datatype: A4.option("datatype")});
2390 }),
2391 o("DEF MethodIdentifier MethodParams MethodBody", function() {
2392 return new MethodDeclaration(A3, A4, A2, null).set({def: A1, keyword: A1, datatype: A2.option("datatype")});
2393 })
2394 ],
2395 MethodParams: [
2396 o("ParamList", function() {
2397 return A1;
2398 }),
2399 o("CALL_START ParamList CALL_END", function() {
2400 return A2;
2401 })
2402 ],
2403 MethodScopeType: [
2404 o(".", function() {
2405 return {static: true};
2406 }),
2407 o("#", function() {
2408 return {};
2409 })
2410 ],
2411 MethodIdentifier: [
2412 o("Identifier"),
2413 o("DecoratorIdentifier"),
2414 o("SymbolIdentifier", function() {
2415 return A1;
2416 }),
2417 o("[ Expression ]", function() {
2418 return new InterpolatedIdentifier(A2);
2419 }),
2420 o("MethodIdentifier Type", function() {
2421 return A1.set({datatype: A2});
2422 })
2423 ],
2424 MethodBody: [
2425 o("DEF_BODY Block", function() {
2426 return A2;
2427 }),
2428 o("DEF_BODY DO Block", function() {
2429 return A3;
2430 }),
2431 o("DEF_EMPTY", function() {
2432 return new Block([]).set({end: A1._loc});
2433 })
2434 ],
2435 MethodScope: [
2436 o("MethodIdentifier"),
2437 o("This"),
2438 o("Self")
2439 ],
2440 OptComma: [
2441 o(""),
2442 o(",")
2443 ],
2444 OptSemicolon: [
2445 o(""),
2446 o(";")
2447 ],
2448 ParamList: [
2449 o("", function() {
2450 return [];
2451 }),
2452 o("Param", function() {
2453 return [A1];
2454 }),
2455 o("ParamList , Param", function() {
2456 return A1.concat(A3);
2457 })
2458 ],
2459 ParamExpression: [
2460 o("Value"),
2461 o("Code"),
2462 o("Operation"),
2463 o("Assign"),
2464 o("Ternary"),
2465 o("Tag")
2466 ],
2467 ParamValue: [
2468 o("Expression")
2469 ],
2470 Param: [
2471 o("Object", function() {
2472 return new Param(A1);
2473 }),
2474 o("Array", function() {
2475 return new Param(A1);
2476 }),
2477 o("ParamVar"),
2478 o("... ParamVar", function() {
2479 return A2.set({splat: A1});
2480 }),
2481 o("BLOCK_ARG ParamVar", function() {
2482 return A2.set({blk: A1});
2483 }),
2484 o("ParamVar = ParamValue", function() {
2485 return new Param(A1.value(), A3).set({datatype: A1.option("datatype")});
2486 }),
2487 o("Object = ParamValue", function() {
2488 return new Param(A1, A3);
2489 }),
2490 o("Array = ParamValue", function() {
2491 return new Param(A1, A3);
2492 }),
2493 o("...", function() {
2494 return new RestParam(A1);
2495 })
2496 ],
2497 ParamVar: [
2498 o("Identifier", function() {
2499 return new Param(A1);
2500 }),
2501 o("Identifier Type", function() {
2502 return new Param(A1).set({datatype: A2});
2503 })
2504 ],
2505 Splat: [
2506 o("SPLAT Expression", function() {
2507 return AST.SPLAT(A2);
2508 })
2509 ],
2510 VarKeyword: [
2511 o("VAR"),
2512 o("LET"),
2513 o("CONST")
2514 ],
2515 VarAssignable: [
2516 o("Identifier"),
2517 o("Identifier Type", function() {
2518 return A1.set({datatype: A2});
2519 }),
2520 o("Array"),
2521 o("Object")
2522 ],
2523 VarDecl: [
2524 o("VarKeyword VarAssignable", function() {
2525 return new VarReference(A2, A1);
2526 })
2527 ],
2528 VarAssign: [
2529 o("VarDecl = Expression", function() {
2530 return new Assign(A2, A1, A3);
2531 }),
2532 o("VarDecl = INDENT Expression Outdent", function() {
2533 return new Assign(A2, A1, A4.indented(A3, A5));
2534 })
2535 ],
2536 SimpleAssignable: [
2537 o("ENV_FLAG", function() {
2538 return new EnvFlag(A1);
2539 }),
2540 o("Argvar"),
2541 o("Self"),
2542 o("Identifier", function() {
2543 return new VarOrAccess(A1);
2544 }),
2545 o("SymbolIdentifier", function() {
2546 return new Access(".", null, A1);
2547 }),
2548 o("Access"),
2549 o("SimpleAssignable Type", function() {
2550 return A1.set({datatype: A2});
2551 })
2552 ],
2553 Access: [
2554 o("Value SoakableOp Identifier", function() {
2555 return AST.OP(A2, A1, A3);
2556 }),
2557 o("Value SoakableOp SymbolIdentifier", function() {
2558 return new IndexAccess(A2, A1, A3);
2559 }),
2560 o("Value INDEX_START IndexValue INDEX_END", function() {
2561 return new IndexAccess(".", A1, A3);
2562 }),
2563 o("Value ?. [ IndexValue ]", function() {
2564 return AST.OP(A2, A1, A4);
2565 })
2566 ],
2567 SoakableOp: [
2568 ".",
2569 "?."
2570 ],
2571 Super: [
2572 o("SUPER", function() {
2573 return new Super(A1);
2574 })
2575 ],
2576 Assignable: [
2577 o("SimpleAssignable"),
2578 o("Array"),
2579 o("Object")
2580 ],
2581 TaggedTemplate: [
2582 o("SimpleAssignable InterpolatedString", function() {
2583 return new TaggedTemplate(A1, A2);
2584 }),
2585 o("SimpleAssignable String", function() {
2586 return new TaggedTemplate(A1, A2);
2587 })
2588 ],
2589 Await: [
2590 o("AWAIT Expression", function() {
2591 return new Await(A2).set({keyword: A1});
2592 })
2593 ],
2594 Value: [
2595 o("Assignable"),
2596 o("Super"),
2597 o("Literal"),
2598 o("Parenthetical"),
2599 o("Range"),
2600 o("ARGUMENTS", function() {
2601 return AST.ARGUMENTS;
2602 }),
2603 o("This"),
2604 o("TagId"),
2605 o("Selector"),
2606 o("Invocation"),
2607 o("TaggedTemplate"),
2608 o("Require"),
2609 o("Value BANG", function() {
2610 return new BangCall(A1).set({keyword: A2});
2611 })
2612 ],
2613 IndexValue: [
2614 o("Expression", function() {
2615 return new Index(A1);
2616 })
2617 ],
2618 Object: [
2619 o("{ AssignList OptComma }", function() {
2620 return new Obj(A2, A1.generated).setEnds(A1, A4);
2621 })
2622 ],
2623 AssignList: [
2624 o("", function() {
2625 return new AssignList([]);
2626 }),
2627 o("AssignObj", function() {
2628 return new AssignList([A1]);
2629 }),
2630 o("AssignList , AssignObj", function() {
2631 return A1.add(A3);
2632 }),
2633 o("AssignList OptComma Terminator AssignObj", function() {
2634 return A1.add(A3).add(A4);
2635 }),
2636 o("AssignList OptComma INDENT AssignList OptComma Outdent", function() {
2637 return A1.concat(A4.indented(A3, A6));
2638 })
2639 ],
2640 ExpressionList: [
2641 o("Expression", function() {
2642 return new ExpressionList([]).add(A1);
2643 }),
2644 o("ExpressionList , Expression", function() {
2645 return A1.add(A3);
2646 }),
2647 o("ExpressionList OptComma Terminator Expression", function() {
2648 return A1.add(A3).add(A4);
2649 }),
2650 o("INDENT ExpressionList OptComma Outdent", function() {
2651 return A2.indented(A1, A4);
2652 }),
2653 o("ExpressionList OptComma INDENT ExpressionList OptComma Outdent", function() {
2654 return A1.concat(A4);
2655 })
2656 ],
2657 Class: [
2658 o("ClassStart", function() {
2659 return A1;
2660 }),
2661 o("EXTEND ClassStart", function() {
2662 return A2.set({extension: A1});
2663 }),
2664 o("LOCAL ClassStart", function() {
2665 return A2.set({local: A1});
2666 }),
2667 o("GLOBAL ClassStart", function() {
2668 return A2.set({global: A1});
2669 })
2670 ],
2671 ClassStart: [
2672 o("CLASS ClassName ClassBody", function() {
2673 return new ClassDeclaration(A2, null, A3).set({keyword: A1});
2674 }),
2675 o("CLASS ClassName", function() {
2676 return new ClassDeclaration(A2, null, []).set({keyword: A1});
2677 }),
2678 o("CLASS ClassBody", function() {
2679 return new ClassDeclaration(null, null, A2).set({keyword: A1});
2680 }),
2681 o("CLASS ClassName COMPARE Expression", function() {
2682 return new ClassDeclaration(A2, A4, []).set({keyword: A1});
2683 }),
2684 o("CLASS ClassName COMPARE Expression ClassBody", function() {
2685 return new ClassDeclaration(A2, A4, A5).set({keyword: A1});
2686 }),
2687 o("CLASS COMPARE Expression ClassBody", function() {
2688 return new ClassDeclaration(null, A3, A4).set({keyword: A1});
2689 })
2690 ],
2691 ClassName: [
2692 o("Identifier", function() {
2693 return new VarOrAccess(A1);
2694 }),
2695 o("SymbolIdentifier", function() {
2696 return new Access(".", null, A1);
2697 }),
2698 o("ClassName . Identifier", function() {
2699 return AST.OP(A2, A1, A3);
2700 }),
2701 o("ClassName . SymbolIdentifier", function() {
2702 return new IndexAccess(A2, A1, A3);
2703 })
2704 ],
2705 ClassBody: [
2706 o("INDENT OUTDENT", function() {
2707 return new ClassBody([]).indented(A1, A2);
2708 }),
2709 o("INDENT ClassBodyBlock OUTDENT", function() {
2710 return A2.indented(A1, A3);
2711 }),
2712 o("INDENT TERMINATOR ClassBodyBlock OUTDENT", function() {
2713 return A3.prebreak(A2).indented(A1, A4);
2714 })
2715 ],
2716 ClassBodyBlock: [
2717 o("ClassBodyLine", function() {
2718 return new ClassBody([]).add(A1);
2719 }),
2720 o("ClassBodyBlock Terminator ClassBodyLine", function() {
2721 return A1.break(A2).add(A3);
2722 }),
2723 o("ClassBodyBlock Terminator", function() {
2724 return A1.break(A2);
2725 })
2726 ],
2727 ClassBodyLine: [
2728 o("Decorators"),
2729 o("ClassDeclLine"),
2730 o("Decorators ClassDeclLine", function() {
2731 return A1.concat([A2]);
2732 }),
2733 o("CSSDeclaration"),
2734 o("Comment"),
2735 o("Tag")
2736 ],
2737 ClassDeclLine: [
2738 o("STATIC ClassFieldDeclaration", function() {
2739 return A2.set({static: A1});
2740 }),
2741 o("DECLARE STATIC ClassFieldDeclaration", function() {
2742 return A3.set({static: A2, declareOnly: A1});
2743 }),
2744 o("DECLARE ClassFieldDeclaration", function() {
2745 return A2.set({declareOnly: A1});
2746 }),
2747 o("STATIC MethodDeclaration", function() {
2748 return A2.set({static: A1});
2749 }),
2750 o("MethodDeclaration"),
2751 o("ClassFieldDeclaration")
2752 ],
2753 ClassFieldDeclaration: [
2754 o("ClassField ClassFieldOp Expression", function() {
2755 return A1.set({value: A3, op: A2});
2756 }),
2757 o("ClassField", function() {
2758 return A1;
2759 }),
2760 o("ClassFieldDeclaration @ WatchBody", function() {
2761 return A1.set({watch: A3});
2762 }),
2763 o("ClassFieldDeclaration DECORATOR WatchBody", function() {
2764 return A1.set({watch: A3});
2765 })
2766 ],
2767 ClassFieldDecoration: [
2768 o("ClassFieldDeclaration @ WatchBody", function() {
2769 return A1.set({watch: A3});
2770 })
2771 ],
2772 WatchBody: [
2773 o("Block"),
2774 o("Expression")
2775 ],
2776 ClassFieldOp: [
2777 "=",
2778 "COMPOUND_ASSIGN"
2779 ],
2780 ClassField: [
2781 o("ClassFieldIdentifier", function() {
2782 return new ClassField(A1);
2783 }),
2784 o("PROP ClassFieldIdentifier", function() {
2785 return new ClassProperty(A2).set({keyword: A1});
2786 }),
2787 o("ATTR ClassFieldIdentifier", function() {
2788 return new ClassAttribute(A2).set({keyword: A1});
2789 }),
2790 o("ClassField Type", function() {
2791 return A1.set({datatype: A2});
2792 })
2793 ],
2794 ClassFieldIdentifier: [
2795 o("Identifier"),
2796 o("SymbolIdentifier")
2797 ],
2798 ClassFieldBody: [
2799 o("WATCH Expression Terminator", function() {
2800 return [A1, A2];
2801 })
2802 ],
2803 Invocation: [
2804 o("Value OptFuncExist Arguments", function() {
2805 return new Call(A1, A3, A2);
2806 }),
2807 o("Value Do", function() {
2808 return A1.addBlock(A2);
2809 })
2810 ],
2811 OptFuncExist: [
2812 o("", function() {
2813 return false;
2814 }),
2815 o("FUNC_EXIST", function() {
2816 return true;
2817 })
2818 ],
2819 Arguments: [
2820 o("CALL_START CALL_END", function() {
2821 return new ArgList([]).setEnds(A1, A2);
2822 }),
2823 o("CALL_START ArgList OptComma CALL_END", function() {
2824 return A2.setEnds(A1, A4);
2825 })
2826 ],
2827 This: [
2828 o("THIS", function() {
2829 return new This(A1);
2830 })
2831 ],
2832 Self: [
2833 o("SELF", function() {
2834 return new Self(A1);
2835 })
2836 ],
2837 Array: [
2838 o("[ ]", function() {
2839 return new Arr(new ArgList([])).setEnds(A1, A2);
2840 }),
2841 o("[ ArgList OptComma ]", function() {
2842 return new Arr(A2).setEnds(A1, A2);
2843 }),
2844 o("Array Type", function() {
2845 return A1.set({datatype: A2});
2846 })
2847 ],
2848 RangeDots: [
2849 o("..", function() {
2850 return "..";
2851 }),
2852 o("...", function() {
2853 return "...";
2854 })
2855 ],
2856 Range: [
2857 o("[ Expression RangeDots Expression ]", function() {
2858 return AST.OP(A3, A2, A4);
2859 })
2860 ],
2861 ArgList: [
2862 o("Arg", function() {
2863 return new ArgList([A1]);
2864 }),
2865 o("ArgList , Arg", function() {
2866 return A1.add(A3);
2867 }),
2868 o("ArgList OptComma Terminator Arg", function() {
2869 return A1.add(A3).add(A4);
2870 }),
2871 o("ArgList OptComma TERMINATOR SEPARATOR Terminator Arg", function() {
2872 return A1.add(A5).add(A6);
2873 }),
2874 o("INDENT ArgList OptComma Outdent", function() {
2875 return A2.indented(A1, A4);
2876 }),
2877 o("ArgList OptComma INDENT ArgList OptComma Outdent", function() {
2878 return A1.concat(A4);
2879 })
2880 ],
2881 Outdent: [
2882 o("Terminator OUTDENT", function() {
2883 return A1;
2884 }),
2885 o("OUTDENT", function() {
2886 return A1;
2887 })
2888 ],
2889 Arg: [
2890 o("Expression"),
2891 o("... Expression", function() {
2892 return new Splat(A2).set({keyword: A1});
2893 }),
2894 o("Splat"),
2895 o("DO_PLACEHOLDER", function() {
2896 return new DoPlaceholder(A1);
2897 }),
2898 o("Comment")
2899 ],
2900 SimpleArgs: [
2901 o("Expression"),
2902 o("SimpleArgs , Expression", function() {
2903 return [].concat(A1, A3);
2904 })
2905 ],
2906 Try: [
2907 o("TRY Block", function() {
2908 return new Try(A2);
2909 }),
2910 o("TRY Block Catch", function() {
2911 return new Try(A2, A3);
2912 }),
2913 o("TRY Block Finally", function() {
2914 return new Try(A2, null, A3);
2915 }),
2916 o("TRY Block Catch Finally", function() {
2917 return new Try(A2, A3, A4);
2918 })
2919 ],
2920 Finally: [
2921 o("FINALLY Block", function() {
2922 return new Finally(A2);
2923 })
2924 ],
2925 Catch: [
2926 o("CATCH CATCH_VAR Block", function() {
2927 return new Catch(A3, A2);
2928 }),
2929 o("CATCH Block", function() {
2930 return new Catch(A2, null);
2931 })
2932 ],
2933 Throw: [
2934 o("THROW Expression", function() {
2935 return new Throw(A2);
2936 })
2937 ],
2938 Parenthetical: [
2939 o("( ExpressionList )", function() {
2940 return new Parens(A2, A1, A3);
2941 }),
2942 o("( ExpressionList ) UNIT", function() {
2943 return new ExpressionWithUnit(new Parens(A2, A1, A3), A4);
2944 }),
2945 o("Parenthetical Type", function() {
2946 return A1.set({datatype: A2});
2947 })
2948 ],
2949 WhileSource: [
2950 o("WHILE Expression", function() {
2951 return new While(A2, {keyword: A1});
2952 }),
2953 o("WHILE Expression WHEN Expression", function() {
2954 return new While(A2, {guard: A4, keyword: A1});
2955 }),
2956 o("UNTIL Expression", function() {
2957 return new While(A2, {invert: true, keyword: A1});
2958 }),
2959 o("UNTIL Expression WHEN Expression", function() {
2960 return new While(A2, {invert: true, guard: A4, keyword: A1});
2961 })
2962 ],
2963 While: [
2964 o("WhileSource Block", function() {
2965 return A1.addBody(A2);
2966 }),
2967 o("Statement WhileSource", function() {
2968 return A2.addBody(Block.wrap([A1]));
2969 }),
2970 o("Expression WhileSource", function() {
2971 return A2.addBody(Block.wrap([A1]));
2972 }),
2973 o("Loop", function() {
2974 return A1;
2975 })
2976 ],
2977 Loop: [
2978 o("LOOP Block", function() {
2979 return new While(new Literal("true", {keyword: A1})).addBody(A2);
2980 }),
2981 o("LOOP Expression", function() {
2982 return new While(new Literal("true", {keyword: A1})).addBody(Block.wrap([A2]));
2983 })
2984 ],
2985 For: [
2986 o("Statement ForBody", function() {
2987 return A2.addBody([A1]);
2988 }),
2989 o("Expression ForBody", function() {
2990 return A2.addBody([A1]);
2991 }),
2992 o("ForBody Block", function() {
2993 return A1.addBody(A2);
2994 }),
2995 o("ForBody Block ELSE Block", function() {
2996 return A1.addBody(A2).addElse(A4);
2997 })
2998 ],
2999 ForKeyword: [
3000 o("FOR"),
3001 o("POST_FOR")
3002 ],
3003 ForBody: [
3004 o("ForKeyword Range", function() {
3005 return {source: new ValueNode(A2)};
3006 }),
3007 o("ForStart ForSource", function() {
3008 return A2.configure({own: A1.own, await: A1.await, name: A1[0], index: A1[1], keyword: A1.keyword, params: A1});
3009 })
3010 ],
3011 ForStart: [
3012 o("ForKeyword ForVariables", function() {
3013 return (A2.keyword = A1) && A2;
3014 }),
3015 o("ForKeyword AWAIT ForVariables", function() {
3016 return (A3.await = A2) && (A3.keyword = A1) && A3;
3017 }),
3018 o("ForKeyword OWN ForVariables", function() {
3019 return (A3.own = true) && (A3.keyword = A1) && A3;
3020 })
3021 ],
3022 ForValue: [
3023 o("Identifier"),
3024 o("Identifier Type", function() {
3025 return A1.set({datatype: A2});
3026 }),
3027 o("Array"),
3028 o("Object")
3029 ],
3030 ForVariables: [
3031 o("ForValue", function() {
3032 return [A1];
3033 }),
3034 o("ForValue , ForValue", function() {
3035 return [A1, A3];
3036 }),
3037 o("ForValue , ForValue , ForValue", function() {
3038 return [A1, A3, A5];
3039 })
3040 ],
3041 ForSource: [
3042 o("FORIN Expression", function() {
3043 return new ForIn({source: A2});
3044 }),
3045 o("FOROF Expression", function() {
3046 return new ForOf({source: A2, object: true});
3047 }),
3048 o("FORIN Expression WHEN Expression", function() {
3049 return new ForIn({source: A2, guard: A4});
3050 }),
3051 o("FOROF Expression WHEN Expression", function() {
3052 return new ForOf({source: A2, guard: A4, object: true});
3053 }),
3054 o("FORIN Expression BY Expression", function() {
3055 return new ForIn({source: A2, step: A4});
3056 }),
3057 o("FORIN Expression WHEN Expression BY Expression", function() {
3058 return new ForIn({source: A2, guard: A4, step: A6});
3059 }),
3060 o("FORIN Expression BY Expression WHEN Expression", function() {
3061 return new ForIn({source: A2, step: A4, guard: A6});
3062 })
3063 ],
3064 Switch: [
3065 o("SWITCH Expression INDENT Whens OUTDENT", function() {
3066 return new Switch(A2, A4);
3067 }),
3068 o("SWITCH Expression INDENT Whens ELSE Block Outdent", function() {
3069 return new Switch(A2, A4, A6);
3070 }),
3071 o("SWITCH INDENT Whens OUTDENT", function() {
3072 return new Switch(null, A3);
3073 }),
3074 o("SWITCH INDENT Whens ELSE Block OUTDENT", function() {
3075 return new Switch(null, A3, A5);
3076 })
3077 ],
3078 Whens: [
3079 o("When"),
3080 o("Whens When", function() {
3081 return A1.concat(A2);
3082 })
3083 ],
3084 When: [
3085 o("LEADING_WHEN SimpleArgs Block", function() {
3086 return [new SwitchCase(A2, A3)];
3087 }),
3088 o("LEADING_WHEN SimpleArgs Block TERMINATOR", function() {
3089 return [new SwitchCase(A2, A3)];
3090 })
3091 ],
3092 IfBlock: [
3093 o("IF Expression Block", function() {
3094 return new If(A2, A3, {type: A1});
3095 }),
3096 o("IfBlock ELSE IF Expression Block", function() {
3097 return A1.addElse(new If(A4, A5, {type: A3}));
3098 }),
3099 o("IfBlock ELIF Expression Block", function() {
3100 return A1.addElse(new If(A3, A4, {type: A2}));
3101 }),
3102 o("IfBlock ELSE Block", function() {
3103 return A1.addElse(A3.set({keyword: A2}));
3104 })
3105 ],
3106 If: [
3107 o("IfBlock"),
3108 o("Statement POST_IF Expression", function() {
3109 return new If(A3, new Block([A1]), {type: A2, statement: true});
3110 }),
3111 o("Expression POST_IF Expression", function() {
3112 return new If(A3, new Block([A1]), {type: A2});
3113 })
3114 ],
3115 Ternary: [
3116 o("Expression ? Expression : Expression", function() {
3117 return AST.If.ternary(A1, A3, A5);
3118 })
3119 ],
3120 Operation: [
3121 o("NEW Expression", function() {
3122 return AST.Instantiation.for(A2, A1);
3123 }),
3124 o("UNARY Expression", function() {
3125 return AST.OP(A1, A2);
3126 }),
3127 o("SQRT Expression", function() {
3128 return AST.OP(A1, A2);
3129 }),
3130 o("--- Expression", function() {
3131 return AST.OP(A1, A2);
3132 }),
3133 o("+++ Expression", function() {
3134 return AST.OP(A1, A2);
3135 }),
3136 o("- Expression", function() {
3137 return AST.OP(A1, A2);
3138 }, {prec: "UNARY"}),
3139 o("+ Expression", function() {
3140 return AST.OP(A1, A2);
3141 }, {prec: "UNARY"}),
3142 o("-- SimpleAssignable", function() {
3143 return new UnaryOp(A1, null, A2);
3144 }),
3145 o("++ SimpleAssignable", function() {
3146 return new UnaryOp(A1, null, A2);
3147 }),
3148 o("SimpleAssignable --", function() {
3149 return new UnaryOp(A2, A1, null, true);
3150 }),
3151 o("SimpleAssignable ++", function() {
3152 return new UnaryOp(A2, A1, null, true);
3153 }),
3154 o("Expression + Expression", function() {
3155 return new Op(A2, A1, A3);
3156 }),
3157 o("Expression - Expression", function() {
3158 return new Op(A2, A1, A3);
3159 }),
3160 o("Expression EXP Expression", function() {
3161 return AST.OP(A2, A1, A3);
3162 }),
3163 o("Expression MATH Expression", function() {
3164 return AST.OP(A2, A1, A3);
3165 }),
3166 o("Expression SHIFT Expression", function() {
3167 return AST.OP(A2, A1, A3);
3168 }),
3169 o("Expression COMPARE Expression", function() {
3170 return AST.OP(A2, A1, A3);
3171 }),
3172 o("Expression LOGIC Expression", function() {
3173 return AST.OP(A2, A1, A3);
3174 }),
3175 o("Expression NOT RELATION Expression", function() {
3176 return AST.OP(A3, A1, A4).invert(A2);
3177 }),
3178 o("Expression RELATION Expression", function() {
3179 return AST.OP(A2, A1, A3);
3180 }),
3181 o("SimpleAssignable COMPOUND_ASSIGN Expression", function() {
3182 return AST.OP(A2, A1, A3);
3183 }),
3184 o("SimpleAssignable COMPOUND_ASSIGN INDENT Expression Outdent", function() {
3185 return AST.OP(A2, A1, A4.indented(A3, A5));
3186 })
3187 ]
3188};
3189var operators = [
3190 ["left", ".", "?.", "::", ".:"],
3191 ["left", "CALL_START", "CALL_END"],
3192 ["nonassoc", "++", "--"],
3193 ["right", "UNARY", "NEW", "THROW", "SQRT", "NOT"],
3194 ["right", "AWAIT"],
3195 ["right", "EXP"],
3196 ["left", "MATH"],
3197 ["left", "+", "-", "+++", "---"],
3198 ["left", "SHIFT"],
3199 ["left", "RELATION"],
3200 ["left", "COMPARE"],
3201 ["left", "LOGIC"],
3202 ["right", "?"],
3203 ["nonassoc", "INDENT", "OUTDENT"],
3204 ["right", "=", ":", "COMPOUND_ASSIGN", "RETURN", "THROW", "EXTENDS"],
3205 ["right", "FORIN", "FOROF", "BY", "WHEN"],
3206 ["right", "TAG_END"],
3207 ["right", "IF", "ELSE", "FOR", "DO", "WHILE", "UNTIL", "LOOP", "SUPER", "CLASS", "MODULE", "TAG", "EVENT", "TRIGGER", "TAG_END", "IMPORT", "EXPORT"],
3208 ["right", "POST_IF", "POST_FOR"],
3209 ["right", "NEW_TAG"],
3210 ["right", "TAG_ATTR_SET"],
3211 ["right", "SPLAT"],
3212 ["left", "SELECTOR_START"],
3213 ["left", "CSS"]
3214];
3215var tokens = [];
3216for (let name in grammar) {
3217 let alternatives;
3218 alternatives = grammar[name];
3219 let res = [];
3220 for (let i = 0, items = iter$(alternatives), len = items.length, alt; i < len; i++) {
3221 alt = items[i];
3222 for (let j = 0, ary = iter$(alt[0].split(" ")), len2 = ary.length, token; j < len2; j++) {
3223 token = ary[j];
3224 if (!grammar[token]) {
3225 tokens.push(token);
3226 }
3227 ;
3228 }
3229 ;
3230 if (name === "Root") {
3231 alt[1] = "return " + alt[1];
3232 }
3233 ;
3234 res.push(alt);
3235 }
3236 ;
3237 grammar[name] = res;
3238}
3239exports.parser = new Parser({
3240 tokens: tokens.join(" "),
3241 bnf: grammar,
3242 operators: operators.reverse(),
3243 startSymbol: "Root"
3244});