spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[ISSUE-013, ISSUE-009] Equality checking inside parentheses should return boolean values, checking type and value for EQ.
author
Ben Vogt <[email protected]>
date
2018-02-10 20:17:48
stats
8 file(s) changed, 41 insertions(+), 49 deletions(-)
files
TODO.md
dist/Parser/Parser.js
dist/Parser/ParserConstants.js
src/Parser/Parser.ts
src/Parser/ParserConstants.ts
src/Parser/ReduceActions.ts
tests/ParsingTest.ts
tests/SheetBasicTests.ts
  1diff --git a/TODO.md b/TODO.md
  2index 86ed4d2..9de422f 100644
  3--- a/TODO.md
  4+++ b/TODO.md
  5@@ -31,11 +31,6 @@ Right now, arrays and reference literals in a formula are parsed using JS `eval`
  6 ### [ISSUE-008] Error literals should be thrown
  7 Error literals in valid locations should throw themselves. For example "=10 + #DIV?/0!" should throw a Divide-By-Zero error.
  8 
  9-
 10-### [ISSUE-009] Equality checking should check for type and value
 11-Currently '=10 = "10"' is true, when it should be false.
 12-
 13-
 14 ### [ISSUE-010] Input should be able to start with a decimal.
 15 Currently '=.1' should parse properly. Could be solved by going back from handling number input in reg-ex to handling it with the parser logic. See [ISSUE-011].
 16 
 17@@ -48,10 +43,6 @@ Currently '=0.e1' should parse properly.  Could be solved by going back from han
 18 Single quotes are reserved for variables, like sheet names.
 19 
 20 
 21-### [ISSUE-013] Equality checking inside parentheses should return boolean values
 22-For example '=(1=1)' should return true.
 23-
 24-
 25 ### [ISSUE-014] Cell reference ranges should not return nested values
 26 For example '=(E1:E4)' should return an array of values, not a nested array of values.
 27 
 28diff --git a/dist/Parser/Parser.js b/dist/Parser/Parser.js
 29index 84a5359..78513a8 100644
 30--- a/dist/Parser/Parser.js
 31+++ b/dist/Parser/Parser.js
 32@@ -50,8 +50,8 @@ var Parser = (function () {
 33                     case 9 /* Plus */:
 34                         this.$ = Math_1.SUM(virtualStack[vsl - 2], virtualStack[vsl]);
 35                         break;
 36-                    case 10 /* LastNumber */:
 37-                        this.$ = TypeConverter_1.TypeConverter.valueToNumber(virtualStack[vsl - 1]);
 38+                    case 10 /* LastExpression */:
 39+                        this.$ = virtualStack[vsl - 1];
 40                         break;
 41                     case 11 /* LTE */:
 42                         this.$ = Math_1.LTE(virtualStack[vsl - 3], virtualStack[vsl]);
 43@@ -167,7 +167,7 @@ var Parser = (function () {
 44                         case 7 /* Ampersand */:
 45                         case 8 /* Equals */:
 46                         case 9 /* Plus */:
 47-                        case 10 /* LastNumber */:
 48+                        case 10 /* LastExpression */:
 49                         case 11 /* LTE */:
 50                         case 12 /* GTE */:
 51                         case 13 /* NotEqual */:
 52diff --git a/dist/Parser/ParserConstants.js b/dist/Parser/ParserConstants.js
 53index aa8e748..30cb88b 100644
 54--- a/dist/Parser/ParserConstants.js
 55+++ b/dist/Parser/ParserConstants.js
 56@@ -31,7 +31,7 @@ productions[6 /* AsString */] = new ReductionPair_1.ReductionPair(Symbols_1.Symb
 57 productions[7 /* Ampersand */] = new ReductionPair_1.ReductionPair(Symbols_1.Symbol.Expression, 3);
 58 productions[8 /* Equals */] = new ReductionPair_1.ReductionPair(Symbols_1.Symbol.Expression, 3);
 59 productions[9 /* Plus */] = new ReductionPair_1.ReductionPair(Symbols_1.Symbol.Expression, 3);
 60-productions[10 /* LastNumber */] = new ReductionPair_1.ReductionPair(Symbols_1.Symbol.Expression, 3);
 61+productions[10 /* LastExpression */] = new ReductionPair_1.ReductionPair(Symbols_1.Symbol.Expression, 3);
 62 productions[11 /* LTE */] = new ReductionPair_1.ReductionPair(Symbols_1.Symbol.Expression, 4);
 63 productions[12 /* GTE */] = new ReductionPair_1.ReductionPair(Symbols_1.Symbol.Expression, 4);
 64 productions[13 /* NotEqual */] = new ReductionPair_1.ReductionPair(Symbols_1.Symbol.Expression, 4);
 65@@ -867,19 +867,19 @@ table[56 /* VariableSeq_Decimal_Variable */] = ObjectBuilder_1.ObjectBuilder
 66     .add(Symbols_1.Symbol.Decimal, [REDUCE, 37 /* EnsureLastTwoINArrayAndPush */])
 67     .build();
 68 table[57 /* Expression_RightParen */] = ObjectBuilder_1.ObjectBuilder
 69-    .add(Symbols_1.Symbol.EOF, [REDUCE, 10 /* LastNumber */])
 70-    .add(Symbols_1.Symbol.Ampersand, [REDUCE, 10 /* LastNumber */])
 71-    .add(Symbols_1.Symbol.Equals, [REDUCE, 10 /* LastNumber */])
 72-    .add(Symbols_1.Symbol.Plus, [REDUCE, 10 /* LastNumber */])
 73-    .add(Symbols_1.Symbol.RightParen, [REDUCE, 10 /* LastNumber */])
 74-    .add(Symbols_1.Symbol.LessThan, [REDUCE, 10 /* LastNumber */])
 75-    .add(Symbols_1.Symbol.GreaterThan, [REDUCE, 10 /* LastNumber */])
 76-    .add(Symbols_1.Symbol.Minus, [REDUCE, 10 /* LastNumber */])
 77-    .add(Symbols_1.Symbol.Asterisk, [REDUCE, 10 /* LastNumber */])
 78-    .add(Symbols_1.Symbol.Divide, [REDUCE, 10 /* LastNumber */])
 79-    .add(Symbols_1.Symbol.Carrot, [REDUCE, 10 /* LastNumber */])
 80-    .add(Symbols_1.Symbol.Semicolon, [REDUCE, 10 /* LastNumber */])
 81-    .add(Symbols_1.Symbol.Comma, [REDUCE, 10 /* LastNumber */])
 82+    .add(Symbols_1.Symbol.EOF, [REDUCE, 10 /* LastExpression */])
 83+    .add(Symbols_1.Symbol.Ampersand, [REDUCE, 10 /* LastExpression */])
 84+    .add(Symbols_1.Symbol.Equals, [REDUCE, 10 /* LastExpression */])
 85+    .add(Symbols_1.Symbol.Plus, [REDUCE, 10 /* LastExpression */])
 86+    .add(Symbols_1.Symbol.RightParen, [REDUCE, 10 /* LastExpression */])
 87+    .add(Symbols_1.Symbol.LessThan, [REDUCE, 10 /* LastExpression */])
 88+    .add(Symbols_1.Symbol.GreaterThan, [REDUCE, 10 /* LastExpression */])
 89+    .add(Symbols_1.Symbol.Minus, [REDUCE, 10 /* LastExpression */])
 90+    .add(Symbols_1.Symbol.Asterisk, [REDUCE, 10 /* LastExpression */])
 91+    .add(Symbols_1.Symbol.Divide, [REDUCE, 10 /* LastExpression */])
 92+    .add(Symbols_1.Symbol.Carrot, [REDUCE, 10 /* LastExpression */])
 93+    .add(Symbols_1.Symbol.Semicolon, [REDUCE, 10 /* LastExpression */])
 94+    .add(Symbols_1.Symbol.Comma, [REDUCE, 10 /* LastExpression */])
 95     .build();
 96 table[58 /* Function_RightParenNoArguments */] = ObjectBuilder_1.ObjectBuilder
 97     .add(Symbols_1.Symbol.EOF, [REDUCE, 23 /* CallFunctionLastBlank */])
 98diff --git a/src/Parser/Parser.ts b/src/Parser/Parser.ts
 99index b051f31..ac97eeb 100644
100--- a/src/Parser/Parser.ts
101+++ b/src/Parser/Parser.ts
102@@ -90,8 +90,8 @@ let Parser = (function () {
103           case ReduceActions.Plus:
104             this.$ = SUM(virtualStack[vsl - 2], virtualStack[vsl]);
105             break;
106-          case ReduceActions.LastNumber:
107-            this.$ = TypeConverter.valueToNumber(virtualStack[vsl - 1]);
108+          case ReduceActions.LastExpression:
109+            this.$ = virtualStack[vsl - 1];
110             break;
111           case ReduceActions.LTE:
112             this.$ = LTE(virtualStack[vsl - 3], virtualStack[vsl]);
113@@ -206,7 +206,7 @@ let Parser = (function () {
114             case ReduceActions.Ampersand:
115             case ReduceActions.Equals:
116             case ReduceActions.Plus:
117-            case ReduceActions.LastNumber:
118+            case ReduceActions.LastExpression:
119             case ReduceActions.LTE:
120             case ReduceActions.GTE:
121             case ReduceActions.NotEqual:
122diff --git a/src/Parser/ParserConstants.ts b/src/Parser/ParserConstants.ts
123index cdcf805..f66cff4 100644
124--- a/src/Parser/ParserConstants.ts
125+++ b/src/Parser/ParserConstants.ts
126@@ -39,7 +39,7 @@ productions[ReduceActions.AsString] = new ReductionPair(Symbol.Expression, 1);
127 productions[ReduceActions.Ampersand] = new ReductionPair(Symbol.Expression, 3);
128 productions[ReduceActions.Equals] = new ReductionPair(Symbol.Expression, 3);
129 productions[ReduceActions.Plus] = new ReductionPair(Symbol.Expression, 3);
130-productions[ReduceActions.LastNumber] = new ReductionPair(Symbol.Expression, 3);
131+productions[ReduceActions.LastExpression] = new ReductionPair(Symbol.Expression, 3);
132 productions[ReduceActions.LTE] = new ReductionPair(Symbol.Expression, 4);
133 productions[ReduceActions.GTE] = new ReductionPair(Symbol.Expression, 4);
134 productions[ReduceActions.NotEqual] = new ReductionPair(Symbol.Expression, 4);
135@@ -968,19 +968,19 @@ table[State.VariableSeq_Decimal_Variable] = ObjectBuilder
136   .add(Symbol.Decimal, [REDUCE, ReduceActions.EnsureLastTwoINArrayAndPush])
137   .build();
138 table[State.Expression_RightParen] = ObjectBuilder
139-  .add(Symbol.EOF, [REDUCE, ReduceActions.LastNumber])
140-  .add(Symbol.Ampersand, [REDUCE, ReduceActions.LastNumber])
141-  .add(Symbol.Equals, [REDUCE, ReduceActions.LastNumber])
142-  .add(Symbol.Plus, [REDUCE, ReduceActions.LastNumber])
143-  .add(Symbol.RightParen, [REDUCE, ReduceActions.LastNumber])
144-  .add(Symbol.LessThan, [REDUCE, ReduceActions.LastNumber])
145-  .add(Symbol.GreaterThan, [REDUCE, ReduceActions.LastNumber])
146-  .add(Symbol.Minus, [REDUCE, ReduceActions.LastNumber])
147-  .add(Symbol.Asterisk, [REDUCE, ReduceActions.LastNumber])
148-  .add(Symbol.Divide, [REDUCE, ReduceActions.LastNumber])
149-  .add(Symbol.Carrot, [REDUCE, ReduceActions.LastNumber])
150-  .add(Symbol.Semicolon, [REDUCE, ReduceActions.LastNumber])
151-  .add(Symbol.Comma, [REDUCE, ReduceActions.LastNumber])
152+  .add(Symbol.EOF, [REDUCE, ReduceActions.LastExpression])
153+  .add(Symbol.Ampersand, [REDUCE, ReduceActions.LastExpression])
154+  .add(Symbol.Equals, [REDUCE, ReduceActions.LastExpression])
155+  .add(Symbol.Plus, [REDUCE, ReduceActions.LastExpression])
156+  .add(Symbol.RightParen, [REDUCE, ReduceActions.LastExpression])
157+  .add(Symbol.LessThan, [REDUCE, ReduceActions.LastExpression])
158+  .add(Symbol.GreaterThan, [REDUCE, ReduceActions.LastExpression])
159+  .add(Symbol.Minus, [REDUCE, ReduceActions.LastExpression])
160+  .add(Symbol.Asterisk, [REDUCE, ReduceActions.LastExpression])
161+  .add(Symbol.Divide, [REDUCE, ReduceActions.LastExpression])
162+  .add(Symbol.Carrot, [REDUCE, ReduceActions.LastExpression])
163+  .add(Symbol.Semicolon, [REDUCE, ReduceActions.LastExpression])
164+  .add(Symbol.Comma, [REDUCE, ReduceActions.LastExpression])
165   .build();
166 table[State.Function_RightParenNoArguments] = ObjectBuilder
167   .add(Symbol.EOF, [REDUCE, ReduceActions.CallFunctionLastBlank])
168diff --git a/src/Parser/ReduceActions.ts b/src/Parser/ReduceActions.ts
169index ebcbd97..94accb4 100644
170--- a/src/Parser/ReduceActions.ts
171+++ b/src/Parser/ReduceActions.ts
172@@ -7,7 +7,7 @@ const enum ReduceActions {
173   Ampersand = 7,
174   Equals = 8,
175   Plus = 9,
176-  LastNumber = 10,
177+  LastExpression = 10,
178   LTE = 11,
179   GTE = 12,
180   NotEqual = 13,
181diff --git a/tests/ParsingTest.ts b/tests/ParsingTest.ts
182index 73e273d..f11bed7 100644
183--- a/tests/ParsingTest.ts
184+++ b/tests/ParsingTest.ts
185@@ -169,8 +169,8 @@ test("Parse boolean literals", function(){
186 });
187 
188 test("Parse boolean logic", function(){
189-  // assertFormulaEquals('=(1=1)', true); // TODO: [ISSUE-013]
190-  // assertFormulaEquals('=(1=2)', false); // TODO: [ISSUE-013]
191+  assertFormulaEquals('=(1=1)', true);
192+  assertFormulaEquals('=(1=2)', false);
193   assertFormulaEquals('=(1=1)+2', 3);
194 
195 });
196@@ -296,7 +296,7 @@ test("Combinations of expressions and operators", function(){
197   test("Combinations of expressions and operators, equality operator", function(){
198     assertFormulaEquals('=10 = 10', true);
199     assertFormulaEquals('=10 = TRUE', false);
200-    // assertFormulaEquals('=10 = "10"', true); // TODO: [ISSUE-009]
201+    assertFormulaEquals('=10 = "10"', false);
202     assertFormulaEquals('=10 = (2*2)', false);
203     assertFormulaEquals('=10 = SUM(1, 2)', false);
204     // assertFormulaEquals('=10 >= [10]', 10); // TODO: [ISSUE-007]
205diff --git a/tests/SheetBasicTests.ts b/tests/SheetBasicTests.ts
206index 25d6686..645d0a8 100644
207--- a/tests/SheetBasicTests.ts
208+++ b/tests/SheetBasicTests.ts
209@@ -203,8 +203,8 @@ test("Sheet, parse boolean literals", function(){
210 });
211 
212 test("Sheet, parse comparison logic inside parentheses", function(){
213-  // assertEquals(parser.parse('(1=1)'), true); // TODO: [ISSUE-013]
214-  // assertEquals(parser.parse('(1=2)'), false); // TODO: [ISSUE-013]
215+  assertFormulaEquals('=(1=1)', true);
216+  assertFormulaEquals('=(1=2)', false);
217   assertFormulaEquals('=(1=1)+2', 3);
218 });
219 
220@@ -220,4 +220,3 @@ test("Sheet state sequence: (number, ampersand, expression)", function(){
221   assertFormulaEquals('=10&"str"', "10str");
222   assertFormulaEquals('=10 & TRUE', "10TRUE");
223 });
224-