commit
message
[Parser] using enums for ReduceActions to make actions mappings easier to read
author
Ben Vogt <[email protected]>
date
2017-08-19 19:39:20
stats
1 file(s) changed,
180 insertions(+),
136 deletions(-)
files
src/Parser/Parser.ts
1diff --git a/src/Parser/Parser.ts b/src/Parser/Parser.ts
2index a659733..c4ed676 100644
3--- a/src/Parser/Parser.ts
4+++ b/src/Parser/Parser.ts
5@@ -1,7 +1,7 @@
6 import {
7 RULES,
8
9- // WHITE_SPACE_RULE_INDEX,
10+ WHITE_SPACE_RULE_INDEX,
11 DOUBLE_QUOTES_RULE_INDEX,
12 SINGLE_QUOTES_RULE_INDEX,
13 FORMULA_NAME_RULE_INDEX,
14@@ -54,6 +54,53 @@ const enum LexActions {
15 ACCEPT
16 }
17
18+
19+const enum ReduceActions {
20+ I1 = 1,
21+ I2,
22+ I3,
23+ I4,
24+ I5,
25+ I6,
26+ I7,
27+ I8,
28+ I9,
29+ I10,
30+ I11,
31+ I12,
32+ I13,
33+ I14,
34+ I15,
35+ I16,
36+ I17,
37+ I18,
38+ I19,
39+ I20,
40+ I21,
41+ I22,
42+ I23,
43+ I24,
44+ I25,
45+ I26,
46+ I27,
47+ I28,
48+ I29,
49+ I30,
50+ I31,
51+ I32,
52+ I33,
53+ I34,
54+ I35,
55+ I36,
56+ I37,
57+ I38,
58+ I39,
59+ I40,
60+ I41,
61+ I42
62+}
63+
64+
65 /**
66 * Parser initially generated by jison 0.4.15, but modified for readability and extensibility.
67 */
68@@ -324,110 +371,108 @@ let Parser = (function () {
69 [2, 3],
70 [2, 4]
71 ],
72- performAction: function anonymous(yytext, yyleng, yylineno, yy, actionIndexToPerform /* action[1] */, virtualStack /* vstack */) {
73+ performAction: function (yytext, yyleng, yylineno, yy, actionIndexToPerform /* action[1] */, virtualStack /* vstack */) {
74 // For context, this function is only called with `call` or `apply`, so `this` is `yyval`.
75
76 let $0 = virtualStack.length - 1;
77 switch (actionIndexToPerform) {
78- case 1:
79+ case ReduceActions.I1:
80 return virtualStack[$0 - 1];
81- case 2:
82+ case ReduceActions.I2:
83 this.$ = yy.handler.helper.callVariable.call(this, virtualStack[$0]);
84 break;
85- case 3:
86+ case ReduceActions.I3:
87 this.$ = yy.handler.time.call(yy.obj, virtualStack[$0], true);
88 break;
89- case 4:
90+ case ReduceActions.I4:
91 this.$ = yy.handler.time.call(yy.obj, virtualStack[$0]);
92 break;
93- case 5:
94+ case ReduceActions.I5:
95 this.$ = yy.handler.helper.number(virtualStack[$0]);
96 break;
97- case 6:
98+ case ReduceActions.I6:
99 this.$ = yy.handler.helper.string(virtualStack[$0]);
100 break;
101- case 7:
102+ case ReduceActions.I7:
103 this.$ = yy.handler.helper.specialMatch('&', virtualStack[$0 - 2], virtualStack[$0]);
104 break;
105- case 8:
106+ case ReduceActions.I8:
107 this.$ = yy.handler.helper.logicMatch('=', virtualStack[$0 - 2], virtualStack[$0]);
108 break;
109- case 9:
110+ case ReduceActions.I9:
111 this.$ = yy.handler.helper.mathMatch('+', virtualStack[$0 - 2], virtualStack[$0]);
112 break;
113- case 10:
114+ case ReduceActions.I10:
115 this.$ = yy.handler.helper.number(virtualStack[$0 - 1]);
116 break;
117- case 11:
118+ case ReduceActions.I11:
119 this.$ = yy.handler.helper.logicMatch('<=', virtualStack[$0 - 3], virtualStack[$0]);
120 break;
121- case 12:
122+ case ReduceActions.I12:
123 this.$ = yy.handler.helper.logicMatch('>=', virtualStack[$0 - 3], virtualStack[$0]);
124 break;
125- case 13:
126+ case ReduceActions.I13:
127 this.$ = yy.handler.helper.logicMatch('<>', virtualStack[$0 - 3], virtualStack[$0]);
128 break;
129- case 14:
130+ case ReduceActions.I14:
131 this.$ = yy.handler.helper.logicMatch('NOT', virtualStack[$0 - 2], virtualStack[$0]);
132 break;
133- case 15:
134+ case ReduceActions.I15:
135 this.$ = yy.handler.helper.logicMatch('>', virtualStack[$0 - 2], virtualStack[$0]);
136 break;
137- case 16:
138+ case ReduceActions.I16:
139 this.$ = yy.handler.helper.logicMatch('<', virtualStack[$0 - 2], virtualStack[$0]);
140 break;
141- case 17:
142+ case ReduceActions.I17:
143 this.$ = yy.handler.helper.mathMatch('-', virtualStack[$0 - 2], virtualStack[$0]);
144 break;
145- case 18:
146+ case ReduceActions.I18:
147 this.$ = yy.handler.helper.mathMatch('*', virtualStack[$0 - 2], virtualStack[$0]);
148 break;
149- case 19:
150+ case ReduceActions.I19:
151 this.$ = yy.handler.helper.mathMatch('/', virtualStack[$0 - 2], virtualStack[$0]);
152 break;
153- case 20:
154+ case ReduceActions.I20:
155 this.$ = yy.handler.helper.mathMatch('^', virtualStack[$0 - 2], virtualStack[$0]);
156 break;
157- case 21:
158+ case ReduceActions.I21:
159 this.$ = yy.handler.helper.numberInverted(virtualStack[$0]);
160 if (isNaN(this.$)) {
161 this.$ = 0;
162 }
163 break;
164- case 22:
165+ case ReduceActions.I22:
166 this.$ = yy.handler.helper.number(virtualStack[$0]);
167 if (isNaN(this.$)) {
168 this.$ = 0;
169 }
170 break;
171- case 23:
172- // console.log("message from parser: 'calling function with no args': ", $$[$0 - 2]);
173+ case ReduceActions.I23:
174 this.$ = yy.handler.helper.callFunction.call(this, virtualStack[$0 - 2], '');
175 break;
176- case 24:
177- // console.log("message from parser: 'calling function w/ args': ", $$[$0 - 3], $$[$0 - 1]);
178+ case ReduceActions.I24:
179 this.$ = yy.handler.helper.callFunction.call(this, virtualStack[$0 - 3], virtualStack[$0 - 1]);
180 break;
181- case 28:
182+ case ReduceActions.I28:
183 this.$ = yy.handler.helper.fixedCellValue.call(yy.obj, virtualStack[$0]);
184 break;
185- case 29:
186+ case ReduceActions.I29:
187 this.$ = yy.handler.helper.fixedCellRangeValue.call(yy.obj, virtualStack[$0 - 2], virtualStack[$0]);
188 break;
189- case 30:
190+ case ReduceActions.I30:
191 this.$ = yy.handler.helper.cellValue.call(yy.obj, virtualStack[$0]);
192 break;
193- case 31:
194+ case ReduceActions.I31:
195 this.$ = yy.handler.helper.cellRangeValue.call(yy.obj, virtualStack[$0 - 2], virtualStack[$0]);
196 break;
197- case 32:
198+ case ReduceActions.I32:
199 if (yy.handler.utils.isArray(virtualStack[$0])) {
200 this.$ = virtualStack[$0];
201 } else {
202 this.$ = [virtualStack[$0]];
203 }
204 break;
205- case 33:
206+ case ReduceActions.I33:
207 let result = [],
208 arr = eval("[" + yytext + "]");
209 arr.forEach(function (item) {
210@@ -435,29 +480,29 @@ let Parser = (function () {
211 });
212 this.$ = result;
213 break;
214- case 34:
215- case 35:
216+ case ReduceActions.I34:
217+ case ReduceActions.I35:
218 virtualStack[$0 - 2].push(virtualStack[$0]);
219 this.$ = virtualStack[$0 - 2];
220 break;
221- case 36:
222+ case ReduceActions.I36:
223 this.$ = [virtualStack[$0]];
224 break;
225- case 37:
226+ case ReduceActions.I37:
227 this.$ = (yy.handler.utils.isArray(virtualStack[$0 - 2]) ? virtualStack[$0 - 2] : [virtualStack[$0 - 2]]);
228 this.$.push(virtualStack[$0]);
229 break;
230- case 38:
231+ case ReduceActions.I38:
232 this.$ = virtualStack[$0];
233 break;
234- case 39:
235+ case ReduceActions.I39:
236 this.$ = parseFloat(virtualStack[$0 - 2] + '.' + virtualStack[$0]);
237 break;
238- case 40:
239+ case ReduceActions.I40:
240 this.$ = virtualStack[$0 - 1] * 0.01;
241 break;
242- case 41:
243- case 42:
244+ case ReduceActions.I41:
245+ case ReduceActions.I42:
246 this.$ = virtualStack[$0 - 2] + virtualStack[$0 - 1] + virtualStack[$0];
247 break;
248 }
249@@ -1531,7 +1576,7 @@ let Parser = (function () {
250 this._backtrack = false;
251 this._input = this._input.slice(match[0].length);
252 this.matched += match[0];
253- token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
254+ token = this.mapActionToActionIndex(indexed_rule);
255 if (this.done && this._input) {
256 this.done = false;
257 }
258@@ -1664,88 +1709,84 @@ let Parser = (function () {
259 // ranges?
260 // flex?
261 },
262- performAction: function anonymous(yy, yy_, $avoiding_name_collisions) {
263- switch ($avoiding_name_collisions) {
264- case 0:
265+ mapActionToActionIndex: function (ruleIndex) {
266+ switch (ruleIndex) {
267+ case WHITE_SPACE_RULE_INDEX:
268 // skip whitespace
269 break;
270- case 1:
271- return 10;
272- case 2:
273- return 10;
274- case 3:
275- return 23;
276- case 4:
277- return 7;
278- case 5:
279- return 8;
280- case 6:
281- //if (yy.obj.type == 'cell') return 26;
282- //return 32;
283- return 26;
284- case 7:
285- //if (yy.obj.type == 'cell') return 28;
286- //return 32;
287- return 28;
288- case 8:
289- return 23;
290- case 9:
291- return 32;
292- case 10:
293- return 32;
294- case 11:
295- return 34;
296- case 12:
297- return 29;
298- case 13:
299- // skip whitespace
300+ case DOUBLE_QUOTES_RULE_INDEX:
301+ return ReduceActions.I10;
302+ case SINGLE_QUOTES_RULE_INDEX:
303+ return ReduceActions.I10;
304+ case FORMULA_NAME_RULE_INDEX:
305+ return ReduceActions.I23;
306+ case DATE_RULE_INDEX:
307+ return ReduceActions.I7;
308+ case TIME_RULE_INDEX:
309+ return ReduceActions.I8;
310+ case $_A1_CELL_RULE_INDEX:
311+ return ReduceActions.I26;
312+ case A1_CELL_RULE_INDEX:
313+ return ReduceActions.I28;
314+ case FORMULA_NAME_SIMPLE_RULE_INDEX:
315+ return ReduceActions.I23;
316+ case VARIABLE_RULE_INDEX:
317+ return ReduceActions.I32;
318+ case SIMPLE_VARIABLE_RILE_INDEX:
319+ return ReduceActions.I32;
320+ case INTEGER_RULE_INDEX:
321+ return ReduceActions.I34;
322+ case OPEN_AND_CLOSE_OF_ARRAY_RULE_INDEX:
323+ return ReduceActions.I29;
324+ case DOLLAR_SIGN_RULE_INDEX:
325+ // skip whitespace??
326 break;
327- case 14:
328- return 11;
329- case 15:
330+ case AMPERSAND_SIGN_RULE_INDEX:
331+ return ReduceActions.I11;
332+ case SINGLE_WHITESPACE_RULE_INDEX:
333 return ' ';
334- case 16:
335- return 33;
336- case 17:
337- return 27;
338- case 18:
339- return 30;
340- case 19:
341- return 31;
342- case 20:
343- return 20;
344- case 21:
345- return 21;
346- case 22:
347- return 19;
348- case 23:
349- return 13;
350- case 24:
351- return 22;
352- case 25:
353- return 14;
354- case 26:
355- return 15;
356- case 27:
357- return 17;
358- case 28:
359- return 16;
360- case 29:
361- return 18;
362- case 30:
363+ case PERIOD_RULE_INDEX:
364+ return ReduceActions.I33;
365+ case COLON_RULE_INDEX:
366+ return ReduceActions.I27;
367+ case SEMI_COLON_RULE_INDEX:
368+ return ReduceActions.I30;
369+ case COMMA_RULE_INDEX:
370+ return ReduceActions.I31;
371+ case ASTERISK_RULE_INDEX:
372+ return ReduceActions.I20;
373+ case FORWARD_SLASH_RULE_INDEX:
374+ return ReduceActions.I21;
375+ case MINUS_SIGN_RULE_INDEX:
376+ return ReduceActions.I19;
377+ case PLUS_SIGN_RULE_INDEX:
378+ return ReduceActions.I13;
379+ case CARET_SIGN_RULE_INDEX:
380+ return ReduceActions.I22;
381+ case OPEN_PAREN_RULE_INDEX:
382+ return ReduceActions.I14;
383+ case CLOSE_PAREN_RULE_INDEX:
384+ return ReduceActions.I15;
385+ case GREATER_THAN_SIGN_RULE_INDEX:
386+ return ReduceActions.I17;
387+ case LESS_THAN_SIGN_RULE_INDEX:
388+ return ReduceActions.I16;
389+ case NOT_RULE_INDEX:
390+ return ReduceActions.I18;
391+ case OPEN_DOUBLE_QUOTE_INDEX:
392 return '"';
393- case 31:
394+ case OPEN_SINGLE_QUITE_INDEX:
395 return "'";
396- case 32:
397+ case EXCLAMATION_POINT_RULE_INDEX:
398 return "!";
399- case 33:
400- return 12;
401- case 34:
402- return 35;
403- case 35:
404- return 36;
405- case 36:
406- return 5;
407+ case EQUALS_SIGN_RULE_INDEX:
408+ return ReduceActions.I12;
409+ case PERCENT_SIGN_RULE_INDEX:
410+ return ReduceActions.I35;
411+ case HASH_SIGN_RULE_INDEX:
412+ return ReduceActions.I36;
413+ case END_OF_STRING_RULE_INDEX:
414+ return ReduceActions.I5;
415 }
416 },
417 rules: RULES,