spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[Parser] beginning process of reformatting, for readability
author
Ben Vogt <[email protected]>
date
2017-08-13 21:55:40
stats
4 file(s) changed, 90 insertions(+), 8 deletions(-)
files
src/Parser.ts
src/Sheet.ts
tests/SheetFormulaTest.ts
tests/Utilities/TypeConverterTest.ts
  1diff --git a/src/Parser.ts b/src/Parser.ts
  2index 26a2e90..f8ca569 100644
  3--- a/src/Parser.ts
  4+++ b/src/Parser.ts
  5@@ -76,7 +76,38 @@ var Parser = (function () {
  6     for (o = o || {}, l = k.length; l--; o[k[l]] = v) {
  7     }
  8     return o
  9-  }, $V0 = [1, 4], $V1 = [1, 5], $V2 = [1, 7], $V3 = [1, 10], $V4 = [1, 8], $V5 = [1, 9], $V6 = [1, 11], $V7 = [1, 16], $V8 = [1, 17], $V9 = [1, 14], $Va = [1, 15], $Vb = [1, 18], $Vc = [1, 20], $Vd = [1, 21], $Ve = [1, 22], $Vf = [1, 23], $Vg = [1, 24], $Vh = [1, 25], $Vi = [1, 26], $Vj = [1, 27], $Vk = [1, 28], $Vl = [1, 29], $Vm = [5, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 30, 31], $Vn = [5, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 30, 31, 33], $Vo = [1, 38], $Vp = [5, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 30, 31, 35], $Vq = [5, 12, 13, 15, 16, 17, 18, 19, 30, 31], $Vr = [5, 12, 15, 16, 17, 18, 30, 31], $Vs = [5, 12, 13, 15, 16, 17, 18, 19, 20, 21, 30, 31], $Vt = [15, 30, 31], $Vu = [5, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 30, 31, 32, 36];
 10+  };
 11+  var $V0 = [1, 4];
 12+  var $V1 = [1, 5];
 13+  var $V2 = [1, 7];
 14+  var $V3 = [1, 10];
 15+  var $V4 = [1, 8];
 16+  var $V5 = [1, 9];
 17+  var $V6 = [1, 11];
 18+  var $V7 = [1, 16];
 19+  var $V8 = [1, 17];
 20+  var $V9 = [1, 14];
 21+  var $Va = [1, 15];
 22+  var $Vb = [1, 18];
 23+  var $Vc = [1, 20];
 24+  var $Vd = [1, 21];
 25+  var $Ve = [1, 22];
 26+  var $Vf = [1, 23];
 27+  var $Vg = [1, 24];
 28+  var $Vh = [1, 25];
 29+  var $Vi = [1, 26];
 30+  var $Vj = [1, 27];
 31+  var $Vk = [1, 28];
 32+  var $Vl = [1, 29];
 33+  var $Vm = [5, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 30, 31];
 34+  var $Vn = [5, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 30, 31, 33];
 35+  var $Vo = [1, 38];
 36+  var $Vp = [5, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 30, 31, 35, 38];
 37+  var $Vq = [5, 12, 13, 15, 16, 17, 18, 19, 30, 31];
 38+  var $Vr = [5, 12, 15, 16, 17, 18, 30, 31];
 39+  var $Vs = [5, 12, 13, 15, 16, 17, 18, 19, 20, 21, 30, 31];
 40+  var $Vt = [15, 30, 31];
 41+  var $Vu = [5, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 30, 31, 32, 36];
 42   var parser = {
 43     lexer: undefined,
 44     Parser: undefined,
 45@@ -154,7 +185,51 @@ var Parser = (function () {
 46       36: "#",
 47       37: "!"
 48     },
 49-    productions_: [0, [3, 2], [4, 1], [4, 1], [4, 1], [4, 1], [4, 1], [4, 3], [4, 3], [4, 3], [4, 3], [4, 4], [4, 4], [4, 4], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 2], [4, 2], [4, 3], [4, 4], [4, 1], [4, 1], [4, 2], [25, 1], [25, 3], [25, 1], [25, 3], [24, 1], [24, 1], [24, 3], [24, 3], [6, 1], [6, 3], [9, 1], [9, 3], [9, 2], [2, 3], [2, 4]],
 50+    productions_: [
 51+      0,
 52+      [3, 2],
 53+      [4, 1],
 54+      [4, 1],
 55+      [4, 1],
 56+      [4, 1],
 57+      [4, 1],
 58+      [4, 3],
 59+      [4, 3],
 60+      [4, 3],
 61+      [4, 3],
 62+      [4, 4],
 63+      [4, 4],
 64+      [4, 4],
 65+      [4, 3],
 66+      [4, 3],
 67+      [4, 3],
 68+      [4, 3],
 69+      [4, 3],
 70+      [4, 3],
 71+      [4, 3],
 72+      [4, 2],
 73+      [4, 2],
 74+      [4, 3],
 75+      [4, 4],
 76+      [4, 1],
 77+      [4, 1],
 78+      [4, 2],
 79+      [25, 1],
 80+      [25, 3],
 81+      [25, 1],
 82+      [25, 3],
 83+      [24, 1],
 84+      [24, 1],
 85+      [24, 3],
 86+      [24, 3],
 87+      [6, 1],
 88+      [6, 3],
 89+      [9, 1],
 90+      [9, 3],
 91+      [9, 2],
 92+      [2, 3],
 93+      [2, 4]
 94+    ],
 95     performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
 96       /* this == yyval */
 97 
 98@@ -1465,7 +1540,7 @@ var Parser = (function () {
 99         /^(?:$)/], // rule 36
100       conditions: {
101         "INITIAL": {
102-          "rules": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36],
103+          "rules": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37],
104           "inclusive": true
105         }
106       }
107diff --git a/src/Sheet.ts b/src/Sheet.ts
108index 20ab06d..bd1204a 100644
109--- a/src/Sheet.ts
110+++ b/src/Sheet.ts
111@@ -341,7 +341,9 @@ var Sheet = (function () {
112     /**
113      * Is the value a number or can the value be interpreted as a number
114      */
115-    number: TypeConverter.valueToNumber,
116+    number: function (x) {
117+      return TypeConverter.valueToNumber(x);
118+    },
119 
120     string: function (str) {
121       return str.substring(1, str.length - 1);
122diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
123index 3621d58..1401d3d 100644
124--- a/tests/SheetFormulaTest.ts
125+++ b/tests/SheetFormulaTest.ts
126@@ -992,15 +992,16 @@ test("Sheet ^", function(){
127 
128 test("Sheet numbers/math", function(){
129   assertFormulaEquals('= "10" + 10', 20);
130-  assertFormulaEquals('="10.111111" + 0', 10.111111);
131+  assertFormulaEquals('= "10.111111" + 0', 10.111111);
132   assertFormulaEquals('= 10%', 0.1);
133   assertFormulaEquals('= 10% + 1', 1.1);
134-  assertFormulaEquals('="10e1" + 0', 100);
135-  assertFormulaEquals('="1,000,000" + 0', 1000000);
136-  assertFormulaEqualsError('= "10e" + 10', VALUE_ERROR); // TODO: Should fail, but doesn't because 10e parses to a string
137-  assertFormulaEquals('="+$10.00" + 0', 10);
138-  assertFormulaEquals('="-$10.00" + 0', -10);
139-  assertFormulaEquals('="$+10.00" + 0', 10);
140-  assertFormulaEquals('="$-10.00" + 0', -10);
141+  assertFormulaEquals('= "10e1" + 0', 100);
142+  // assertFormulaEquals('= 10e1', 100);
143+  assertFormulaEquals('= "1,000,000" + 0', 1000000);
144+  assertFormulaEqualsError('= "10e" + 10', VALUE_ERROR);
145+  assertFormulaEquals('= "+$10.00" + 0', 10);
146+  assertFormulaEquals('= "-$10.00" + 0', -10);
147+  assertFormulaEquals('= "$+10.00" + 0', 10);
148+  assertFormulaEquals('= "$-10.00" + 0', -10);
149 });
150 
151diff --git a/tests/Utilities/TypeConverterTest.ts b/tests/Utilities/TypeConverterTest.ts
152index c39d10e..ba0aeec 100644
153--- a/tests/Utilities/TypeConverterTest.ts
154+++ b/tests/Utilities/TypeConverterTest.ts
155@@ -226,6 +226,7 @@ test("TypeConverter.stringToNumber", function () {
156   assertEquals(TypeConverter.stringToNumber("33.213131"), 33.213131);
157   assertEquals(TypeConverter.stringToNumber("41.1231"), 41.1231);
158   assertEquals(TypeConverter.stringToNumber("10e1"), 100);
159+  assertEquals(TypeConverter.stringToNumber("10e2"), 1000);
160   assertEquals(TypeConverter.stringToNumber("10E1"), 100);
161   assertEquals(TypeConverter.stringToNumber("10.44E1"), 104.39999999999999);
162   assertEquals(TypeConverter.stringToNumber("10.44E10"), 104400000000);