spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[Parser] using Actions enum instead of 1,2,3 for action mapping
author
Ben Vogt <[email protected]>
date
2017-08-19 00:51:54
stats
1 file(s) changed, 109 insertions(+), 83 deletions(-)
files
src/Parser/Parser.ts
  1diff --git a/src/Parser/Parser.ts b/src/Parser/Parser.ts
  2index bee00c7..e6eb517 100644
  3--- a/src/Parser/Parser.ts
  4+++ b/src/Parser/Parser.ts
  5@@ -81,6 +81,12 @@ import {
  6 } from "../Utilities/ObjectFromPairs";
  7 
  8 
  9+const enum Actions {
 10+  SHIFT = 1,
 11+  REDUCE,
 12+  ACCEPT
 13+}
 14+
 15 /* parser generated by jison 0.4.15 */
 16 /*
 17  Returns a Parser object of the following structure:
 18@@ -477,7 +483,7 @@ let Parser = (function () {
 19         INDEX1, [3]
 20       ]),
 21       ObjectFromPairs.of([
 22-        TIME_RULE_INDEX, [1, 19],
 23+        TIME_RULE_INDEX, [Actions.SHIFT, 19],
 24         INTEGER_RULE_INDEX, $Vc,
 25         OPEN_AND_CLOSE_OF_ARRAY_RULE_INDEX, $Vd,
 26         DOLLAR_SIGN_RULE_INDEX, $Ve,
 27@@ -489,11 +495,11 @@ let Parser = (function () {
 28         FORWARD_SLASH_RULE_INDEX, $Vk,
 29         MINUS_SIGN_RULE_INDEX, $Vl
 30       ]),
 31-      extendRules($Vm, [2, 2], ObjectFromPairs.of([INDEX33, [1, 30]])),
 32-      extendRules($Vm, [2, 3]),
 33-      extendRules($Vm, [2, 4]),
 34-      extendRules($Vm, [2, 5], ObjectFromPairs.of([INDEX35, [1, 31]])),
 35-      extendRules($Vm, [2, 6]),
 36+      extendRules($Vm, [Actions.REDUCE, 2], ObjectFromPairs.of([INDEX33, [Actions.SHIFT, 30]])),
 37+      extendRules($Vm, [Actions.REDUCE, 3]),
 38+      extendRules($Vm, [Actions.REDUCE, 4]),
 39+      extendRules($Vm, [Actions.REDUCE, 5], ObjectFromPairs.of([INDEX35, [Actions.SHIFT, 31]])),
 40+      extendRules($Vm, [Actions.REDUCE, 6]),
 41       ObjectFromPairs.of([
 42         SINGLE_QUOTES_RULE_INDEX, 13,
 43         DATE_RULE_INDEX, 32,
 44@@ -552,16 +558,16 @@ let Parser = (function () {
 45         END_OF_STRING_RULE_INDEX, $Vb
 46       ]),
 47       ObjectFromPairs.of([
 48-        AMPERSAND_SIGN_RULE_INDEX, [1, 35]
 49+        AMPERSAND_SIGN_RULE_INDEX, [Actions.SHIFT, 35]
 50       ]),
 51-      extendRules($Vm, [2, 25]),
 52-      extendRules($Vm, [2, 26], ObjectFromPairs.of([2, 36, 32, [1, 37], 36, $Vb])),
 53-      extendRules($Vn, [2, 36], ObjectFromPairs.of([INDEX36, $Vo])),
 54-      extendRules($Vp, [2, 38], ObjectFromPairs.of([INDEX33, [1, 39]])),
 55-      extendRules($Vm, [2, 28], ObjectFromPairs.of([INDEX27, [1, 40]])),
 56-      extendRules($Vm, [2, 30], ObjectFromPairs.of([INDEX27, [1, 41]])),
 57-      ObjectFromPairs.of([INDEX32, [1, 42]]),
 58-      ObjectFromPairs.of([INDEX1, [2, 1]]),
 59+      extendRules($Vm, [Actions.REDUCE, 25]),
 60+      extendRules($Vm, [Actions.REDUCE, 26], ObjectFromPairs.of([Actions.REDUCE, 36, 32, [Actions.SHIFT, 37], 36, $Vb])),
 61+      extendRules($Vn, [Actions.REDUCE, 36], ObjectFromPairs.of([INDEX36, $Vo])),
 62+      extendRules($Vp, [Actions.REDUCE, 38], ObjectFromPairs.of([INDEX33, [Actions.SHIFT, 39]])),
 63+      extendRules($Vm, [Actions.REDUCE, 28], ObjectFromPairs.of([INDEX27, [Actions.SHIFT, 40]])),
 64+      extendRules($Vm, [Actions.REDUCE, 30], ObjectFromPairs.of([INDEX27, [Actions.SHIFT, 41]])),
 65+      ObjectFromPairs.of([INDEX32, [Actions.SHIFT, 42]]),
 66+      ObjectFromPairs.of([INDEX1, [Actions.ACCEPT, 1]]),
 67       ObjectFromPairs.of([
 68         SINGLE_QUOTES_RULE_INDEX, 13,
 69         DATE_RULE_INDEX, 43,
 70@@ -755,13 +761,13 @@ let Parser = (function () {
 71         PERCENT_SIGN_RULE_INDEX, $Va,
 72         END_OF_STRING_RULE_INDEX, $Vb
 73       ]),
 74-      ObjectFromPairs.of([ [1, 56]]),
 75-      extendRules($Vp, [2, 40]),
 76+      ObjectFromPairs.of([ [Actions.SHIFT, 56]]),
 77+      extendRules($Vp, [Actions.REDUCE, 40]),
 78       ObjectFromPairs.of([
 79         INTEGER_RULE_INDEX, $Vc,
 80         OPEN_AND_CLOSE_OF_ARRAY_RULE_INDEX, $Vd,
 81         DOLLAR_SIGN_RULE_INDEX, $Ve,
 82-        SINGLE_WHITESPACE_RULE_INDEX, [1, 57],
 83+        SINGLE_WHITESPACE_RULE_INDEX, [Actions.SHIFT, 57],
 84         PERIOD_RULE_INDEX, $Vf,
 85         COLON_RULE_INDEX, $Vg,
 86         SEMI_COLON_RULE_INDEX, $Vh,
 87@@ -770,13 +776,13 @@ let Parser = (function () {
 88         FORWARD_SLASH_RULE_INDEX, $Vk,
 89         MINUS_SIGN_RULE_INDEX, $Vl
 90       ]),
 91-      extendRules($Vq, [2, 21], ObjectFromPairs.of([
 92+      extendRules($Vq, [Actions.REDUCE, 21], ObjectFromPairs.of([
 93         INDEX11, $Vc,
 94         INDEX20, $Vj,
 95         INDEX21, $Vk,
 96         INDEX22, $Vl
 97       ])),
 98-      extendRules($Vq, [2, 22], ObjectFromPairs.of([
 99+      extendRules($Vq, [Actions.REDUCE, 22], ObjectFromPairs.of([
100         INDEX11, $Vc,
101         INDEX20, $Vj,
102         INDEX21, $Vk,
103@@ -804,15 +810,15 @@ let Parser = (function () {
104         PERCENT_SIGN_RULE_INDEX, $Va,
105         END_OF_STRING_RULE_INDEX, $Vb
106       ]),
107-      extendRules($Vm, [2, 27]),
108+      extendRules($Vm, [Actions.REDUCE, 27]),
109       ObjectFromPairs.of([INDEX36, $Vo]),
110-      ObjectFromPairs.of([INDEX32, [1, 62]]),
111-      ObjectFromPairs.of([INDEX34, [1, 63]]),
112-      ObjectFromPairs.of([INDEX26, [1, 64]]),
113-      ObjectFromPairs.of([INDEX28, [1, 65]]),
114-      ObjectFromPairs.of([37, [1, 66]]),
115-      extendRules($Vm, [2, 7]),
116-      extendRules([5, 12, 15, 30, 31], [2, 8], ObjectFromPairs.of([
117+      ObjectFromPairs.of([INDEX32, [Actions.SHIFT, 62]]),
118+      ObjectFromPairs.of([INDEX34, [Actions.SHIFT, 63]]),
119+      ObjectFromPairs.of([INDEX26, [Actions.SHIFT, 64]]),
120+      ObjectFromPairs.of([INDEX28, [Actions.SHIFT, 65]]),
121+      ObjectFromPairs.of([37, [Actions.SHIFT, 66]]),
122+      extendRules($Vm, [Actions.REDUCE, 7]),
123+      extendRules([5, 12, 15, 30, 31], [Actions.REDUCE, 8], ObjectFromPairs.of([
124         INTEGER_RULE_INDEX, $Vc,
125         DOLLAR_SIGN_RULE_INDEX, $Ve,
126         PERIOD_RULE_INDEX, $Vf,
127@@ -823,7 +829,7 @@ let Parser = (function () {
128         FORWARD_SLASH_RULE_INDEX, $Vk,
129         MINUS_SIGN_RULE_INDEX, $Vl
130       ])),
131-      extendRules($Vq, [2, 9], ObjectFromPairs.of([
132+      extendRules($Vq, [Actions.REDUCE, 9], ObjectFromPairs.of([
133         INDEX11, $Vc,
134         INDEX20, $Vj,
135         INDEX21, $Vk,
136@@ -867,7 +873,7 @@ let Parser = (function () {
137         PERCENT_SIGN_RULE_INDEX, $Va,
138         END_OF_STRING_RULE_INDEX, $Vb
139       ]),
140-      extendRules($Vr, [2, 16], ObjectFromPairs.of([
141+      extendRules($Vr, [Actions.REDUCE, 16], ObjectFromPairs.of([
142         INTEGER_RULE_INDEX, $Vc,
143         DOLLAR_SIGN_RULE_INDEX, $Ve,
144         COMMA_RULE_INDEX, $Vi,
145@@ -894,7 +900,7 @@ let Parser = (function () {
146         PERCENT_SIGN_RULE_INDEX, $Va,
147         END_OF_STRING_RULE_INDEX, $Vb
148       ]),
149-      extendRules($Vr, [2, 15], ObjectFromPairs.of([
150+      extendRules($Vr, [Actions.REDUCE, 15], ObjectFromPairs.of([
151         INTEGER_RULE_INDEX, $Vc,
152         DOLLAR_SIGN_RULE_INDEX, $Ve,
153         COMMA_RULE_INDEX, $Vi,
154@@ -902,7 +908,7 @@ let Parser = (function () {
155         FORWARD_SLASH_RULE_INDEX, $Vk,
156         MINUS_SIGN_RULE_INDEX, $Vl
157       ])),
158-      extendRules([5, 12, 15, 18, 30, 31], [2, 14], ObjectFromPairs.of([
159+      extendRules([5, 12, 15, 18, 30, 31], [Actions.REDUCE, 14], ObjectFromPairs.of([
160         INTEGER_RULE_INDEX, $Vc,
161         DOLLAR_SIGN_RULE_INDEX, $Ve,
162         PERIOD_RULE_INDEX, $Vf,
163@@ -912,30 +918,30 @@ let Parser = (function () {
164         FORWARD_SLASH_RULE_INDEX, $Vk,
165         MINUS_SIGN_RULE_INDEX, $Vl
166       ])),
167-      extendRules($Vq, [2, 17], ObjectFromPairs.of([
168+      extendRules($Vq, [Actions.REDUCE, 17], ObjectFromPairs.of([
169         INTEGER_RULE_INDEX, $Vc,
170         ASTERISK_RULE_INDEX, $Vj,
171         FORWARD_SLASH_RULE_INDEX, $Vk,
172         MINUS_SIGN_RULE_INDEX, $Vl
173       ])),
174-      extendRules($Vs, [2, 18], ObjectFromPairs.of([
175+      extendRules($Vs, [Actions.REDUCE, 18], ObjectFromPairs.of([
176         INTEGER_RULE_INDEX, $Vc,
177         MINUS_SIGN_RULE_INDEX, $Vl
178       ])),
179-      extendRules($Vs, [2, 19], ObjectFromPairs.of([
180+      extendRules($Vs, [Actions.REDUCE, 19], ObjectFromPairs.of([
181         INTEGER_RULE_INDEX, $Vc,
182         MINUS_SIGN_RULE_INDEX, $Vl
183       ])),
184-      extendRules([5, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 30, 31], [2, 20], ObjectFromPairs.of([INTEGER_RULE_INDEX, $Vc])),
185-      extendRules($Vn, [2, 37]),
186-      extendRules($Vm, [2, 10]),
187-      extendRules($Vm, [2, 23]),
188+      extendRules([5, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 30, 31], [Actions.REDUCE, 20], ObjectFromPairs.of([INTEGER_RULE_INDEX, $Vc])),
189+      extendRules($Vn, [Actions.REDUCE, 37]),
190+      extendRules($Vm, [Actions.REDUCE, 10]),
191+      extendRules($Vm, [Actions.REDUCE, 23]),
192       ObjectFromPairs.of([
193-        SINGLE_WHITESPACE_RULE_INDEX, [1, 70],
194-        OPEN_DOUBLE_QUOTE_INDEX, [1, 71],
195-        OPEN_SINGLE_QUITE_INDEX, [1, 72]
196+        SINGLE_WHITESPACE_RULE_INDEX, [Actions.SHIFT, 70],
197+        OPEN_DOUBLE_QUOTE_INDEX, [Actions.SHIFT, 71],
198+        OPEN_SINGLE_QUITE_INDEX, [Actions.SHIFT, 72]
199       ]),
200-      extendRules($Vt, [2, 32], ObjectFromPairs.of([
201+      extendRules($Vt, [Actions.REDUCE, 32], ObjectFromPairs.of([
202         INTEGER_RULE_INDEX, $Vc,
203         OPEN_AND_CLOSE_OF_ARRAY_RULE_INDEX, $Vd,
204         DOLLAR_SIGN_RULE_INDEX, $Ve,
205@@ -947,12 +953,12 @@ let Parser = (function () {
206         FORWARD_SLASH_RULE_INDEX, $Vk,
207         MINUS_SIGN_RULE_INDEX, $Vl
208       ])),
209-      extendRules($Vt, [2, 33]), ObjectFromPairs.of([37, [1, 73]]), // index 37?
210-      extendRules($Vp, [2, 39]),
211-      extendRules($Vm, [2, 29]),
212-      extendRules($Vm, [2, 31]),
213-      extendRules($Vu, [2, 41]),
214-      extendRules($Vr, [2, 11], ObjectFromPairs.of([
215+      extendRules($Vt, [Actions.REDUCE, 33]), ObjectFromPairs.of([37, [Actions.SHIFT, 73]]), // index 37?
216+      extendRules($Vp, [Actions.REDUCE, 39]),
217+      extendRules($Vm, [Actions.REDUCE, 29]),
218+      extendRules($Vm, [Actions.REDUCE, 31]),
219+      extendRules($Vu, [Actions.REDUCE, 41]),
220+      extendRules($Vr, [Actions.REDUCE, 11], ObjectFromPairs.of([
221         INTEGER_RULE_INDEX, $Vc,
222         DOLLAR_SIGN_RULE_INDEX, $Ve,
223         COMMA_RULE_INDEX, $Vi,
224@@ -960,7 +966,7 @@ let Parser = (function () {
225         FORWARD_SLASH_RULE_INDEX, $Vk,
226         MINUS_SIGN_RULE_INDEX, $Vl
227       ])),
228-      extendRules($Vr, [2, 13], ObjectFromPairs.of([
229+      extendRules($Vr, [Actions.REDUCE, 13], ObjectFromPairs.of([
230         11, $Vc,
231         13, $Ve,
232         19, $Vi,
233@@ -968,7 +974,7 @@ let Parser = (function () {
234         21, $Vk,
235         22, $Vl
236       ])),
237-      extendRules($Vr, [2, 12], ObjectFromPairs.of([
238+      extendRules($Vr, [Actions.REDUCE, 12], ObjectFromPairs.of([
239         INTEGER_RULE_INDEX, $Vc,
240         DOLLAR_SIGN_RULE_INDEX, $Ve,
241         COMMA_RULE_INDEX, $Vi,
242@@ -976,7 +982,7 @@ let Parser = (function () {
243         FORWARD_SLASH_RULE_INDEX, $Vk,
244         MINUS_SIGN_RULE_INDEX, $Vl
245       ])),
246-      extendRules($Vm, [2, 24]),
247+      extendRules($Vm, [Actions.REDUCE, 24]),
248       ObjectFromPairs.of([
249         SINGLE_QUOTES_RULE_INDEX, 13,
250         DATE_RULE_INDEX, 74,
251@@ -1015,8 +1021,8 @@ let Parser = (function () {
252         PERCENT_SIGN_RULE_INDEX, $Va,
253         END_OF_STRING_RULE_INDEX, $Vb
254       ]),
255-      extendRules($Vu, [2, 42]),
256-      extendRules($Vt, [2, 34], ObjectFromPairs.of([
257+      extendRules($Vu, [Actions.REDUCE, 42]),
258+      extendRules($Vt, [Actions.REDUCE, 34], ObjectFromPairs.of([
259         INTEGER_RULE_INDEX, $Vc,
260         OPEN_AND_CLOSE_OF_ARRAY_RULE_INDEX, $Vd,
261         DOLLAR_SIGN_RULE_INDEX, $Ve,
262@@ -1028,7 +1034,7 @@ let Parser = (function () {
263         FORWARD_SLASH_RULE_INDEX, $Vk,
264         MINUS_SIGN_RULE_INDEX, $Vl
265       ])),
266-      extendRules($Vt, [2, 35], ObjectFromPairs.of([
267+      extendRules($Vt, [Actions.REDUCE, 35], ObjectFromPairs.of([
268         INTEGER_RULE_INDEX, $Vc,
269         OPEN_AND_CLOSE_OF_ARRAY_RULE_INDEX, $Vd,
270         DOLLAR_SIGN_RULE_INDEX, $Ve,
271@@ -1041,7 +1047,7 @@ let Parser = (function () {
272         MINUS_SIGN_RULE_INDEX, $Vl
273       ]))
274     ],
275-    defaultActions: ObjectFromPairs.of([COMMA_RULE_INDEX, [2, 1]]),
276+    defaultActions: ObjectFromPairs.of([COMMA_RULE_INDEX, [Actions.REDUCE, 1]]),
277     parseError: function parseError(str, hash) {
278       if (hash.recoverable) {
279         this.trace(str);
280@@ -1050,9 +1056,8 @@ let Parser = (function () {
281       }
282     },
283     parse: function parse(input) {
284-      var self = this,
285+      let self = this,
286         stack = [0],
287-        tstack = [], // token stack
288         vstack = [null], // semantic value stack
289         lstack = [], // location stack
290         table = this.table,
291@@ -1063,14 +1068,24 @@ let Parser = (function () {
292         TERROR = 2,
293         EOF = 1;
294 
295-      var args = lstack.slice.call(arguments, 1);
296+      let args = lstack.slice.call(arguments, 1);
297 
298       //this.reductionCount = this.shiftCount = 0;
299 
300-      var lexer = Object.create(this.lexer);
301-      var sharedState = {yy: {parseError: undefined, lexer: {parseError: undefined}, parser: {parseError: undefined}}};
302+      let lexer = Object.create(this.lexer);
303+      let sharedState = {
304+        yy: {
305+          parseError: undefined,
306+          lexer: {
307+            parseError: undefined
308+          },
309+          parser: {
310+            parseError: undefined
311+          }
312+        }
313+      };
314       // copy state
315-      for (var k in this.yy) {
316+      for (let k in this.yy) {
317         if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
318           sharedState.yy[k] = this.yy[k];
319         }
320@@ -1082,10 +1097,10 @@ let Parser = (function () {
321       if (typeof lexer.yylloc == 'undefined') {
322         lexer.yylloc = {};
323       }
324-      var yyloc = lexer.yylloc;
325+      let yyloc = lexer.yylloc;
326       lstack.push(yyloc);
327 
328-      var ranges = lexer.options && lexer.options.ranges;
329+      let ranges = lexer.options && lexer.options.ranges;
330 
331       if (typeof sharedState.yy.parseError === 'function') {
332         this.parseError = sharedState.yy.parseError;
333@@ -1100,7 +1115,7 @@ let Parser = (function () {
334       }
335 
336       function lex() {
337-        var token;
338+        let token;
339         token = lexer.lex() || EOF;
340         // if token isn't its numeric value, convert
341         if (typeof token !== 'number') {
342@@ -1114,7 +1129,7 @@ let Parser = (function () {
343         _$: undefined
344       }, p, len, newState, expected;
345       while (true) {
346-        // retreive state number from top of stack
347+        // retrieve state number from top of stack
348         state = stack[stack.length - 1];
349 
350         // use default actions if available
351@@ -1128,6 +1143,7 @@ let Parser = (function () {
352           action = table[state] && table[state][symbol];
353         }
354 
355+        // console.log("symbol:", symbol, "action:", action);
356         // handle parse error
357         if (typeof action === 'undefined' || !action.length || !action[0]) {
358           let error_rule_depth;
359@@ -1216,8 +1232,12 @@ let Parser = (function () {
360           throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
361         }
362 
363+        // Actions are always:
364+        //   Shift: continue to process tokens.
365+        //   Reduce: enough tokens have been gathered for use to reduce input through evaluation.
366+        //   Accept: return.
367         switch (action[0]) {
368-          case 1: // shift
369+          case Actions.SHIFT: // Shift
370             //this.shiftCount++;
371 
372             stack.push(symbol);
373@@ -1240,8 +1260,8 @@ let Parser = (function () {
374             }
375             break;
376 
377-          case 2:
378-            // reduce
379+          case Actions.REDUCE:
380+            // Reduce
381             //this.reductionCount++;
382 
383             len = this.productions_[action[1]][1];
384@@ -1279,8 +1299,8 @@ let Parser = (function () {
385             stack.push(newState);
386             break;
387 
388-          case 3:
389-            // accept
390+          case Actions.ACCEPT:
391+            // Accept
392             return true;
393         }
394