commit
message
[Parser, CHOOSE] documenting parser, fixing tests for CHOOSE array issue
author
Ben Vogt <[email protected]>
date
2017-09-03 21:18:50
stats
11 file(s) changed,
1891 insertions(+),
84 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/Lookup.js
dist/Parser/Parser.js
dist/Sheet.js
dist/Utilities/ObjectFromPairs.js
dist/Utilities/TypeConverter.js
src/Formulas/Lookup.ts
src/Parser/Parser.ts
tests/Formulas/LookupTest.ts
tests/SheetFormulaTest.ts
1diff --git a/DOCS.md b/DOCS.md
2index 56aa751..af7be95 100644
3--- a/DOCS.md
4+++ b/DOCS.md
5@@ -820,7 +820,7 @@
6
7 ```
8 Returns an element from a list of choices based on index.
9-@param index - Which choice to return.
10+@param index - Which choice to return. Index starts at 1.
11 @param values - Array of potential value to return. Required. May be a reference to a cell or an individual value.
12 @constructor
13 ```
14diff --git a/TODO.md b/TODO.md
15index 705a965..3c0b6e0 100644
16--- a/TODO.md
17+++ b/TODO.md
18@@ -9,10 +9,6 @@ Instead of having non-primitives, (i.e. Date, DateTime, Time, Dollar), cells sho
19 When entering raw values into cells, if the value is a string, the Sheet should automatically attempt to convert to a number. For example, `= 10e2` should be be evaluated with a RegEx and converted to a number. See `Sheet.helper.number`.
20
21
22-### Parser should be able to detect arrays following numbers when passing in arguments.
23-For example the CHOOSE formula can't be parsed: `=CHOOSE(2, [1, 2, 3])`.
24-
25-
26 ### Cell.rawFormulaText does not get reset when updating a cell for the second time.
27
28
29diff --git a/dist/Formulas/Lookup.js b/dist/Formulas/Lookup.js
30index 50d095c..8d21a57 100644
31--- a/dist/Formulas/Lookup.js
32+++ b/dist/Formulas/Lookup.js
33@@ -6,7 +6,7 @@ var TypeConverter_1 = require("../Utilities/TypeConverter");
34 var Filter_1 = require("../Utilities/Filter");
35 /**
36 * Returns an element from a list of choices based on index.
37- * @param index - Which choice to return.
38+ * @param index - Which choice to return. Index starts at 1.
39 * @param values - Array of potential value to return. Required. May be a reference to a cell or an individual value.
40 * @constructor
41 */
42diff --git a/dist/Parser/Parser.js b/dist/Parser/Parser.js
43new file mode 100644
44index 0000000..35152ae
45--- /dev/null
46+++ b/dist/Parser/Parser.js
47@@ -0,0 +1,1773 @@
48+"use strict";
49+exports.__esModule = true;
50+var ObjectFromPairs_1 = require("../Utilities/ObjectFromPairs");
51+// Rules represent the Regular Expressions that will be used in sequence to match a given input to the Parser.
52+var WHITE_SPACE_RULE = /^(?:\s+)/; // rule 0
53+var DOUBLE_QUOTES_RULE = /^(?:"(\\["]|[^"])*")/; // rule 1
54+var SINGLE_QUOTES_RULE = /^(?:'(\\[']|[^'])*')/; // rule 2
55+var FORMULA_NAME_RULE = /^(?:[A-Za-z.]{1,}[A-Za-z_0-9]+(?=[(]))/; // Changed from /^(?:[A-Za-z]{1,}[A-Za-z_0-9]+(?=[(]))/ // rule 3
56+var DATE_RULE = /^(?:([0]?[1-9]|1[0-2])[:][0-5][0-9]([:][0-5][0-9])?[ ]?(AM|am|aM|Am|PM|pm|pM|Pm))/; // rule 4
57+var TIME_RULE = /^(?:([0]?[0-9]|1[0-9]|2[0-3])[:][0-5][0-9]([:][0-5][0-9])?)/; // rule 5
58+var $_A1_CELL_RULE = /^(?:\$[A-Za-z]+\$[0-9]+)/; // rule 6
59+var A1_CELL_RULE = /^(?:[A-Za-z]+[0-9]+)/; // rules 7
60+var FORMULA_NAME_SIMPLE_RULE = /^(?:[A-Za-z.]+(?=[(]))/; // rule 8
61+var VARIABLE_RULE = /^(?:[A-Za-z]{1,}[A-Za-z_0-9]+)/; // rule 9
62+var SIMPLE_VARIABLE_RILE = /^(?:[A-Za-z_]+)/; //rule 10
63+var INTEGER_RULE = /^(?:[0-9]+(?:(?:[eE])(?:[\+-])?[0-9]+)?)/; // Changed from /^(?:[0-9]+)/ // rule 11
64+var OPEN_AND_CLOSE_OF_ARRAY_RULE = /^(?:\[(.*)?\])/; // rule 12
65+var DOLLAR_SIGN_RULE = /^(?:\$)/; // rule 13
66+var AMPERSAND_SIGN_RULE = /^(?:&)/; //rule 14
67+var SINGLE_WHITESPACE_RULE = /^(?: )/; // rule 15
68+var PERIOD_RULE = /^(?:[.])/; // rule 16
69+var COLON_RULE = /^(?::)/; //rule 17
70+var SEMI_COLON_RULE = /^(?:;)/; // rule 18
71+var COMMA_RULE = /^(?:,)/; // rule 19
72+var ASTERISK_RULE = /^(?:\*)/; //rule 20
73+var FORWARD_SLASH_RULE = /^(?:\/)/; // rule 21
74+var MINUS_SIGN_RULE = /^(?:-)/; // rule 22
75+var PLUS_SIGN_RULE = /^(?:\+)/; // rule 23
76+var CARET_SIGN_RULE = /^(?:\^)/; //rule 24
77+var OPEN_PAREN_RULE = /^(?:\()/; // rule 25
78+var CLOSE_PAREN_RULE = /^(?:\))/; // rule 26
79+var GREATER_THAN_SIGN_RULE = /^(?:>)/; // rule 27
80+var LESS_THAN_SIGN_RULE = /^(?:<)/; // rule 28
81+var NOT_RULE = /^(?:NOT\b)/; // rule 29
82+var OPEN_DOUBLE_QUOTE = /^(?:")/; // rule 30
83+var OPEN_SINGLE_QUITE = /^(?:')/; // rule 31
84+var EXCLAMATION_POINT_RULE = /^(?:!)/; // rule 32
85+var EQUALS_SIGN_RULE = /^(?:=)/; // rule 33
86+var PERCENT_SIGN_RULE = /^(?:%)/; // rule 34
87+var HASH_SIGN_RULE = /^(?:[#])/; // rule 35
88+var END_OF_STRING_RULE = /^(?:$)/; // rule 36
89+// Sequential rules to use when parsing a given input.
90+var RULES = [
91+ WHITE_SPACE_RULE,
92+ DOUBLE_QUOTES_RULE,
93+ SINGLE_QUOTES_RULE,
94+ FORMULA_NAME_RULE,
95+ DATE_RULE,
96+ TIME_RULE,
97+ $_A1_CELL_RULE,
98+ A1_CELL_RULE,
99+ FORMULA_NAME_SIMPLE_RULE,
100+ VARIABLE_RULE,
101+ SIMPLE_VARIABLE_RILE,
102+ INTEGER_RULE,
103+ OPEN_AND_CLOSE_OF_ARRAY_RULE,
104+ DOLLAR_SIGN_RULE,
105+ AMPERSAND_SIGN_RULE,
106+ SINGLE_WHITESPACE_RULE,
107+ PERIOD_RULE,
108+ COLON_RULE,
109+ SEMI_COLON_RULE,
110+ COMMA_RULE,
111+ ASTERISK_RULE,
112+ FORWARD_SLASH_RULE,
113+ MINUS_SIGN_RULE,
114+ PLUS_SIGN_RULE,
115+ CARET_SIGN_RULE,
116+ OPEN_PAREN_RULE,
117+ CLOSE_PAREN_RULE,
118+ GREATER_THAN_SIGN_RULE,
119+ LESS_THAN_SIGN_RULE,
120+ NOT_RULE,
121+ OPEN_DOUBLE_QUOTE,
122+ OPEN_SINGLE_QUITE,
123+ EXCLAMATION_POINT_RULE,
124+ EQUALS_SIGN_RULE,
125+ PERCENT_SIGN_RULE,
126+ HASH_SIGN_RULE,
127+ END_OF_STRING_RULE
128+];
129+/**
130+ * Represents the length to reduce the stack by, and the token index value that will replace those tokens in the stack.
131+ */
132+var ReductionPair = (function () {
133+ function ReductionPair(replacementTokenIndex, length) {
134+ this.lengthToReduceStackBy = length;
135+ this.replacementTokenIndex = replacementTokenIndex;
136+ }
137+ /**
138+ * Get the number representing the length to reduce the stack by.
139+ * @returns {number}
140+ */
141+ ReductionPair.prototype.getLengthToReduceStackBy = function () {
142+ return this.lengthToReduceStackBy;
143+ };
144+ /**
145+ * Get the replacement token index.
146+ * @returns {number}
147+ */
148+ ReductionPair.prototype.getReplacementTokenIndex = function () {
149+ return this.replacementTokenIndex;
150+ };
151+ return ReductionPair;
152+}());
153+/**
154+ * Productions is used to look up both the number to use when reducing the stack (productions[x][1]) and the semantic
155+ * value that will replace the tokens in the stack (productions[x][0]).
156+ * @type {Array<ReductionPair>}
157+ */
158+var productions = [];
159+productions[0 /* NO_ACTION */] = null;
160+productions[1 /* RETURN_LAST */] = new ReductionPair(3, 2);
161+productions[2 /* CALL_VARIABLE */] = new ReductionPair(4, 1);
162+productions[3 /* TIME_CALL_TRUE */] = new ReductionPair(4, 1);
163+productions[4 /* TIME_CALL */] = new ReductionPair(4, 1);
164+productions[5 /* AS_NUMBER */] = new ReductionPair(4, 1);
165+productions[6 /* AS_STRING */] = new ReductionPair(4, 1);
166+productions[7 /* AMPERSAND */] = new ReductionPair(4, 3);
167+productions[8 /* EQUALS */] = new ReductionPair(4, 3);
168+productions[9 /* PLUS */] = new ReductionPair(4, 3);
169+productions[10 /* LAST_NUMBER */] = new ReductionPair(4, 3);
170+productions[11 /* LTE */] = new ReductionPair(4, 4);
171+productions[12 /* GTE */] = new ReductionPair(4, 4);
172+productions[13 /* NOT_EQ */] = new ReductionPair(4, 4);
173+productions[14 /* NOT */] = new ReductionPair(4, 3);
174+productions[15 /* GT */] = new ReductionPair(4, 3);
175+productions[16 /* LT */] = new ReductionPair(4, 3);
176+productions[17 /* MINUS */] = new ReductionPair(4, 3);
177+productions[18 /* MULTIPLY */] = new ReductionPair(4, 3);
178+productions[19 /* DIVIDE */] = new ReductionPair(4, 3);
179+productions[20 /* TO_POWER */] = new ReductionPair(4, 3);
180+productions[21 /* INVERT_NUM */] = new ReductionPair(4, 2);
181+productions[22 /* TO_NUMBER_NAN_AS_ZERO */] = new ReductionPair(4, 2);
182+productions[23 /* CALL_FUNCTION_LAST_BLANK */] = new ReductionPair(4, 3);
183+productions[24 /* CALL_FUNCTION_LAST_TWO_IN_STACK */] = new ReductionPair(4, 4);
184+productions[25 /* I25 */] = new ReductionPair(4, 1);
185+productions[26 /* I26 */] = new ReductionPair(4, 1);
186+productions[27 /* I27 */] = new ReductionPair(4, 2);
187+productions[28 /* FIXED_CELL_VAL */] = new ReductionPair(25, 1);
188+productions[29 /* FIXED_CELL_RANGE_VAL */] = new ReductionPair(25, 3);
189+productions[30 /* CELL_VALUE */] = new ReductionPair(25, 1);
190+productions[31 /* CELL_RANGE_VALUE */] = new ReductionPair(25, 3);
191+productions[32 /* ENSURE_IS_ARRAY */] = new ReductionPair(24, 1);
192+productions[33 /* ENSURE_YYTEXT_ARRAY */] = new ReductionPair(24, 1);
193+productions[34 /* REDUCE_INT */] = new ReductionPair(24, 3);
194+productions[35 /* REDUCE_PERCENT */] = new ReductionPair(24, 3);
195+productions[36 /* WRAP_CURRENT_INDEX_TOKEN_AS_ARRAY */] = new ReductionPair(6, 1);
196+productions[37 /* ENSURE_LAST_TWO_IN_ARRAY_AND_PUSH */] = new ReductionPair(6, 3);
197+productions[38 /* REFLEXIVE_REDUCE */] = new ReductionPair(9, 1);
198+productions[39 /* REDUCE_FLOAT */] = new ReductionPair(9, 3);
199+productions[40 /* REDUCE_PREV_AS_PERCENT */] = new ReductionPair(9, 2);
200+productions[41 /* REDUCE_LAST_THREE_A */] = new ReductionPair(2, 3);
201+productions[42 /* REDUCE_LAST_THREE_B */] = new ReductionPair(2, 4);
202+var PRODUCTIONS = productions;
203+/**
204+ * Parser initially generated by jison 0.4.15, but modified for readability and extensibility.
205+ */
206+var Parser = (function () {
207+ /**
208+ * Extend object obj by keys k, and values v for each k.
209+ * @param k - keys to extend object by.
210+ * @param v - value set for each key k.
211+ * @param obj - object to extend.
212+ * @param l
213+ * @returns {Object}
214+ */
215+ var extendRules = function (k, v, obj, l) {
216+ for (obj = obj || {}, l = k.length; l--; obj[k[l]] = v) { }
217+ return obj;
218+ };
219+ var $V0 = [1 /* SHIFT */, 4];
220+ var $V1 = [1 /* SHIFT */, 5];
221+ var $V2 = [1 /* SHIFT */, 7];
222+ var $V3 = [1 /* SHIFT */, 10];
223+ var $V4 = [1 /* SHIFT */, 8];
224+ var $V5 = [1 /* SHIFT */, 9];
225+ var $V6 = [1 /* SHIFT */, 11];
226+ var $V7 = [1 /* SHIFT */, 16];
227+ var $V8 = [1 /* SHIFT */, 17];
228+ var $V9 = [1 /* SHIFT */, 14];
229+ var $Va = [1 /* SHIFT */, 15];
230+ var $Vb = [1 /* SHIFT */, 18];
231+ var $Vc = [1 /* SHIFT */, 20];
232+ var $Vd = [1 /* SHIFT */, 21];
233+ var $Ve = [1 /* SHIFT */, 22];
234+ var $Vf = [1 /* SHIFT */, 23];
235+ var $Vg = [1 /* SHIFT */, 24];
236+ var $Vh = [1 /* SHIFT */, 25];
237+ var $Vi = [1 /* SHIFT */, 26];
238+ var $Vj = [1 /* SHIFT */, 27];
239+ var $Vk = [1 /* SHIFT */, 28];
240+ var $Vl = [1 /* SHIFT */, 29];
241+ var $Vm = [
242+ 5,
243+ 11,
244+ 12,
245+ 13,
246+ 15,
247+ 16,
248+ 17,
249+ 18,
250+ 19,
251+ 20,
252+ 21,
253+ 22,
254+ 30,
255+ 31
256+ ];
257+ var $Vn = [
258+ 5,
259+ 11,
260+ 12,
261+ 13,
262+ 15,
263+ 16,
264+ 17,
265+ 18,
266+ 19,
267+ 20,
268+ 21,
269+ 22,
270+ 30,
271+ 31,
272+ 33
273+ ];
274+ var $Vo = [1 /* SHIFT */, 38];
275+ var $Vp = [
276+ 5,
277+ 11,
278+ 12,
279+ 13,
280+ 15,
281+ 16,
282+ 17,
283+ 18,
284+ 19,
285+ 20,
286+ 21,
287+ 22,
288+ 30,
289+ 31,
290+ 35,
291+ 38
292+ ];
293+ var $Vq = [
294+ 5,
295+ 12,
296+ 13,
297+ 15,
298+ 16,
299+ 17,
300+ 18,
301+ 19,
302+ 30,
303+ 31
304+ ];
305+ var $Vr = [
306+ 5,
307+ 12,
308+ 15,
309+ 16,
310+ 17,
311+ 18,
312+ 30,
313+ 31
314+ ];
315+ var $Vs = [
316+ 5,
317+ 12,
318+ 13,
319+ 15,
320+ 16,
321+ 17,
322+ 18,
323+ 19,
324+ 20,
325+ 21,
326+ 30,
327+ 31
328+ ];
329+ var $Vt = [
330+ 15,
331+ 30,
332+ 31
333+ ];
334+ var $Vu = [
335+ 5,
336+ 11,
337+ 12,
338+ 13,
339+ 15,
340+ 16,
341+ 17,
342+ 18,
343+ 19,
344+ 20,
345+ 21,
346+ 22,
347+ 30,
348+ 31,
349+ 32,
350+ 36
351+ ];
352+ var parser = {
353+ lexer: undefined,
354+ Parser: undefined,
355+ trace: function trace() { },
356+ yy: {},
357+ symbols: {
358+ "error": 2,
359+ "expressions": 3,
360+ "expression": 4,
361+ "EOF": 5,
362+ "variableSequence": 6,
363+ "TIME_AMPM": 7,
364+ "TIME_24": 8,
365+ "number": 9,
366+ "STRING": 10,
367+ "&": 11,
368+ "=": 12,
369+ "+": 13,
370+ "(": 14,
371+ ")": 15,
372+ "<": 16,
373+ ">": 17,
374+ "NOT": 18,
375+ "-": 19,
376+ "*": 20,
377+ "/": 21,
378+ "^": 22,
379+ "FUNCTION": 23,
380+ "expseq": 24,
381+ "cell": 25,
382+ "FIXEDCELL": 26,
383+ ":": 27,
384+ "CELL": 28,
385+ "ARRAY": 29,
386+ ";": 30,
387+ ",": 31,
388+ "VARIABLE": 32,
389+ "DECIMAL": 33,
390+ "NUMBER": 34,
391+ "%": 35,
392+ "#": 36,
393+ "!": 37,
394+ "$accept": 0,
395+ "$end": 1
396+ },
397+ terminals: {
398+ 5: "EOF",
399+ 7: "TIME_AMPM",
400+ 8: "TIME_24",
401+ 10: "STRING",
402+ 11: "&",
403+ 12: "=",
404+ 13: "+",
405+ 14: "(",
406+ 15: ")",
407+ 16: "<",
408+ 17: ">",
409+ 18: "NOT",
410+ 19: "-",
411+ 20: "*",
412+ 21: "/",
413+ 22: "^",
414+ 23: "FUNCTION",
415+ 26: "FIXEDCELL",
416+ 27: ":",
417+ 28: "CELL",
418+ 29: "ARRAY",
419+ 30: ";",
420+ 31: ",",
421+ 32: "VARIABLE",
422+ 33: "DECIMAL",
423+ 34: "NUMBER",
424+ 35: "%",
425+ 36: "#",
426+ 37: "!"
427+ },
428+ /**
429+ * Maps a ProductionRule to the appropriate number of previous tokens to use in a reduction action.
430+ */
431+ productions: PRODUCTIONS,
432+ /**
433+ * Perform a reduce action on the given virtual stack. Basically, fetching, deriving, or calculating a value.
434+ * @param rawValueOfReduceOriginToken - Some actions require the origin token to perform a reduce action. For
435+ * example, when reducing the cell reference A1 to it's actual value this value would be "A1".
436+ * @param sharedStateYY - the shared state that has all helpers, and current working object.
437+ * @param reduceActionToPerform - the ReduceAction to perform with the current virtual stack. Since this function
438+ * is only called in one place, this should always be action[1] in that context.
439+ * @param virtualStack - Array of values to use in action.
440+ * @returns {number|boolean|string}
441+ */
442+ performAction: function (rawValueOfReduceOriginToken, sharedStateYY, reduceActionToPerform, virtualStack) {
443+ // For context, this function is only called with `apply`, so `this` is `yyval`.
444+ var vsl = virtualStack.length - 1;
445+ switch (reduceActionToPerform) {
446+ case 1 /* RETURN_LAST */:
447+ return virtualStack[vsl - 1];
448+ case 2 /* CALL_VARIABLE */:
449+ this.$ = sharedStateYY.handler.helper.callVariable.call(this, virtualStack[vsl]);
450+ break;
451+ case 3 /* TIME_CALL_TRUE */:
452+ this.$ = sharedStateYY.handler.time.call(sharedStateYY.obj, virtualStack[vsl], true);
453+ break;
454+ case 4 /* TIME_CALL */:
455+ this.$ = sharedStateYY.handler.time.call(sharedStateYY.obj, virtualStack[vsl]);
456+ break;
457+ case 5 /* AS_NUMBER */:
458+ this.$ = sharedStateYY.handler.helper.number(virtualStack[vsl]);
459+ break;
460+ case 6 /* AS_STRING */:
461+ this.$ = sharedStateYY.handler.helper.string(virtualStack[vsl]);
462+ break;
463+ case 7 /* AMPERSAND */:
464+ this.$ = sharedStateYY.handler.helper.specialMatch('&', virtualStack[vsl - 2], virtualStack[vsl]);
465+ break;
466+ case 8 /* EQUALS */:
467+ this.$ = sharedStateYY.handler.helper.logicMatch('=', virtualStack[vsl - 2], virtualStack[vsl]);
468+ break;
469+ case 9 /* PLUS */:
470+ this.$ = sharedStateYY.handler.helper.mathMatch('+', virtualStack[vsl - 2], virtualStack[vsl]);
471+ break;
472+ case 10 /* LAST_NUMBER */:
473+ this.$ = sharedStateYY.handler.helper.number(virtualStack[vsl - 1]);
474+ break;
475+ case 11 /* LTE */:
476+ this.$ = sharedStateYY.handler.helper.logicMatch('<=', virtualStack[vsl - 3], virtualStack[vsl]);
477+ break;
478+ case 12 /* GTE */:
479+ this.$ = sharedStateYY.handler.helper.logicMatch('>=', virtualStack[vsl - 3], virtualStack[vsl]);
480+ break;
481+ case 13 /* NOT_EQ */:
482+ this.$ = sharedStateYY.handler.helper.logicMatch('<>', virtualStack[vsl - 3], virtualStack[vsl]);
483+ break;
484+ case 14 /* NOT */:
485+ this.$ = sharedStateYY.handler.helper.logicMatch('NOT', virtualStack[vsl - 2], virtualStack[vsl]);
486+ break;
487+ case 15 /* GT */:
488+ this.$ = sharedStateYY.handler.helper.logicMatch('>', virtualStack[vsl - 2], virtualStack[vsl]);
489+ break;
490+ case 16 /* LT */:
491+ this.$ = sharedStateYY.handler.helper.logicMatch('<', virtualStack[vsl - 2], virtualStack[vsl]);
492+ break;
493+ case 17 /* MINUS */:
494+ this.$ = sharedStateYY.handler.helper.mathMatch('-', virtualStack[vsl - 2], virtualStack[vsl]);
495+ break;
496+ case 18 /* MULTIPLY */:
497+ this.$ = sharedStateYY.handler.helper.mathMatch('*', virtualStack[vsl - 2], virtualStack[vsl]);
498+ break;
499+ case 19 /* DIVIDE */:
500+ this.$ = sharedStateYY.handler.helper.mathMatch('/', virtualStack[vsl - 2], virtualStack[vsl]);
501+ break;
502+ case 20 /* TO_POWER */:
503+ this.$ = sharedStateYY.handler.helper.mathMatch('^', virtualStack[vsl - 2], virtualStack[vsl]);
504+ break;
505+ case 21 /* INVERT_NUM */:
506+ this.$ = sharedStateYY.handler.helper.numberInverted(virtualStack[vsl]);
507+ if (isNaN(this.$)) {
508+ this.$ = 0;
509+ }
510+ break;
511+ case 22 /* TO_NUMBER_NAN_AS_ZERO */:
512+ this.$ = sharedStateYY.handler.helper.number(virtualStack[vsl]);
513+ if (isNaN(this.$)) {
514+ this.$ = 0;
515+ }
516+ break;
517+ case 23 /* CALL_FUNCTION_LAST_BLANK */:
518+ this.$ = sharedStateYY.handler.helper.callFunction.call(this, virtualStack[vsl - 2], '');
519+ break;
520+ case 24 /* CALL_FUNCTION_LAST_TWO_IN_STACK */:
521+ this.$ = sharedStateYY.handler.helper.callFunction.call(this, virtualStack[vsl - 3], virtualStack[vsl - 1]);
522+ break;
523+ case 28 /* FIXED_CELL_VAL */:
524+ this.$ = sharedStateYY.handler.helper.fixedCellValue.call(sharedStateYY.obj, virtualStack[vsl]);
525+ break;
526+ case 29 /* FIXED_CELL_RANGE_VAL */:
527+ this.$ = sharedStateYY.handler.helper.fixedCellRangeValue.call(sharedStateYY.obj, virtualStack[vsl - 2], virtualStack[vsl]);
528+ break;
529+ case 30 /* CELL_VALUE */:
530+ this.$ = sharedStateYY.handler.helper.cellValue.call(sharedStateYY.obj, virtualStack[vsl]);
531+ break;
532+ case 31 /* CELL_RANGE_VALUE */:
533+ this.$ = sharedStateYY.handler.helper.cellRangeValue.call(sharedStateYY.obj, virtualStack[vsl - 2], virtualStack[vsl]);
534+ break;
535+ case 32 /* ENSURE_IS_ARRAY */:
536+ if (sharedStateYY.handler.utils.isArray(virtualStack[vsl])) {
537+ this.$ = virtualStack[vsl];
538+ }
539+ else {
540+ this.$ = [virtualStack[vsl]];
541+ }
542+ break;
543+ case 33 /* ENSURE_YYTEXT_ARRAY */:
544+ var result_1 = [], arr = eval("[" + rawValueOfReduceOriginToken + "]");
545+ arr.forEach(function (item) {
546+ result_1.push(item);
547+ });
548+ this.$ = result_1;
549+ break;
550+ case 34 /* REDUCE_INT */:
551+ case 35 /* REDUCE_PERCENT */:
552+ virtualStack[vsl - 2].push(virtualStack[vsl]);
553+ this.$ = virtualStack[vsl - 2];
554+ break;
555+ case 36 /* WRAP_CURRENT_INDEX_TOKEN_AS_ARRAY */:
556+ this.$ = [virtualStack[vsl]];
557+ break;
558+ case 37 /* ENSURE_LAST_TWO_IN_ARRAY_AND_PUSH */:
559+ this.$ = (sharedStateYY.handler.utils.isArray(virtualStack[vsl - 2]) ? virtualStack[vsl - 2] : [virtualStack[vsl - 2]]);
560+ this.$.push(virtualStack[vsl]);
561+ break;
562+ case 38 /* REFLEXIVE_REDUCE */:
563+ this.$ = virtualStack[vsl];
564+ break;
565+ case 39 /* REDUCE_FLOAT */:
566+ this.$ = parseFloat(virtualStack[vsl - 2] + '.' + virtualStack[vsl]);
567+ break;
568+ case 40 /* REDUCE_PREV_AS_PERCENT */:
569+ this.$ = virtualStack[vsl - 1] * 0.01;
570+ break;
571+ case 41 /* REDUCE_LAST_THREE_A */:
572+ case 42 /* REDUCE_LAST_THREE_B */:
573+ this.$ = virtualStack[vsl - 2] + virtualStack[vsl - 1] + virtualStack[vsl];
574+ break;
575+ }
576+ },
577+ /**
578+ * The `table` is an array of objects that map {@link RULES} to LexActions and tokens.
579+ */
580+ table: [
581+ ObjectFromPairs_1.ObjectFromPairs.of([
582+ 2, 13,
583+ 3, 1,
584+ 4, 2,
585+ 6, 3,
586+ 7, $V0,
587+ 8, $V1,
588+ 9, 6,
589+ 10, $V2,
590+ 13, $V3,
591+ 14, $V4,
592+ 19, $V5,
593+ 23, $V6,
594+ 25, 12,
595+ 26, $V7,
596+ 28, $V8,
597+ 32, $V9,
598+ 34, $Va,
599+ 36, $Vb
600+ ]),
601+ ObjectFromPairs_1.ObjectFromPairs.of([
602+ 1, [3]
603+ ]),
604+ ObjectFromPairs_1.ObjectFromPairs.of([
605+ 5, [1 /* SHIFT */, 19],
606+ 11, $Vc,
607+ 12, $Vd,
608+ 13, $Ve,
609+ 16, $Vf,
610+ 17, $Vg,
611+ 18, $Vh,
612+ 19, $Vi,
613+ 20, $Vj,
614+ 21, $Vk,
615+ 22, $Vl
616+ ]),
617+ extendRules($Vm, [2 /* REDUCE */, 2], ObjectFromPairs_1.ObjectFromPairs.of([33, [1 /* SHIFT */, 30]])),
618+ extendRules($Vm, [2 /* REDUCE */, 3]),
619+ extendRules($Vm, [2 /* REDUCE */, 4]),
620+ extendRules($Vm, [2 /* REDUCE */, 5], ObjectFromPairs_1.ObjectFromPairs.of([35, [1 /* SHIFT */, 31]])),
621+ extendRules($Vm, [2 /* REDUCE */, 6]),
622+ ObjectFromPairs_1.ObjectFromPairs.of([
623+ 2, 13,
624+ 4, 32,
625+ 6, 3,
626+ 7, $V0,
627+ 8, $V1,
628+ 9, 6,
629+ 10, $V2,
630+ 13, $V3,
631+ 14, $V4,
632+ 19, $V5,
633+ 23, $V6,
634+ 25, 12,
635+ 26, $V7,
636+ 28, $V8,
637+ 32, $V9,
638+ 34, $Va,
639+ 36, $Vb
640+ ]),
641+ ObjectFromPairs_1.ObjectFromPairs.of([
642+ 2, 13,
643+ 4, 33,
644+ 6, 3,
645+ 7, $V0,
646+ 8, $V1,
647+ 9, 6,
648+ 10, $V2,
649+ 13, $V3,
650+ 14, $V4,
651+ 19, $V5,
652+ 23, $V6,
653+ 25, 12,
654+ 26, $V7,
655+ 28, $V8,
656+ 32, $V9,
657+ 34, $Va,
658+ 36, $Vb
659+ ]),
660+ ObjectFromPairs_1.ObjectFromPairs.of([
661+ 2, 13,
662+ 4, 34,
663+ 6, 3,
664+ 7, $V0,
665+ 8, $V1,
666+ 9, 6,
667+ 10, $V2,
668+ 13, $V3,
669+ 14, $V4,
670+ 19, $V5,
671+ 23, $V6,
672+ 25, 12,
673+ 26, $V7,
674+ 28, $V8,
675+ 32, $V9,
676+ 34, $Va,
677+ 36, $Vb
678+ ]),
679+ ObjectFromPairs_1.ObjectFromPairs.of([
680+ 14, [1 /* SHIFT */, 35]
681+ ]),
682+ extendRules($Vm, [2 /* REDUCE */, 25]),
683+ extendRules($Vm, [2 /* REDUCE */, 26], ObjectFromPairs_1.ObjectFromPairs.of([2 /* REDUCE */, 36, 32, [1 /* SHIFT */, 37], 36, $Vb])),
684+ extendRules($Vn, [2 /* REDUCE */, 36], ObjectFromPairs_1.ObjectFromPairs.of([36, $Vo])),
685+ extendRules($Vp, [2 /* REDUCE */, 38], ObjectFromPairs_1.ObjectFromPairs.of([33, [1 /* SHIFT */, 39]])),
686+ extendRules($Vm, [2 /* REDUCE */, 28], ObjectFromPairs_1.ObjectFromPairs.of([27, [1 /* SHIFT */, 40]])),
687+ extendRules($Vm, [2 /* REDUCE */, 30], ObjectFromPairs_1.ObjectFromPairs.of([27, [1 /* SHIFT */, 41]])),
688+ ObjectFromPairs_1.ObjectFromPairs.of([32, [1 /* SHIFT */, 42]]),
689+ ObjectFromPairs_1.ObjectFromPairs.of([1, [3 /* ACCEPT */, 1]]),
690+ ObjectFromPairs_1.ObjectFromPairs.of([
691+ 2, 13,
692+ 4, 43,
693+ 6, 3,
694+ 7, $V0,
695+ 8, $V1,
696+ 9, 6,
697+ 10, $V2,
698+ 13, $V3,
699+ 14, $V4,
700+ 19, $V5,
701+ 23, $V6,
702+ 25, 12,
703+ 26, $V7,
704+ 28, $V8,
705+ 32, $V9,
706+ 34, $Va,
707+ 36, $Vb
708+ ]),
709+ ObjectFromPairs_1.ObjectFromPairs.of([
710+ 2, 13,
711+ 4, 44,
712+ 6, 3,
713+ 7, $V0,
714+ 8, $V1,
715+ 9, 6,
716+ 10, $V2,
717+ 13, $V3,
718+ 14, $V4,
719+ 19, $V5,
720+ 23, $V6,
721+ 25, 12,
722+ 26, $V7,
723+ 28, $V8,
724+ 32, $V9,
725+ 34, $Va,
726+ 36, $Vb
727+ ]),
728+ ObjectFromPairs_1.ObjectFromPairs.of([
729+ 2, 13,
730+ 4, 45,
731+ 6, 3,
732+ 7, $V0,
733+ 8, $V1,
734+ 9, 6,
735+ 10, $V2,
736+ 13, $V3,
737+ 14, $V4,
738+ 19, $V5,
739+ 23, $V6,
740+ 25, 12,
741+ 26, $V7,
742+ 28, $V8,
743+ 32, $V9,
744+ 34, $Va,
745+ 36, $Vb
746+ ]),
747+ ObjectFromPairs_1.ObjectFromPairs.of([
748+ 2, 13,
749+ 4, 48,
750+ 6, 3,
751+ 7, $V0,
752+ 8, $V1,
753+ 9, 6,
754+ 10, $V2,
755+ 12, [1, 46],
756+ 13, $V3,
757+ 14, $V4,
758+ 17, [1, 47],
759+ 19, $V5,
760+ 23, $V6,
761+ 25, 12,
762+ 26, $V7,
763+ 28, $V8,
764+ 32, $V9,
765+ 34, $Va,
766+ 36, $Vb
767+ ]),
768+ ObjectFromPairs_1.ObjectFromPairs.of([
769+ 2, 13,
770+ 4, 50,
771+ 6, 3,
772+ 7, $V0,
773+ 8, $V1,
774+ 9, 6,
775+ 10, $V2,
776+ 12, [1, 49],
777+ 13, $V3,
778+ 14, $V4,
779+ 19, $V5,
780+ 23, $V6,
781+ 25, 12,
782+ 26, $V7,
783+ 28, $V8,
784+ 32, $V9,
785+ 34, $Va,
786+ 36, $Vb
787+ ]),
788+ ObjectFromPairs_1.ObjectFromPairs.of([
789+ 2, 13,
790+ 4, 51,
791+ 6, 3,
792+ 7, $V0,
793+ 8, $V1,
794+ 9, 6,
795+ 10, $V2,
796+ 13, $V3,
797+ 14, $V4,
798+ 19, $V5,
799+ 23, $V6,
800+ 25, 12,
801+ 26, $V7,
802+ 28, $V8,
803+ 32, $V9,
804+ 34, $Va,
805+ 36, $Vb
806+ ]),
807+ ObjectFromPairs_1.ObjectFromPairs.of([
808+ 2, 13,
809+ 4, 52,
810+ 6, 3,
811+ 7, $V0,
812+ 8, $V1,
813+ 9, 6,
814+ 10, $V2,
815+ 13, $V3,
816+ 14, $V4,
817+ 19, $V5,
818+ 23, $V6,
819+ 25, 12,
820+ 26, $V7,
821+ 28, $V8,
822+ 32, $V9,
823+ 34, $Va,
824+ 36, $Vb
825+ ]),
826+ ObjectFromPairs_1.ObjectFromPairs.of([
827+ 2, 13,
828+ 4, 53,
829+ 6, 3,
830+ 7, $V0,
831+ 8, $V1,
832+ 9, 6,
833+ 10, $V2,
834+ 13, $V3,
835+ 14, $V4,
836+ 19, $V5,
837+ 23, $V6,
838+ 25, 12,
839+ 26, $V7,
840+ 28, $V8,
841+ 32, $V9,
842+ 34, $Va,
843+ 36, $Vb
844+ ]),
845+ ObjectFromPairs_1.ObjectFromPairs.of([
846+ 2, 13,
847+ 4, 54,
848+ 6, 3,
849+ 7, $V0,
850+ 8, $V1,
851+ 9, 6,
852+ 10, $V2,
853+ 13, $V3,
854+ 14, $V4,
855+ 19, $V5,
856+ 23, $V6,
857+ 25, 12,
858+ 26, $V7,
859+ 28, $V8,
860+ 32, $V9,
861+ 34, $Va,
862+ 36, $Vb
863+ ]),
864+ ObjectFromPairs_1.ObjectFromPairs.of([
865+ 2, 13,
866+ 4, 55,
867+ 6, 3,
868+ 7, $V0,
869+ 8, $V1,
870+ 9, 6,
871+ 10, $V2,
872+ 13, $V3,
873+ 14, $V4,
874+ 19, $V5,
875+ 23, $V6,
876+ 25, 12,
877+ 26, $V7,
878+ 28, $V8,
879+ 32, $V9,
880+ 34, $Va,
881+ 36, $Vb
882+ ]),
883+ ObjectFromPairs_1.ObjectFromPairs.of([[1 /* SHIFT */, 56]]),
884+ extendRules($Vp, [2 /* REDUCE */, 40]),
885+ ObjectFromPairs_1.ObjectFromPairs.of([
886+ 11, $Vc,
887+ 12, $Vd,
888+ 13, $Ve,
889+ 15, [1 /* SHIFT */, 57],
890+ 16, $Vf,
891+ 17, $Vg,
892+ 18, $Vh,
893+ 19, $Vi,
894+ 20, $Vj,
895+ 21, $Vk,
896+ 22, $Vl
897+ ]),
898+ extendRules($Vq, [2 /* REDUCE */, 21], ObjectFromPairs_1.ObjectFromPairs.of([
899+ 11, $Vc,
900+ 20, $Vj,
901+ 21, $Vk,
902+ 22, $Vl
903+ ])),
904+ extendRules($Vq, [2 /* REDUCE */, 22], ObjectFromPairs_1.ObjectFromPairs.of([
905+ 11, $Vc,
906+ 20, $Vj,
907+ 21, $Vk,
908+ 22, $Vl
909+ ])),
910+ ObjectFromPairs_1.ObjectFromPairs.of([
911+ 2, 13,
912+ 4, 60,
913+ 6, 3,
914+ 7, $V0,
915+ 8, $V1,
916+ 9, 6,
917+ 10, $V2,
918+ 13, $V3,
919+ 14, $V4,
920+ 15, [1 /* SHIFT */, 58],
921+ 19, $V5,
922+ 23, $V6,
923+ 24, 59,
924+ 25, 12,
925+ 26, $V7,
926+ 28, $V8,
927+ 29, [1 /* SHIFT */, 61],
928+ 32, $V9,
929+ 34, $Va,
930+ 36, $Vb
931+ ]),
932+ extendRules($Vm, [2 /* REDUCE */, 27]),
933+ ObjectFromPairs_1.ObjectFromPairs.of([36, $Vo]),
934+ ObjectFromPairs_1.ObjectFromPairs.of([32, [1 /* SHIFT */, 62]]),
935+ ObjectFromPairs_1.ObjectFromPairs.of([34, [1 /* SHIFT */, 63]]),
936+ ObjectFromPairs_1.ObjectFromPairs.of([26, [1 /* SHIFT */, 64]]),
937+ ObjectFromPairs_1.ObjectFromPairs.of([28, [1 /* SHIFT */, 65]]),
938+ ObjectFromPairs_1.ObjectFromPairs.of([37, [1 /* SHIFT */, 66]]),
939+ extendRules($Vm, [2 /* REDUCE */, 7]),
940+ extendRules([5, 12, 15, 30, 31], [2 /* REDUCE */, 8], ObjectFromPairs_1.ObjectFromPairs.of([
941+ 11, $Vc,
942+ 13, $Ve,
943+ 16, $Vf,
944+ 17, $Vg,
945+ 18, $Vh,
946+ 19, $Vi,
947+ 20, $Vj,
948+ 21, $Vk,
949+ 22, $Vl
950+ ])),
951+ extendRules($Vq, [2 /* REDUCE */, 9], ObjectFromPairs_1.ObjectFromPairs.of([
952+ 11, $Vc,
953+ 20, $Vj,
954+ 21, $Vk,
955+ 22, $Vl
956+ ])),
957+ ObjectFromPairs_1.ObjectFromPairs.of([
958+ 2, 13,
959+ 4, 67,
960+ 6, 3,
961+ 7, $V0,
962+ 8, $V1,
963+ 9, 6,
964+ 10, $V2,
965+ 13, $V3,
966+ 14, $V4,
967+ 19, $V5,
968+ 23, $V6,
969+ 25, 12,
970+ 26, $V7,
971+ 28, $V8,
972+ 32, $V9,
973+ 34, $Va,
974+ 36, $Vb
975+ ]),
976+ ObjectFromPairs_1.ObjectFromPairs.of([
977+ 2, 13,
978+ 4, 68,
979+ 6, 3,
980+ 7, $V0,
981+ 8, $V1,
982+ 9, 6,
983+ 10, $V2,
984+ 13, $V3,
985+ 14, $V4,
986+ 19, $V5,
987+ 23, $V6,
988+ 25, 12,
989+ 26, $V7,
990+ 28, $V8,
991+ 32, $V9,
992+ 34, $Va,
993+ 36, $Vb
994+ ]),
995+ extendRules($Vr, [2 /* REDUCE */, 16], ObjectFromPairs_1.ObjectFromPairs.of([
996+ 11, $Vc,
997+ 13, $Ve,
998+ 19, $Vi,
999+ 20, $Vj,
1000+ 21, $Vk,
1001+ 22, $Vl
1002+ ])),
1003+ ObjectFromPairs_1.ObjectFromPairs.of([
1004+ 2, 13,
1005+ 4, 69,
1006+ 6, 3,
1007+ 7, $V0,
1008+ 8, $V1,
1009+ 9, 6,
1010+ 10, $V2,
1011+ 13, $V3,
1012+ 14, $V4,
1013+ 19, $V5,
1014+ 23, $V6,
1015+ 25, 12,
1016+ 26, $V7,
1017+ 28, $V8,
1018+ 32, $V9,
1019+ 34, $Va,
1020+ 36, $Vb
1021+ ]),
1022+ extendRules($Vr, [2 /* REDUCE */, 15], ObjectFromPairs_1.ObjectFromPairs.of([
1023+ 11, $Vc,
1024+ 13, $Ve,
1025+ 19, $Vi,
1026+ 20, $Vj,
1027+ 21, $Vk,
1028+ 22, $Vl
1029+ ])),
1030+ extendRules([5, 12, 15, 18, 30, 31], [2 /* REDUCE */, 14], ObjectFromPairs_1.ObjectFromPairs.of([
1031+ 11, $Vc,
1032+ 13, $Ve,
1033+ 16, $Vf,
1034+ 17, $Vg,
1035+ 19, $Vi,
1036+ 20, $Vj,
1037+ 21, $Vk,
1038+ 22, $Vl
1039+ ])),
1040+ extendRules($Vq, [2 /* REDUCE */, 17], ObjectFromPairs_1.ObjectFromPairs.of([
1041+ 11, $Vc,
1042+ 20, $Vj,
1043+ 21, $Vk,
1044+ 22, $Vl
1045+ ])),
1046+ extendRules($Vs, [2 /* REDUCE */, 18], ObjectFromPairs_1.ObjectFromPairs.of([
1047+ 11, $Vc,
1048+ 22, $Vl
1049+ ])),
1050+ extendRules($Vs, [2 /* REDUCE */, 19], ObjectFromPairs_1.ObjectFromPairs.of([
1051+ 11, $Vc,
1052+ 22, $Vl
1053+ ])),
1054+ extendRules([5, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 30, 31], [2 /* REDUCE */, 20], ObjectFromPairs_1.ObjectFromPairs.of([11, $Vc])),
1055+ extendRules($Vn, [2 /* REDUCE */, 37]),
1056+ extendRules($Vm, [2 /* REDUCE */, 10]),
1057+ extendRules($Vm, [2 /* REDUCE */, 23]),
1058+ ObjectFromPairs_1.ObjectFromPairs.of([
1059+ 15, [1 /* SHIFT */, 70],
1060+ 30, [1 /* SHIFT */, 71],
1061+ 31, [1 /* SHIFT */, 72]
1062+ ]),
1063+ extendRules($Vt, [2 /* REDUCE */, 32], ObjectFromPairs_1.ObjectFromPairs.of([
1064+ 11, $Vc,
1065+ 12, $Vd,
1066+ 13, $Ve,
1067+ 16, $Vf,
1068+ 17, $Vg,
1069+ 18, $Vh,
1070+ 19, $Vi,
1071+ 20, $Vj,
1072+ 21, $Vk,
1073+ 22, $Vl
1074+ ])),
1075+ extendRules($Vt, [2 /* REDUCE */, 33]), ObjectFromPairs_1.ObjectFromPairs.of([
1076+ 37, [1 /* SHIFT */, 73]
1077+ ]),
1078+ extendRules($Vp, [2 /* REDUCE */, 39]),
1079+ extendRules($Vm, [2 /* REDUCE */, 29]),
1080+ extendRules($Vm, [2 /* REDUCE */, 31]),
1081+ extendRules($Vu, [2 /* REDUCE */, 41]),
1082+ extendRules($Vr, [2 /* REDUCE */, 11], ObjectFromPairs_1.ObjectFromPairs.of([
1083+ 11, $Vc,
1084+ 13, $Ve,
1085+ 19, $Vi,
1086+ 20, $Vj,
1087+ 21, $Vk,
1088+ 22, $Vl
1089+ ])),
1090+ extendRules($Vr, [2 /* REDUCE */, 13], ObjectFromPairs_1.ObjectFromPairs.of([
1091+ 11, $Vc,
1092+ 13, $Ve,
1093+ 19, $Vi,
1094+ 20, $Vj,
1095+ 21, $Vk,
1096+ 22, $Vl
1097+ ])),
1098+ extendRules($Vr, [2 /* REDUCE */, 12], ObjectFromPairs_1.ObjectFromPairs.of([
1099+ 11, $Vc,
1100+ 13, $Ve,
1101+ 19, $Vi,
1102+ 20, $Vj,
1103+ 21, $Vk,
1104+ 22, $Vl
1105+ ])),
1106+ extendRules($Vm, [2 /* REDUCE */, 24]),
1107+ ObjectFromPairs_1.ObjectFromPairs.of([
1108+ 2, 13,
1109+ 4, 74,
1110+ 6, 3,
1111+ 7, $V0,
1112+ 8, $V1,
1113+ 9, 6,
1114+ 10, $V2,
1115+ 13, $V3,
1116+ 14, $V4,
1117+ 19, $V5,
1118+ 23, $V6,
1119+ 25, 12,
1120+ 26, $V7,
1121+ 28, $V8,
1122+ 32, $V9,
1123+ 34, $Va,
1124+ 36, $Vb,
1125+ 12, $Vd,
1126+ ]),
1127+ ObjectFromPairs_1.ObjectFromPairs.of([
1128+ 2, 13,
1129+ 4, 75,
1130+ 6, 3,
1131+ 7, $V0,
1132+ 8, $V1,
1133+ 9, 6,
1134+ 10, $V2,
1135+ 13, $V3,
1136+ 14, $V4,
1137+ 19, $V5,
1138+ 23, $V6,
1139+ 25, 12,
1140+ 26, $V7,
1141+ 28, $V8,
1142+ 32, $V9,
1143+ 34, $Va,
1144+ 36, $Vb,
1145+ 12, $Vd,
1146+ ]),
1147+ extendRules($Vu, [2 /* REDUCE */, 42]),
1148+ extendRules($Vt, [2 /* REDUCE */, 34], ObjectFromPairs_1.ObjectFromPairs.of([
1149+ 11, $Vc,
1150+ 12, $Vd,
1151+ 13, $Ve,
1152+ 16, $Vf,
1153+ 17, $Vg,
1154+ 18, $Vh,
1155+ 19, $Vi,
1156+ 20, $Vj,
1157+ 21, $Vk,
1158+ 22, $Vl
1159+ ])),
1160+ extendRules($Vt, [2 /* REDUCE */, 35], ObjectFromPairs_1.ObjectFromPairs.of([
1161+ 11, $Vc,
1162+ 12, $Vd,
1163+ 13, $Ve,
1164+ 16, $Vf,
1165+ 17, $Vg,
1166+ 18, $Vh,
1167+ 19, $Vi,
1168+ 20, $Vj,
1169+ 21, $Vk,
1170+ 22, $Vl
1171+ ]))
1172+ ],
1173+ defaultActions: ObjectFromPairs_1.ObjectFromPairs.of([19, [2 /* REDUCE */, 1]]),
1174+ parseError: function parseError(str, hash) {
1175+ if (hash.recoverable) {
1176+ this.trace(str);
1177+ }
1178+ else {
1179+ throw new Error(str);
1180+ }
1181+ },
1182+ parse: function parse(input) {
1183+ var self = this, stack = [0], semanticValueStack = [null], locationStack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
1184+ var args = locationStack.slice.call(arguments, 1);
1185+ var lexer = Object.create(this.lexer);
1186+ var sharedState = {
1187+ yy: {
1188+ parseError: undefined,
1189+ lexer: {
1190+ parseError: undefined
1191+ },
1192+ parser: {
1193+ parseError: undefined
1194+ }
1195+ }
1196+ };
1197+ // copy state
1198+ for (var k in this.yy) {
1199+ if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
1200+ sharedState.yy[k] = this.yy[k];
1201+ }
1202+ }
1203+ lexer.setInput(input, sharedState.yy);
1204+ sharedState.yy.lexer = lexer;
1205+ sharedState.yy.parser = this;
1206+ if (typeof lexer.yylloc == 'undefined') {
1207+ lexer.yylloc = {};
1208+ }
1209+ var yyloc = lexer.yylloc;
1210+ locationStack.push(yyloc);
1211+ var ranges = lexer.options && lexer.options.ranges;
1212+ if (typeof sharedState.yy.parseError === 'function') {
1213+ this.parseError = sharedState.yy.parseError;
1214+ }
1215+ else {
1216+ this.parseError = Object.getPrototypeOf(this).parseError;
1217+ }
1218+ function popStack(n) {
1219+ stack.length = stack.length - 2 * n;
1220+ semanticValueStack.length = semanticValueStack.length - n;
1221+ locationStack.length = locationStack.length - n;
1222+ }
1223+ function lex() {
1224+ var token = lexer.lex() || EOF;
1225+ // if token isn't its numeric value, convert
1226+ if (typeof token !== 'number') {
1227+ token = self.symbols[token] || token;
1228+ }
1229+ return token;
1230+ }
1231+ var symbol, preErrorSymbol, state, action, result, yyval = {
1232+ $: undefined,
1233+ _$: undefined
1234+ }, p, newState, expected;
1235+ while (true) {
1236+ // retrieve state number from top of stack
1237+ state = stack[stack.length - 1];
1238+ // use default actions if available
1239+ if (this.defaultActions[state]) {
1240+ action = this.defaultActions[state];
1241+ }
1242+ else {
1243+ if (typeof symbol == 'undefined' || symbol === null) {
1244+ symbol = lex();
1245+ }
1246+ // read action for current state and first input
1247+ action = table[state] && table[state][symbol];
1248+ }
1249+ // handle parse error
1250+ if (typeof action === 'undefined' || !action.length || !action[0]) {
1251+ var error_rule_depth = void 0;
1252+ var errStr = '';
1253+ // Return the rule stack depth where the nearest error rule can be found.
1254+ // Return FALSE when no error recovery rule was found.
1255+ this.locateNearestErrorRecoveryRule = function (state) {
1256+ var stack_probe = stack.length - 1;
1257+ var depth = 0;
1258+ // try to recover from error
1259+ for (;;) {
1260+ // check for error recovery rule in this state
1261+ if ((TERROR.toString()) in table[state]) {
1262+ return depth;
1263+ }
1264+ if (state === 0 || stack_probe < 2) {
1265+ return false; // No suitable error recovery rule available.
1266+ }
1267+ stack_probe -= 2; // popStack(1): [symbol, action]
1268+ state = stack[stack_probe];
1269+ ++depth;
1270+ }
1271+ };
1272+ if (!recovering) {
1273+ // first see if there's any chance at hitting an error recovery rule:
1274+ error_rule_depth = this.locateNearestErrorRecoveryRule(state);
1275+ // Report error
1276+ expected = [];
1277+ var expectedIndexes = [];
1278+ var tableState = table[state];
1279+ for (p in table[state]) {
1280+ if (this.terminals[p] && p > TERROR) {
1281+ expected.push(this.terminals[p]);
1282+ expectedIndexes.push(p);
1283+ }
1284+ }
1285+ if (lexer.showPosition) {
1286+ errStr = 'Parse error on line ' + (yylineno + 1) + ":\n" + lexer.showPosition() + "\nExpecting " + expected.join(', ') + ", got '" + (this.terminals[symbol] || symbol) + "'";
1287+ }
1288+ else {
1289+ errStr = 'Parse error on line ' + (yylineno + 1) + ": Unexpected " +
1290+ (symbol == EOF ? "end of input" :
1291+ ("'" + (this.terminals[symbol] || symbol) + "'"));
1292+ }
1293+ this.parseError(errStr, {
1294+ text: lexer.match,
1295+ token: this.terminals[symbol] || symbol,
1296+ line: lexer.yylineno,
1297+ loc: yyloc,
1298+ expected: expected,
1299+ expectedIndexes: expectedIndexes,
1300+ state: state,
1301+ tableState: tableState,
1302+ recoverable: (error_rule_depth !== false)
1303+ });
1304+ }
1305+ else if (preErrorSymbol !== EOF) {
1306+ error_rule_depth = this.locateNearestErrorRecoveryRule(state);
1307+ }
1308+ // just recovered from another error
1309+ if (recovering == 3) {
1310+ if (symbol === EOF || preErrorSymbol === EOF) {
1311+ throw new Error(errStr || 'Parsing halted while starting to recover from another error.');
1312+ }
1313+ // discard current lookahead and grab another
1314+ yyleng = lexer.yyleng;
1315+ yytext = lexer.yytext;
1316+ yylineno = lexer.yylineno;
1317+ yyloc = lexer.yylloc;
1318+ symbol = lex();
1319+ }
1320+ // try to recover from error
1321+ if (error_rule_depth === false) {
1322+ throw new Error(errStr || 'Parsing halted. No suitable error recovery rule available.');
1323+ }
1324+ popStack(error_rule_depth);
1325+ preErrorSymbol = (symbol == TERROR ? null : symbol); // save the lookahead token
1326+ symbol = TERROR; // insert generic error symbol as new lookahead
1327+ state = stack[stack.length - 1];
1328+ action = table[state] && table[state][TERROR];
1329+ recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
1330+ }
1331+ // this shouldn't happen, unless resolve defaults are off
1332+ if (action[0] instanceof Array && action.length > 1) {
1333+ throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
1334+ }
1335+ // LexActions are always:
1336+ // Shift: continue to process tokens.
1337+ // Reduce: enough tokens have been gathered to reduce input through evaluation.
1338+ // Accept: return.
1339+ switch (action[0]) {
1340+ case 1 /* SHIFT */:
1341+ stack.push(symbol);
1342+ semanticValueStack.push(lexer.yytext);
1343+ locationStack.push(lexer.yylloc);
1344+ stack.push(action[1]); // push state
1345+ symbol = null;
1346+ if (!preErrorSymbol) {
1347+ yyleng = lexer.yyleng;
1348+ yytext = lexer.yytext;
1349+ yylineno = lexer.yylineno;
1350+ yyloc = lexer.yylloc;
1351+ if (recovering > 0) {
1352+ recovering--;
1353+ }
1354+ }
1355+ else {
1356+ // error just occurred, resume old lookahead f/ before error
1357+ symbol = preErrorSymbol;
1358+ preErrorSymbol = null;
1359+ }
1360+ break;
1361+ case 2 /* REDUCE */:
1362+ var currentProduction = this.productions[action[1]];
1363+ var lengthToReduceStackBy = currentProduction.getLengthToReduceStackBy();
1364+ // perform semantic action
1365+ yyval.$ = semanticValueStack[semanticValueStack.length - lengthToReduceStackBy]; // default to $$ = $1
1366+ // default location, uses first token for firsts, last for lasts
1367+ yyval._$ = {
1368+ first_line: locationStack[locationStack.length - (lengthToReduceStackBy || 1)].first_line,
1369+ last_line: locationStack[locationStack.length - 1].last_line,
1370+ first_column: locationStack[locationStack.length - (lengthToReduceStackBy || 1)].first_column,
1371+ last_column: locationStack[locationStack.length - 1].last_column
1372+ };
1373+ if (ranges) {
1374+ yyval._$.range = [locationStack[locationStack.length - (lengthToReduceStackBy || 1)].range[0], locationStack[locationStack.length - 1].range[1]];
1375+ }
1376+ result = this.performAction.apply(yyval, [yytext, sharedState.yy, action[1], semanticValueStack].concat(args));
1377+ if (typeof result !== 'undefined') {
1378+ return result;
1379+ }
1380+ // pop off stack
1381+ if (lengthToReduceStackBy) {
1382+ stack = stack.slice(0, -1 * lengthToReduceStackBy * 2);
1383+ semanticValueStack = semanticValueStack.slice(0, -1 * lengthToReduceStackBy);
1384+ locationStack = locationStack.slice(0, -1 * lengthToReduceStackBy);
1385+ }
1386+ // push non-terminal (reduce)
1387+ stack.push(currentProduction.getReplacementTokenIndex());
1388+ semanticValueStack.push(yyval.$);
1389+ locationStack.push(yyval._$);
1390+ newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
1391+ stack.push(newState);
1392+ break;
1393+ case 3 /* ACCEPT */:
1394+ // Accept
1395+ return true;
1396+ }
1397+ }
1398+ }
1399+ };
1400+ parser.lexer = (function () {
1401+ return ({
1402+ EOF: 1,
1403+ parseError: function parseError(str, hash) {
1404+ if (this.yy.parser) {
1405+ this.yy.parser.parseError(str, hash);
1406+ }
1407+ else {
1408+ throw new Error(str);
1409+ }
1410+ },
1411+ // resets the lexer, sets new input
1412+ setInput: function (input, yy) {
1413+ this.yy = yy || this.yy || {};
1414+ this._input = input;
1415+ this._more = this._backtrack = this.done = false;
1416+ this.yylineno = this.yyleng = 0;
1417+ this.yytext = this.matched = this.match = '';
1418+ this.conditionStack = ['INITIAL'];
1419+ this.yylloc = {
1420+ first_line: 1,
1421+ first_column: 0,
1422+ last_line: 1,
1423+ last_column: 0
1424+ };
1425+ if (this.options.ranges) {
1426+ this.yylloc.range = [0, 0];
1427+ }
1428+ this.offset = 0;
1429+ return this;
1430+ },
1431+ // consumes and returns one char from the input
1432+ input: function () {
1433+ var ch = this._input[0];
1434+ this.yytext += ch;
1435+ this.yyleng++;
1436+ this.offset++;
1437+ this.match += ch;
1438+ this.matched += ch;
1439+ var lines = ch.match(/(?:\r\n?|\n).*/g);
1440+ if (lines) {
1441+ this.yylineno++;
1442+ this.yylloc.last_line++;
1443+ }
1444+ else {
1445+ this.yylloc.last_column++;
1446+ }
1447+ if (this.options.ranges) {
1448+ this.yylloc.range[1]++;
1449+ }
1450+ this._input = this._input.slice(1);
1451+ return ch;
1452+ },
1453+ // unshifts one char (or a string) into the input
1454+ unput: function (ch) {
1455+ var len = ch.length;
1456+ var lines = ch.split(/(?:\r\n?|\n)/g);
1457+ this._input = ch + this._input;
1458+ this.yytext = this.yytext.substr(0, this.yytext.length - len);
1459+ //this.yyleng -= len;
1460+ this.offset -= len;
1461+ var oldLines = this.match.split(/(?:\r\n?|\n)/g);
1462+ this.match = this.match.substr(0, this.match.length - 1);
1463+ this.matched = this.matched.substr(0, this.matched.length - 1);
1464+ if (lines.length - 1) {
1465+ this.yylineno -= lines.length - 1;
1466+ }
1467+ var r = this.yylloc.range;
1468+ this.yylloc = {
1469+ first_line: this.yylloc.first_line,
1470+ last_line: this.yylineno + 1,
1471+ first_column: this.yylloc.first_column,
1472+ last_column: lines ?
1473+ (lines.length === oldLines.length ? this.yylloc.first_column : 0)
1474+ + oldLines[oldLines.length - lines.length].length - lines[0].length :
1475+ this.yylloc.first_column - len
1476+ };
1477+ if (this.options.ranges) {
1478+ this.yylloc.range = [r[0], r[0] + this.yyleng - len];
1479+ }
1480+ this.yyleng = this.yytext.length;
1481+ return this;
1482+ },
1483+ // When called from action, caches matched text and appends it on next action
1484+ more: function () {
1485+ this._more = true;
1486+ return this;
1487+ },
1488+ // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
1489+ reject: function () {
1490+ if (this.options.backtrack_lexer) {
1491+ this._backtrack = true;
1492+ }
1493+ else {
1494+ return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), {
1495+ text: "",
1496+ token: null,
1497+ line: this.yylineno
1498+ });
1499+ }
1500+ return this;
1501+ },
1502+ // retain first n characters of the match
1503+ less: function (n) {
1504+ this.unput(this.match.slice(n));
1505+ },
1506+ // displays already matched input, i.e. for error messages
1507+ pastInput: function () {
1508+ var past = this.matched.substr(0, this.matched.length - this.match.length);
1509+ return (past.length > 20 ? '...' : '') + past.substr(-20).replace(/\n/g, "");
1510+ },
1511+ // displays upcoming input, i.e. for error messages
1512+ upcomingInput: function () {
1513+ var next = this.match;
1514+ if (next.length < 20) {
1515+ next += this._input.substr(0, 20 - next.length);
1516+ }
1517+ return (next.substr(0, 20) + (next.length > 20 ? '...' : '')).replace(/\n/g, "");
1518+ },
1519+ // displays the character position where the lexing error occurred, i.e. for error messages
1520+ showPosition: function () {
1521+ var pre = this.pastInput();
1522+ var c = new Array(pre.length + 1).join("-");
1523+ return pre + this.upcomingInput() + "\n" + c + "^";
1524+ },
1525+ // test the lexed token: return FALSE when not a match, otherwise return token
1526+ test_match: function (match, indexed_rule) {
1527+ var token, lines, backup;
1528+ if (this.options.backtrack_lexer) {
1529+ // save context
1530+ backup = {
1531+ yylineno: this.yylineno,
1532+ yylloc: {
1533+ first_line: this.yylloc.first_line,
1534+ last_line: this.last_line,
1535+ first_column: this.yylloc.first_column,
1536+ last_column: this.yylloc.last_column
1537+ },
1538+ yytext: this.yytext,
1539+ match: this.match,
1540+ matches: this.matches,
1541+ matched: this.matched,
1542+ yyleng: this.yyleng,
1543+ offset: this.offset,
1544+ _more: this._more,
1545+ _input: this._input,
1546+ yy: this.yy,
1547+ conditionStack: this.conditionStack.slice(0),
1548+ done: this.done
1549+ };
1550+ if (this.options.ranges) {
1551+ backup.yylloc.range = this.yylloc.range.slice(0);
1552+ }
1553+ }
1554+ lines = match[0].match(/(?:\r\n?|\n).*/g);
1555+ if (lines) {
1556+ this.yylineno += lines.length;
1557+ }
1558+ this.yylloc = {
1559+ first_line: this.yylloc.last_line,
1560+ last_line: this.yylineno + 1,
1561+ first_column: this.yylloc.last_column,
1562+ last_column: lines ?
1563+ lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length :
1564+ this.yylloc.last_column + match[0].length
1565+ };
1566+ this.yytext += match[0];
1567+ this.match += match[0];
1568+ this.matches = match;
1569+ this.yyleng = this.yytext.length;
1570+ if (this.options.ranges) {
1571+ this.yylloc.range = [this.offset, this.offset += this.yyleng];
1572+ }
1573+ this._more = false;
1574+ this._backtrack = false;
1575+ this._input = this._input.slice(match[0].length);
1576+ this.matched += match[0];
1577+ token = this.mapActionToActionIndex(indexed_rule);
1578+ if (this.done && this._input) {
1579+ this.done = false;
1580+ }
1581+ if (token) {
1582+ return token;
1583+ }
1584+ else if (this._backtrack) {
1585+ // recover context
1586+ for (var k in backup) {
1587+ this[k] = backup[k];
1588+ }
1589+ return false; // rule action called reject() implying the next rule should be tested instead.
1590+ }
1591+ return false;
1592+ },
1593+ // return next match in input
1594+ next: function () {
1595+ if (this.done) {
1596+ return this.EOF;
1597+ }
1598+ if (!this._input) {
1599+ this.done = true;
1600+ }
1601+ var token, match, tempMatch, index;
1602+ if (!this._more) {
1603+ this.yytext = '';
1604+ this.match = '';
1605+ }
1606+ var rules = this._currentRules();
1607+ for (var i = 0; i < rules.length; i++) {
1608+ tempMatch = this._input.match(this.rules[rules[i]]);
1609+ if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
1610+ match = tempMatch;
1611+ index = i;
1612+ if (this.options.backtrack_lexer) {
1613+ token = this.test_match(tempMatch, rules[i]);
1614+ if (token !== false) {
1615+ return token;
1616+ }
1617+ else if (this._backtrack) {
1618+ match = false;
1619+ // rule action called reject() implying a rule mis-match.
1620+ // implied `continue`
1621+ }
1622+ else {
1623+ // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
1624+ return false;
1625+ }
1626+ }
1627+ else if (!this.options.flex) {
1628+ break;
1629+ }
1630+ }
1631+ }
1632+ if (match) {
1633+ token = this.test_match(match, rules[index]);
1634+ if (token !== false) {
1635+ return token;
1636+ }
1637+ // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace)
1638+ return false;
1639+ }
1640+ if (this._input === "") {
1641+ return this.EOF;
1642+ }
1643+ else {
1644+ return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), {
1645+ text: "",
1646+ token: null,
1647+ line: this.yylineno
1648+ });
1649+ }
1650+ },
1651+ // return next match that has a token
1652+ lex: function lex() {
1653+ var r = this.next();
1654+ if (r) {
1655+ return r;
1656+ }
1657+ else {
1658+ return this.lex();
1659+ }
1660+ },
1661+ // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
1662+ begin: function begin(condition) {
1663+ this.conditionStack.push(condition);
1664+ },
1665+ // pop the previously active lexer condition state off the condition stack
1666+ popState: function popState() {
1667+ var n = this.conditionStack.length - 1;
1668+ if (n > 0) {
1669+ return this.conditionStack.pop();
1670+ }
1671+ else {
1672+ return this.conditionStack[0];
1673+ }
1674+ },
1675+ // produce the lexer rule set which is active for the currently active lexer condition state
1676+ _currentRules: function _currentRules() {
1677+ if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
1678+ return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
1679+ }
1680+ else {
1681+ return this.conditions["INITIAL"].rules;
1682+ }
1683+ },
1684+ options: {},
1685+ mapActionToActionIndex: function (ruleIndex) {
1686+ switch (ruleIndex) {
1687+ case 0:
1688+ // skip whitespace
1689+ break;
1690+ case 1:
1691+ return 10 /* LAST_NUMBER */;
1692+ case 2:
1693+ return 10 /* LAST_NUMBER */;
1694+ case 3:
1695+ return 23 /* CALL_FUNCTION_LAST_BLANK */;
1696+ case 4:
1697+ return 7 /* AMPERSAND */;
1698+ case 5:
1699+ return 8 /* EQUALS */;
1700+ case 6:
1701+ return 26 /* I26 */;
1702+ case 7:
1703+ return 28 /* FIXED_CELL_VAL */;
1704+ case 8:
1705+ return 23 /* CALL_FUNCTION_LAST_BLANK */;
1706+ case 9:
1707+ return 32 /* ENSURE_IS_ARRAY */;
1708+ case 10:
1709+ return 32 /* ENSURE_IS_ARRAY */;
1710+ case 11:
1711+ return 34 /* REDUCE_INT */;
1712+ case 12:
1713+ return 29 /* FIXED_CELL_RANGE_VAL */;
1714+ case 13:
1715+ // skip whitespace??
1716+ break;
1717+ case 14:
1718+ return 11 /* LTE */;
1719+ case 15:
1720+ return ' ';
1721+ case 16:
1722+ return 33 /* ENSURE_YYTEXT_ARRAY */;
1723+ case 17:
1724+ return 27 /* I27 */;
1725+ case 18:
1726+ return 30 /* CELL_VALUE */;
1727+ case 19:
1728+ return 31 /* CELL_RANGE_VALUE */;
1729+ case 20:
1730+ return 20 /* TO_POWER */;
1731+ case 21:
1732+ return 21 /* INVERT_NUM */;
1733+ case 22:
1734+ return 19 /* DIVIDE */;
1735+ case 23:
1736+ return 13 /* NOT_EQ */;
1737+ case 24:
1738+ return 22 /* TO_NUMBER_NAN_AS_ZERO */;
1739+ case 25:
1740+ return 14 /* NOT */;
1741+ case 26:
1742+ return 15 /* GT */;
1743+ case 27:
1744+ return 17 /* MINUS */;
1745+ case 28:
1746+ return 16 /* LT */;
1747+ case 29:
1748+ return 18 /* MULTIPLY */;
1749+ case 30:
1750+ return '"';
1751+ case 31:
1752+ return "'";
1753+ case 32:
1754+ return "!";
1755+ case 33:
1756+ return 12 /* GTE */;
1757+ case 34:
1758+ return 35 /* REDUCE_PERCENT */;
1759+ case 35:
1760+ return 36 /* WRAP_CURRENT_INDEX_TOKEN_AS_ARRAY */;
1761+ case 36:
1762+ return 5 /* AS_NUMBER */;
1763+ }
1764+ },
1765+ rules: RULES,
1766+ conditions: {
1767+ "INITIAL": {
1768+ "rules": [
1769+ 0,
1770+ 1,
1771+ 2,
1772+ 3,
1773+ 4,
1774+ 5,
1775+ 6,
1776+ 7,
1777+ 8,
1778+ 9,
1779+ 10,
1780+ 11,
1781+ 12,
1782+ 13,
1783+ 14,
1784+ 15,
1785+ 16,
1786+ 17,
1787+ 18,
1788+ 19,
1789+ 20,
1790+ 21,
1791+ 22,
1792+ 23,
1793+ 24,
1794+ 25,
1795+ 26,
1796+ 27,
1797+ 28,
1798+ 29,
1799+ 30,
1800+ 31,
1801+ 32,
1802+ 33,
1803+ 34,
1804+ 35,
1805+ 36,
1806+ 37
1807+ ],
1808+ "inclusive": true
1809+ }
1810+ }
1811+ });
1812+ })();
1813+ function Parser() {
1814+ this.yy = {};
1815+ }
1816+ Parser.prototype = parser;
1817+ parser.Parser = Parser;
1818+ return new Parser;
1819+})();
1820+exports.Parser = Parser;
1821diff --git a/dist/Sheet.js b/dist/Sheet.js
1822index 3c27e22..d6e27e2 100644
1823--- a/dist/Sheet.js
1824+++ b/dist/Sheet.js
1825@@ -1,6 +1,6 @@
1826 "use strict";
1827 exports.__esModule = true;
1828-var Parser_1 = require("./Parser");
1829+var Parser_1 = require("./Parser/Parser");
1830 var Cell_1 = require("./Cell");
1831 var Errors_1 = require("./Errors");
1832 var Formulas_1 = require("./Formulas");
1833@@ -286,7 +286,9 @@ var Sheet = (function () {
1834 /**
1835 * Is the value a number or can the value be interpreted as a number
1836 */
1837- number: TypeConverter_1.TypeConverter.valueToNumber,
1838+ number: function (x) {
1839+ return TypeConverter_1.TypeConverter.valueToNumber(x);
1840+ },
1841 string: function (str) {
1842 return str.substring(1, str.length - 1);
1843 },
1844diff --git a/dist/Utilities/ObjectFromPairs.js b/dist/Utilities/ObjectFromPairs.js
1845new file mode 100644
1846index 0000000..757dd8c
1847--- /dev/null
1848+++ b/dist/Utilities/ObjectFromPairs.js
1849@@ -0,0 +1,40 @@
1850+"use strict";
1851+exports.__esModule = true;
1852+/**
1853+ * Static class for building objects using variables as keys. Mostly used in situations where we want to build objects
1854+ * with similar key structures inside of arrays.
1855+ * ```
1856+ * var m = "key";
1857+ * var n = "another"
1858+ * var x = [
1859+ * ObjectFromPairs.of([
1860+ * m, 1,
1861+ * n, 2
1862+ * ]);
1863+ * ]
1864+ * ```
1865+ * The example above would result in: `{"key": 1, "another": 2}`.
1866+ * NOTE: This code does not perform well, and should be used sparingly.
1867+ */
1868+var ObjectFromPairs = (function () {
1869+ function ObjectFromPairs() {
1870+ }
1871+ /**
1872+ * Creates an object from pairs.
1873+ * @param values - Even number of values, where odd-indexed values will be used as keys, and even-indexed values will
1874+ * be used as values in the object. If function is given odd number of values the last value will still be used as a
1875+ * key for which the value will be undefined. Use at your own risk.
1876+ * @returns {{}}
1877+ */
1878+ ObjectFromPairs.of = function (values) {
1879+ var o = {};
1880+ for (var i = 0; i < values.length - 1; i = i + 2) {
1881+ if (i % 2 === 0) {
1882+ o[values[i]] = values[i + 1];
1883+ }
1884+ }
1885+ return o;
1886+ };
1887+ return ObjectFromPairs;
1888+}());
1889+exports.ObjectFromPairs = ObjectFromPairs;
1890diff --git a/dist/Utilities/TypeConverter.js b/dist/Utilities/TypeConverter.js
1891index 4bad051..aaa86a1 100644
1892--- a/dist/Utilities/TypeConverter.js
1893+++ b/dist/Utilities/TypeConverter.js
1894@@ -124,7 +124,7 @@ function matchTimestampAndMutateMoment(timestampString, momentToMutate) {
1895 return momentToMutate;
1896 }
1897 /**
1898- * Static class of helpers used to convert various types to each other.
1899+ * Static class of helpers used to convert let ious types to each other.
1900 */
1901 var TypeConverter = (function () {
1902 function TypeConverter() {
1903@@ -335,7 +335,7 @@ var TypeConverter = (function () {
1904 };
1905 /**
1906 * Converts strings to numbers, returning undefined if string cannot be parsed to number. Examples: "100", "342424",
1907- * "10%", "33.213131", "41.1231", "10e1", "10E1", "10.44E1", "-$9.29", "+$9.29", "1,000.1", "2000,000,000".
1908+ * "10%", "33.213131", "41.1231", "10e+1", "10E-1", "10.44E1", "-$9.29", "+$9.29", "1,000.1", "2000,000,000".
1909 * For reference see: https://regex101.com/r/PwghnF/9/
1910 * @param value to parse.
1911 * @returns {number} or undefined
1912@@ -347,7 +347,8 @@ var TypeConverter = (function () {
1913 function isDefined(x) {
1914 return x !== undefined;
1915 }
1916- var NUMBER_REGEX = /^ *(\+|\-)? *(\$)? *(\+|\-)? *((\d+)?(,\d{3})?(,\d{3})?(,\d{3})?(,\d{3})?)? *(\.)? *(\d*)? *(e|E)? *(\d*)? *(%)? *$/;
1917+ // var NUMBER_REGEX = /^ *(\+|\-)? *(\$)? *(\+|\-)? *((\d+)?(,\d{3})?(,\d{3})?(,\d{3})?(,\d{3})?)? *(\.)? *(\d*)? *(e|E)? *(\d*)? *(%)? *$/;
1918+ var NUMBER_REGEX = /^ *(\+|\-)? *(\$)? *(\+|\-)? *((\d+)?(,\d{3})?(,\d{3})?(,\d{3})?(,\d{3})?)? *(\.)? *(\d*)? *(e|E)? *(\+|\-)? *(\d*)? *(%)? *$/;
1919 var matches = value.match(NUMBER_REGEX);
1920 if (matches !== null) {
1921 var firstSign = matches[1];
1922@@ -357,21 +358,22 @@ var TypeConverter = (function () {
1923 var decimalPoint = matches[10];
1924 var decimalNumber = matches[11];
1925 var sciNotation = matches[12];
1926- var sciNotationFactor = matches[13];
1927- var percentageSign = matches[14];
1928+ var sciNotationSign = matches[13];
1929+ var sciNotationFactor = matches[14];
1930+ var percentageSign = matches[15];
1931 // Number is not valid if it is a currency and in scientific notation.
1932 if (isDefined(currency) && isDefined(sciNotation)) {
1933- return undefined;
1934+ return;
1935 }
1936 // Number is not valid if there are two signs.
1937 if (isDefined(firstSign) && isDefined(secondSign)) {
1938- return undefined;
1939+ return;
1940 }
1941 // Number is not valid if we have 'sciNotation' but no 'sciNotationFactor'
1942 if (isDefined(sciNotation) && isUndefined(sciNotationFactor)) {
1943- return undefined;
1944+ return;
1945 }
1946- var activeSign;
1947+ var activeSign = void 0;
1948 if (isUndefined(firstSign) && isUndefined(secondSign)) {
1949 activeSign = "+";
1950 }
1951@@ -381,23 +383,22 @@ var TypeConverter = (function () {
1952 else {
1953 activeSign = secondSign;
1954 }
1955- var x;
1956+ var x = void 0;
1957 if (isDefined(wholeNumberWithCommas)) {
1958 if (isDefined(decimalNumber) && isDefined(decimalNumber)) {
1959- // console.log("parsing:", value, activeSign + wholeNumberWithCommas.split(",").join("") + decimalPoint + decimalNumber);
1960 x = parseFloat(activeSign + wholeNumberWithCommas.split(",").join("") + decimalPoint + decimalNumber);
1961 }
1962 else {
1963- // console.log("parsing:", value, activeSign + wholeNumberWithCommas.split(",").join(""))
1964 x = parseFloat(activeSign + wholeNumberWithCommas.split(",").join(""));
1965 }
1966 }
1967 else {
1968- // console.log("parsing:", value, activeSign + "0" + decimalPoint + decimalNumber);
1969 x = parseFloat(activeSign + "0" + decimalPoint + decimalNumber);
1970 }
1971 if (isDefined(sciNotation) && isDefined(sciNotationFactor)) {
1972- x = x * Math.pow(10, parseInt(sciNotationFactor));
1973+ sciNotationSign = isDefined(sciNotationSign) ? sciNotationSign : "+";
1974+ // x + "e" + "-" + "10"
1975+ x = parseFloat(x.toString() + sciNotation.toString() + "" + sciNotationSign.toString() + sciNotationFactor.toString());
1976 }
1977 if (!isUndefined(percentageSign)) {
1978 x = x * 0.01;
1979@@ -409,7 +410,7 @@ var TypeConverter = (function () {
1980 return TypeConverter.stringToDateNumber(value);
1981 }
1982 catch (_) {
1983- return undefined;
1984+ return;
1985 }
1986 }
1987 };
1988@@ -439,7 +440,7 @@ var TypeConverter = (function () {
1989 }
1990 var n = TypeConverter.stringToNumber(value);
1991 if (n === undefined) {
1992- throw new Errors_1.ValueError("Function ____ expects number values, but is text and cannot be coerced to a number.");
1993+ throw new Errors_1.ValueError("Function expects number values, but is text and cannot be coerced to a number.");
1994 }
1995 return n;
1996 }
1997diff --git a/src/Formulas/Lookup.ts b/src/Formulas/Lookup.ts
1998index bfda929..88cf7c4 100644
1999--- a/src/Formulas/Lookup.ts
2000+++ b/src/Formulas/Lookup.ts
2001@@ -14,14 +14,14 @@ import {
2002
2003 /**
2004 * Returns an element from a list of choices based on index.
2005- * @param index - Which choice to return.
2006+ * @param index - Which choice to return. Index starts at 1.
2007 * @param values - Array of potential value to return. Required. May be a reference to a cell or an individual value.
2008 * @constructor
2009 */
2010-var CHOOSE = function (index, ...values) {
2011+let CHOOSE = function (index, ...values) {
2012 ArgsChecker.checkAtLeastLength(arguments, 2, "CHOOSE");
2013- var i = Math.floor(TypeConverter.firstValueAsNumber(index));
2014- var data = Filter.flattenAndThrow(values);
2015+ let i = Math.floor(TypeConverter.firstValueAsNumber(index));
2016+ let data = Filter.flattenAndThrow(values);
2017 if (i < 1 || i > data.length) {
2018 throw new NumError("Function CHOOSE parameter 1 value is " + i + ". Valid values are between 1 and "
2019 + (data.length) + " inclusive.");
2020diff --git a/src/Parser/Parser.ts b/src/Parser/Parser.ts
2021index bccd719..03b3e29 100644
2022--- a/src/Parser/Parser.ts
2023+++ b/src/Parser/Parser.ts
2024@@ -2,7 +2,6 @@ import {
2025 ObjectFromPairs
2026 } from "../Utilities/ObjectFromPairs";
2027
2028-
2029 // Rules represent the Regular Expressions that will be used in sequence to match a given input to the Parser.
2030 const WHITE_SPACE_RULE = /^(?:\s+)/; // rule 0
2031 const DOUBLE_QUOTES_RULE = /^(?:"(\\["]|[^"])*")/; // rule 1
2032@@ -42,7 +41,6 @@ const PERCENT_SIGN_RULE = /^(?:%)/; // rule 34
2033 const HASH_SIGN_RULE = /^(?:[#])/; // rule 35
2034 const END_OF_STRING_RULE = /^(?:$)/; // rule 36
2035
2036-
2037 // Sequential rules to use when parsing a given input.
2038 const RULES = [
2039 WHITE_SPACE_RULE,
2040@@ -235,28 +233,28 @@ let Parser = (function () {
2041 for (obj = obj || {}, l = k.length; l--; obj[k[l]] = v) {}
2042 return obj;
2043 };
2044- const $V0 = [1, 4];
2045- const $V1 = [1, 5];
2046- const $V2 = [1, 7];
2047- const $V3 = [1, 10];
2048- const $V4 = [1, 8];
2049- const $V5 = [1, 9];
2050- const $V6 = [1, 11];
2051- const $V7 = [1, 16];
2052- const $V8 = [1, 17];
2053- const $V9 = [1, 14];
2054- const $Va = [1, 15];
2055- const $Vb = [1, 18];
2056- const $Vc = [1, 20];
2057- const $Vd = [1, 21];
2058- const $Ve = [1, 22];
2059- const $Vf = [1, 23];
2060- const $Vg = [1, 24];
2061- const $Vh = [1, 25];
2062- const $Vi = [1, 26];
2063- const $Vj = [1, 27];
2064- const $Vk = [1, 28];
2065- const $Vl = [1, 29];
2066+ const $V0 = [LexActions.SHIFT, 4];
2067+ const $V1 = [LexActions.SHIFT, 5];
2068+ const $V2 = [LexActions.SHIFT, 7];
2069+ const $V3 = [LexActions.SHIFT, 10];
2070+ const $V4 = [LexActions.SHIFT, 8];
2071+ const $V5 = [LexActions.SHIFT, 9];
2072+ const $V6 = [LexActions.SHIFT, 11];
2073+ const $V7 = [LexActions.SHIFT, 16];
2074+ const $V8 = [LexActions.SHIFT, 17];
2075+ const $V9 = [LexActions.SHIFT, 14];
2076+ const $Va = [LexActions.SHIFT, 15];
2077+ const $Vb = [LexActions.SHIFT, 18];
2078+ const $Vc = [LexActions.SHIFT, 20];
2079+ const $Vd = [LexActions.SHIFT, 21];
2080+ const $Ve = [LexActions.SHIFT, 22];
2081+ const $Vf = [LexActions.SHIFT, 23];
2082+ const $Vg = [LexActions.SHIFT, 24];
2083+ const $Vh = [LexActions.SHIFT, 25];
2084+ const $Vi = [LexActions.SHIFT, 26];
2085+ const $Vj = [LexActions.SHIFT, 27];
2086+ const $Vk = [LexActions.SHIFT, 28];
2087+ const $Vl = [LexActions.SHIFT, 29];
2088 const $Vm = [
2089 5,
2090 11,
2091@@ -290,7 +288,7 @@ let Parser = (function () {
2092 31,
2093 33
2094 ];
2095- const $Vo = [1, 38]; // index 38?
2096+ const $Vo = [LexActions.SHIFT, 38];
2097 const $Vp = [
2098 5,
2099 11,
2100@@ -307,7 +305,7 @@ let Parser = (function () {
2101 30,
2102 31,
2103 35,
2104- 38 // index 38?
2105+ 38
2106 ];
2107 const $Vq = [
2108 5,
2109@@ -373,7 +371,7 @@ let Parser = (function () {
2110 Parser: undefined,
2111 trace: function trace() {},
2112 yy: {},
2113- symbols_: {
2114+ symbols: {
2115 "error": 2,
2116 "expressions": 3,
2117 "expression": 4,
2118@@ -413,7 +411,7 @@ let Parser = (function () {
2119 "$accept": 0,
2120 "$end": 1
2121 },
2122- terminals_: {
2123+ terminals: {
2124 5: "EOF",
2125 7: "TIME_AMPM",
2126 8: "TIME_24",
2127@@ -575,10 +573,6 @@ let Parser = (function () {
2128 case ReduceActions.WRAP_CURRENT_INDEX_TOKEN_AS_ARRAY:
2129 this.$ = [virtualStack[vsl]];
2130 break;
2131- /**
2132- * As far as I can tell, we don't use this rule, but I'm hesitant to delete it until I understand why it was
2133- * initially written.
2134- */
2135 case ReduceActions.ENSURE_LAST_TWO_IN_ARRAY_AND_PUSH:
2136 this.$ = (sharedStateYY.handler.utils.isArray(virtualStack[vsl - 2]) ? virtualStack[vsl - 2] : [virtualStack[vsl - 2]]);
2137 this.$.push(virtualStack[vsl]);
2138@@ -592,9 +586,6 @@ let Parser = (function () {
2139 case ReduceActions.REDUCE_PREV_AS_PERCENT:
2140 this.$ = virtualStack[vsl - 1] * 0.01;
2141 break;
2142- /**
2143- * I don't understand where these come from as well, but I want to know the intent behind them.
2144- */
2145 case ReduceActions.REDUCE_LAST_THREE_A:
2146 case ReduceActions.REDUCE_LAST_THREE_B:
2147 this.$ = virtualStack[vsl - 2] + virtualStack[vsl - 1] + virtualStack[vsl];
2148@@ -944,14 +935,14 @@ let Parser = (function () {
2149 10, $V2,
2150 13, $V3,
2151 14, $V4,
2152- 15, [1, 58],
2153+ 15, [LexActions.SHIFT, 58],
2154 19, $V5,
2155 23, $V6,
2156 24, 59,
2157 25, 12,
2158 26, $V7,
2159 28, $V8,
2160- 29, [1, 61],
2161+ 29, [LexActions.SHIFT, 61],
2162 32, $V9,
2163 34, $Va,
2164 36, $Vb
2165@@ -1046,7 +1037,7 @@ let Parser = (function () {
2166 34, $Va,
2167 36, $Vb
2168 ]),
2169- extendRules($Vr, [LexActions.REDUCE, 15], ObjectFromPairs.of([ //51
2170+ extendRules($Vr, [LexActions.REDUCE, 15], ObjectFromPairs.of([
2171 11, $Vc,
2172 13, $Ve,
2173 19, $Vi,
2174@@ -1100,7 +1091,7 @@ let Parser = (function () {
2175 22, $Vl
2176 ])),
2177 extendRules($Vt, [LexActions.REDUCE, 33]), ObjectFromPairs.of([
2178- 37, [LexActions.SHIFT, 73] // index 37?
2179+ 37, [LexActions.SHIFT, 73]
2180 ]),
2181 extendRules($Vp, [LexActions.REDUCE, 39]),
2182 extendRules($Vm, [LexActions.REDUCE, 29]),
2183@@ -1131,10 +1122,8 @@ let Parser = (function () {
2184 22, $Vl
2185 ])),
2186 extendRules($Vm, [LexActions.REDUCE, 24]),
2187- ObjectFromPairs.of([
2188+ ObjectFromPairs.of([ // 70
2189 2, 13,
2190- // As far as I can tell, some of these higher values are lazy ways of indicating an out-of-bounds "production"
2191- // index, forcing a default to len=1 when reducing values.
2192 4, 74,
2193 6, 3,
2194 7, $V0,
2195@@ -1267,7 +1256,7 @@ let Parser = (function () {
2196 let token = lexer.lex() || EOF;
2197 // if token isn't its numeric value, convert
2198 if (typeof token !== 'number') {
2199- token = self.symbols_[token] || token;
2200+ token = self.symbols[token] || token;
2201 }
2202 return token;
2203 }
2204@@ -1331,25 +1320,30 @@ let Parser = (function () {
2205
2206 // Report error
2207 expected = [];
2208+ let expectedIndexes = [];
2209+ let tableState = table[state];
2210 for (p in table[state]) {
2211- if (this.terminals_[p] && p > TERROR) {
2212- expected.push(this.terminals_[p]);
2213+ if (this.terminals[p] && p > TERROR) {
2214+ expected.push(this.terminals[p]);
2215+ expectedIndexes.push(p);
2216 }
2217 }
2218 if (lexer.showPosition) {
2219- errStr = 'Parse error on line ' + (yylineno + 1) + ":\n" + lexer.showPosition() + "\nExpecting " + expected.join(', ') + ", got '" + (this.terminals_[symbol] || symbol) + "'";
2220+ errStr = 'Parse error on line ' + (yylineno + 1) + ":\n" + lexer.showPosition() + "\nExpecting " + expected.join(', ') + ", got '" + (this.terminals[symbol] || symbol) + "'";
2221 } else {
2222 errStr = 'Parse error on line ' + (yylineno + 1) + ": Unexpected " +
2223 (symbol == EOF ? "end of input" :
2224- ("'" + (this.terminals_[symbol] || symbol) + "'"));
2225+ ("'" + (this.terminals[symbol] || symbol) + "'"));
2226 }
2227 this.parseError(errStr, {
2228 text: lexer.match,
2229- token: this.terminals_[symbol] || symbol,
2230+ token: this.terminals[symbol] || symbol,
2231 line: lexer.yylineno,
2232 loc: yyloc,
2233 expected: expected,
2234+ expectedIndexes: expectedIndexes,
2235 state: state,
2236+ tableState: tableState,
2237 recoverable: (error_rule_depth !== false)
2238 });
2239 } else if (preErrorSymbol !== EOF) {
2240diff --git a/tests/Formulas/LookupTest.ts b/tests/Formulas/LookupTest.ts
2241index cd62bfb..d72cad6 100644
2242--- a/tests/Formulas/LookupTest.ts
2243+++ b/tests/Formulas/LookupTest.ts
2244@@ -10,8 +10,8 @@ import {
2245
2246
2247 test("CHOOSE", function(){
2248- assertEquals(CHOOSE.apply(this, [1, 1, 2, 3]), 1);
2249- assertEquals(CHOOSE.apply(this, [2, 1, 2, 3]), 2);
2250+ assertEquals(CHOOSE(1, 1, 2, 3), 1);
2251+ assertEquals(CHOOSE(2, 1, 2, 3), 2);
2252 catchAndAssertEquals(function() {
2253 CHOOSE.apply(this, []);
2254 }, ERRORS.NA_ERROR);
2255diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
2256index e1f497b..010ba10 100644
2257--- a/tests/SheetFormulaTest.ts
2258+++ b/tests/SheetFormulaTest.ts
2259@@ -164,7 +164,9 @@ test("Sheet CORREL", function(){
2260 });
2261
2262 test("Sheet CHOOSE", function(){
2263- assertFormulaEquals('=CHOOSE([2], [1, 2, 3])', 2);
2264+ assertFormulaEquals('=CHOOSE(3, 1, 2, 3)', 3);
2265+ assertFormulaEquals('=CHOOSE(2, 1, 2, 3)', 2);
2266+ assertFormulaEquals('=CHOOSE(1, 1, 2, 3)', 1);
2267 });
2268
2269 test("Sheet COS", function(){