spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[Parser] naming 'productions' indicies with ReduceActions enums
author
Ben Vogt <[email protected]>
date
2017-08-20 17:30:39
stats
1 file(s) changed, 110 insertions(+), 55 deletions(-)
files
src/Parser/Parser.ts
  1diff --git a/src/Parser/Parser.ts b/src/Parser/Parser.ts
  2index 0e69afa..1be51c9 100644
  3--- a/src/Parser/Parser.ts
  4+++ b/src/Parser/Parser.ts
  5@@ -56,8 +56,9 @@ const enum LexActions {
  6 
  7 
  8 const enum ReduceActions {
  9-  I1 = 1,
 10-  I2,
 11+  NO_ACTION = 0,
 12+  RETURN_LAST,
 13+  CALL_VARIABLE,
 14   I3,
 15   I4,
 16   AS_NUMBER,
 17@@ -84,7 +85,7 @@ const enum ReduceActions {
 18   I26,
 19   I27,
 20   FIXED_CELL_VAL,
 21-  FIX_EDCELL_RANGE_VAL,
 22+  FIXED_CELL_RANGE_VAL,
 23   CELL_VALUE,
 24   CELL_RANGE_VALUE,
 25   ENSURE_IS_ARRAY,
 26@@ -95,11 +96,56 @@ const enum ReduceActions {
 27   ENSURE_LAST_TWO_IN_ARRAY_AND_PUSH,
 28   REFLEXIVE_REDUCE,
 29   REDUCE_FLOAT,
 30-  REUDCE_PREV_AS_PERCENT,
 31+  REDUCE_PREV_AS_PERCENT,
 32   REDUCE_LAST_THREE_A,
 33   REDUCE_LAST_THREE_B
 34 }
 35 
 36+let productions = [];
 37+productions[ReduceActions.NO_ACTION] = 0;
 38+productions[ReduceActions.RETURN_LAST] = [3, 2];
 39+productions[ReduceActions.CALL_VARIABLE] = [4, 1];
 40+productions[ReduceActions.I3] = [4, 1];
 41+productions[ReduceActions.I4] = [4, 1];
 42+productions[ReduceActions.AS_NUMBER] = [4, 1];
 43+productions[ReduceActions.AS_STRING] = [4, 1];
 44+productions[ReduceActions.AMPERSAND] = [4, 3];
 45+productions[ReduceActions.EQUALS] = [4, 3];
 46+productions[ReduceActions.PLUS] = [4, 3];
 47+productions[ReduceActions.LAST_NUMBER] = [4, 3];
 48+productions[ReduceActions.LTE] = [4, 4];
 49+productions[ReduceActions.GTE] = [4, 4];
 50+productions[ReduceActions.NOT_EQ] = [4, 4];
 51+productions[ReduceActions.NOT] = [4, 3];
 52+productions[ReduceActions.GT] = [4, 3];
 53+productions[ReduceActions.LT] = [4, 3];
 54+productions[ReduceActions.MINUS] = [4, 3];
 55+productions[ReduceActions.MULTIPLY] = [4, 3];
 56+productions[ReduceActions.DIVIDE] = [4, 3];
 57+productions[ReduceActions.TO_POWER] = [4, 3];
 58+productions[ReduceActions.INVERT_NUM] = [4, 2];
 59+productions[ReduceActions.TO_NUMBER_NAN_AS_ZERO] = [4, 2];
 60+productions[ReduceActions.CALL_FUNCTION_LAST_BLANK] = [4, 3];
 61+productions[ReduceActions.CALL_FUNCTION_LAST_TWO_IN_STACK] = [4, 4];
 62+productions[ReduceActions.I25] = [4, 1];
 63+productions[ReduceActions.I26] = [4, 1];
 64+productions[ReduceActions.I27] = [4, 2];
 65+productions[ReduceActions.FIXED_CELL_VAL] = [25, 1];
 66+productions[ReduceActions.FIXED_CELL_RANGE_VAL] = [25, 3];
 67+productions[ReduceActions.CELL_VALUE] = [25, 1];
 68+productions[ReduceActions.CELL_RANGE_VALUE] = [25, 3];
 69+productions[ReduceActions.ENSURE_IS_ARRAY] = [24, 1];
 70+productions[ReduceActions.ENSURE_YYTEXT_ARRAY] = [24, 1];
 71+productions[ReduceActions.REDUCE_INT] = [24, 3];
 72+productions[ReduceActions.REDUCE_PERCENT] = [24, 3];
 73+productions[ReduceActions.WRAP_CURRENT_INDEX_TOKEN_AS_ARRAY] = [6, 1];
 74+productions[ReduceActions.ENSURE_LAST_TWO_IN_ARRAY_AND_PUSH] = [6, 3];
 75+productions[ReduceActions.REFLEXIVE_REDUCE] = [9, 1];
 76+productions[ReduceActions.REDUCE_FLOAT] = [9, 3];
 77+productions[ReduceActions.REDUCE_PREV_AS_PERCENT] = [9, 2];
 78+productions[ReduceActions.REDUCE_LAST_THREE_A] = [2, 3];
 79+productions[ReduceActions.REDUCE_LAST_THREE_B] = [2, 4];
 80+const PRODUCTIONS = productions;
 81 
 82 /**
 83  * Parser initially generated by jison 0.4.15, but modified for readability and extensibility.
 84@@ -329,59 +375,25 @@ let Parser = (function () {
 85     /**
 86      * Maps a ProductionRule to the appropriate number of previous tokens to use in a reduction action.
 87      */
 88-    productions: [
 89-      0,
 90-      [3, 2],
 91-      [4, 1],
 92-      [4, 1],
 93-      [4, 1],
 94-      [4, 1],
 95-      [4, 1],
 96-      [4, 3],
 97-      [4, 3],
 98-      [4, 3],
 99-      [4, 3],
100-      [4, 4],
101-      [4, 4],
102-      [4, 4],
103-      [4, 3],
104-      [4, 3],
105-      [4, 3],
106-      [4, 3],
107-      [4, 3],
108-      [4, 3],
109-      [4, 3],
110-      [4, 2],
111-      [4, 2],
112-      [4, 3],
113-      [4, 4],
114-      [4, 1],
115-      [4, 1],
116-      [4, 2],
117-      [25, 1],
118-      [25, 3],
119-      [25, 1],
120-      [25, 3],
121-      [24, 1],
122-      [24, 1],
123-      [24, 3],
124-      [24, 3],
125-      [6, 1],
126-      [6, 3],
127-      [9, 1],
128-      [9, 3],
129-      [9, 2],
130-      [2, 3],
131-      [2, 4]
132-    ],
133-    performAction: function (yytext, yyleng, yylineno, yy, actionIndexToPerform /* action[1] */, virtualStack /* vstack */) {
134+    productions: PRODUCTIONS,
135+    /**
136+     * Perform a reduce action on the given virtual stack. Basically, fetching, deriving, or calculating a value.
137+     * @param yytext ???
138+     * @param yyleng ???
139+     * @param yylineno ???
140+     * @param yy ???
141+     * @param reduceActionToPerform - the ReduceAction to perform with the current virtual stack
142+     * @param virtualStack - Array of values to use in action.
143+     * @returns {number|boolean|string}
144+     */
145+    performAction: function (yytext, yyleng, yylineno, yy, reduceActionToPerform /* action[1] */, virtualStack : Array<any>) {
146       // For context, this function is only called with `call` or `apply`, so `this` is `yyval`.
147 
148       let $0 = virtualStack.length - 1;
149-      switch (actionIndexToPerform) {
150-        case ReduceActions.I1:
151+      switch (reduceActionToPerform) {
152+        case ReduceActions.RETURN_LAST:
153           return virtualStack[$0 - 1];
154-        case ReduceActions.I2:
155+        case ReduceActions.CALL_VARIABLE:
156           this.$ = yy.handler.helper.callVariable.call(this, virtualStack[$0]);
157           break;
158         case ReduceActions.I3:
159@@ -459,7 +471,7 @@ let Parser = (function () {
160         case ReduceActions.FIXED_CELL_VAL:
161           this.$ = yy.handler.helper.fixedCellValue.call(yy.obj, virtualStack[$0]);
162           break;
163-        case ReduceActions.FIX_EDCELL_RANGE_VAL:
164+        case ReduceActions.FIXED_CELL_RANGE_VAL:
165           this.$ = yy.handler.helper.fixedCellRangeValue.call(yy.obj, virtualStack[$0 - 2], virtualStack[$0]);
166           break;
167         case ReduceActions.CELL_VALUE:
168@@ -505,7 +517,7 @@ let Parser = (function () {
169         case ReduceActions.REDUCE_FLOAT:
170           this.$ = parseFloat(virtualStack[$0 - 2] + '.' + virtualStack[$0]);
171           break;
172-        case ReduceActions.REUDCE_PREV_AS_PERCENT:
173+        case ReduceActions.REDUCE_PREV_AS_PERCENT:
174           this.$ = virtualStack[$0 - 1] * 0.01;
175           break;
176         /**
177@@ -1748,7 +1760,7 @@ let Parser = (function () {
178           case INTEGER_RULE_INDEX:
179             return ReduceActions.REDUCE_INT;
180           case OPEN_AND_CLOSE_OF_ARRAY_RULE_INDEX:
181-            return ReduceActions.FIX_EDCELL_RANGE_VAL;
182+            return ReduceActions.FIXED_CELL_RANGE_VAL;
183           case DOLLAR_SIGN_RULE_INDEX:
184             // skip whitespace??
185             break;