commit
message
[Parser, ParserConstants] work-in-progress on letting arrays passed in to formulas without errors
author
Ben Vogt <[email protected]>
date
2017-12-02 02:34:47
stats
6 file(s) changed,
38 insertions(+),
54 deletions(-)
files
TODO.md
src/Parser/Parser.ts
src/Parser/ParserConstants.ts
tests.sh
tests/SheetFormulaTest.ts
tests/SheetParsingTest.ts
1diff --git a/TODO.md b/TODO.md
2index 00fc034..a947b8f 100644
3--- a/TODO.md
4+++ b/TODO.md
5@@ -55,8 +55,6 @@ Many of these formulas can be written by allowing the Sheet and Parser to return
6 * T.INV.2T
7 * TINV
8 * TTEST
9-* FINDB
10-* SEARCHB
11 * LOGEST
12 * MDETERM
13 * MINVERSE
14diff --git a/src/Parser/Parser.ts b/src/Parser/Parser.ts
15index 2bebfb9..c621ceb 100644
16--- a/src/Parser/Parser.ts
17+++ b/src/Parser/Parser.ts
18@@ -17,6 +17,7 @@ import {
19 SYMBOL_NAME_TO_INDEX,
20 PRODUCTIONS
21 } from "./ParserConstants"
22+import {isUndefined} from "../Utilities/MoreUtils";
23
24 let Parser = (function () {
25 let parser = {
26@@ -378,6 +379,9 @@ let Parser = (function () {
27
28 // try to recover from error
29 for (; ;) {
30+ if (isUndefined(state)) {
31+ return false;
32+ }
33 // check for error recovery rule in this state
34 if ((TERROR.toString()) in ACTION_TABLE[state]) {
35 return depth;
36diff --git a/src/Parser/ParserConstants.ts b/src/Parser/ParserConstants.ts
37index 7ca040d..07a908e 100644
38--- a/src/Parser/ParserConstants.ts
39+++ b/src/Parser/ParserConstants.ts
40@@ -12,7 +12,7 @@ const FORMULA_NAME_SIMPLE_RULE = /^(?:[A-Za-z.]+(?=[(]))/; // rule 8
41 const VARIABLE_RULE = /^(?:[A-Za-z]{1,}[A-Za-z_0-9]+)/; // rule 9
42 const SIMPLE_VARIABLE_RILE = /^(?:[A-Za-z_]+)/; //rule 10
43 const INTEGER_RULE = /^(?:[0-9]+(?:(?:[eE])(?:[\+-])?[0-9]+)?)/; // Changed from /^(?:[0-9]+)/ // rule 11
44-const OPEN_AND_CLOSE_OF_ARRAY_RULE = /^(?:\[(.*)?\])/; // rule 12
45+const OPEN_AND_CLOSE_OF_ARRAY_RULE = /^(?:\[([^\]]*)?\])/; // rule 12 // Changed from /^(?:\[(.*)?\])/
46 const DOLLAR_SIGN_RULE = /^(?:\$)/; // rule 13
47 const AMPERSAND_SIGN_RULE = /^(?:&)/; //rule 14
48 const SINGLE_WHITESPACE_RULE = /^(?: )/; // rule 15
49@@ -326,6 +326,7 @@ symbolIndexToName[Symbol.DECIMAL] = "DECIMAL";
50 symbolIndexToName[Symbol.NUMBER_UPPER] = "NUMBER";
51 symbolIndexToName[Symbol.PERCENT] = "%";
52 symbolIndexToName[Symbol.POUND] = "#";
53+symbolIndexToName[Symbol.ARRAY] = "ARRAY";
54 symbolIndexToName[Symbol.EXCLAMATION_POINT] = "!";
55 const SYMBOL_INDEX_TO_NAME = symbolIndexToName;
56
57@@ -1435,6 +1436,7 @@ table[72] = ObjectBuilder
58 .add(Symbol.CELL_UPPER, [SHIFT, ReduceActions.MINUS])
59 .add(Symbol.VARIABLE, [SHIFT, ReduceActions.NOT])
60 .add(Symbol.NUMBER_UPPER, [SHIFT, ReduceActions.GT])
61+ .add(Symbol.ARRAY, [SHIFT, 61])
62 .add(Symbol.POUND, [SHIFT, ReduceActions.MULTIPLY]).build();
63 table[73] = ObjectBuilder
64 .add(Symbol.EOF, [REDUCE, ReduceActions.REDUCE_LAST_THREE_B])
65diff --git a/tests.sh b/tests.sh
66index bb2b4fc..b0017f7 100755
67--- a/tests.sh
68+++ b/tests.sh
69@@ -10,4 +10,5 @@ do
70 echo "$(date) Running ${test_file}"
71 node ${test_file}
72 done
73+node test_output/tests/SheetParsingTest.js
74 echo "$(date) Tests Done"
75\ No newline at end of file
76diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
77index bcaa3ef..61ff6e3 100644
78--- a/tests/SheetFormulaTest.ts
79+++ b/tests/SheetFormulaTest.ts
80@@ -1101,54 +1101,3 @@ test("Sheet parsing error", function(){
81 assertFormulaEqualsError('= 10e', PARSE_ERROR);
82 assertFormulaEqualsError('= SUM(', PARSE_ERROR);
83 });
84-
85-test("Sheet *", function(){
86- assertFormulaEquals('= 10 * 10', 100);
87- assertFormulaEquals('= 10 * 0', 0);
88- assertFormulaEquals('= 1 * 1', 1);
89-});
90-
91-test("Sheet &", function(){
92- assertFormulaEquals('="hey"&" "&"there"', "hey there");
93- assertFormulaEquals('=TEXT(12.3, "###.##")&"mm"', "12.3mm");
94-});
95-
96-test("Sheet /", function(){
97- assertFormulaEquals('= 10 / 2', 5);
98- assertFormulaEquals('= 10 / 1', 10);
99- assertFormulaEquals('= 1 / 1', 1);
100- assertFormulaEquals('= 0 / 1', 0);
101- assertFormulaEquals('="1" / 1', 1);
102- assertFormulaEquals('="500" / 1', 500);
103- assertFormulaEqualsError('= 10 / 0', DIV_ZERO_ERROR);
104- assertFormulaEqualsError('= 0 / 0', DIV_ZERO_ERROR);
105- assertFormulaEquals('= P9 / 1', 0);
106-});
107-
108-test("Sheet ^", function(){
109- assertFormulaEquals('= 10 ^ 10', 10000000000);
110- assertFormulaEquals('= 10 ^ 0', 1);
111- assertFormulaEquals('= 1 ^ 1', 1);
112- assertFormulaEquals('= 2 ^ 10', 1024);
113-});
114-
115-test("Sheet numbers/math", function(){
116- assertFormulaEquals('= "10" + 10', 20);
117- assertFormulaEquals('= "10.111111" + 0', 10.111111);
118- assertFormulaEquals('= 10%', 0.1);
119- assertFormulaEquals('= 10% + 1', 1.1);
120- assertFormulaEquals('= "10e1" + 0', 100);
121- assertFormulaEquals('= 10e1', 100);
122- assertFormulaEquals('= 10e-1', 1);
123- assertFormulaEquals('= 10e+1', 100);
124- assertFormulaEquals('= 10E1', 100);
125- assertFormulaEquals('= 10E-1', 1);
126- assertFormulaEquals('= 10E+1', 100);
127- assertFormulaEquals('= "1,000,000" + 0', 1000000);
128- assertFormulaEqualsError('= "10e" + 10', VALUE_ERROR);
129- assertFormulaEquals('= "+$10.00" + 0', 10);
130- assertFormulaEquals('= "-$10.00" + 0', -10);
131- assertFormulaEquals('= "$+10.00" + 0', 10);
132- assertFormulaEquals('= "$-10.00" + 0', -10);
133-});
134-
135diff --git a/tests/SheetParsingTest.ts b/tests/SheetParsingTest.ts
136index 5c4a473..41e9e76 100644
137--- a/tests/SheetParsingTest.ts
138+++ b/tests/SheetParsingTest.ts
139@@ -14,6 +14,11 @@ test("Sheet parsing error", function(){
140 assertFormulaEqualsError('= SUM(', PARSE_ERROR);
141 });
142
143+test("Sheet &", function(){
144+ assertFormulaEquals('="hey"&" "&"there"', "hey there");
145+ assertFormulaEquals('=TEXT(12.3, "###.##")&"mm"', "12.3mm");
146+});
147+
148 test("Sheet *", function(){
149 assertFormulaEquals('= 10 * 10', 100);
150 assertFormulaEquals('= 10 * 0', 0);
151@@ -81,4 +86,28 @@ test("Sheet numbers/math", function(){
152 assertFormulaEquals('= "-$10.00" + 0', -10);
153 assertFormulaEquals('= "$+10.00" + 0', 10);
154 assertFormulaEquals('= "$-10.00" + 0', -10);
155+ assertFormulaEquals('= "10" + 10', 20);
156+ assertFormulaEquals('= "10.111111" + 0', 10.111111);
157+ assertFormulaEquals('= 10%', 0.1);
158+ assertFormulaEquals('= 10% + 1', 1.1);
159+ assertFormulaEquals('= "10e1" + 0', 100);
160+ assertFormulaEquals('= 10e1', 100);
161+ assertFormulaEquals('= 10e-1', 1);
162+ assertFormulaEquals('= 10e+1', 100);
163+ assertFormulaEquals('= 10E1', 100);
164+ assertFormulaEquals('= 10E-1', 1);
165+ assertFormulaEquals('= 10E+1', 100);
166+ assertFormulaEquals('= "1,000,000" + 0', 1000000);
167+ assertFormulaEqualsError('= "10e" + 10', VALUE_ERROR);
168+ assertFormulaEquals('= "+$10.00" + 0', 10);
169+ assertFormulaEquals('= "-$10.00" + 0', -10);
170+ assertFormulaEquals('= "$+10.00" + 0', 10);
171+ assertFormulaEquals('= "$-10.00" + 0', -10);
172+});
173+
174+test("Sheet parse range following comma", function(){
175+ // assertFormulaEquals('=SERIESSUM(1, 0, 1, [4, 5, 6])', 15);
176+ // assertFormulaEquals('=SERIESSUM([1], [0], [1], [4, 5, 6])', 15);
177 });
178+
179+