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