commit
message
Allowing formulas with dot-notation to be parsed as regular formulas.
author
Ben Vogt <[email protected]>
date
2017-01-10 23:23:12
stats
4 file(s) changed,
39 insertions(+),
5 deletions(-)
files
README.md
lib/parser.js
src/SupportedFormulas.ts
tests.sh
1diff --git a/README.md b/README.md
2index b53f986..ef11b73 100644
3--- a/README.md
4+++ b/README.md
5@@ -14,8 +14,5 @@ Things I should do.
6 * SUM_ formulas
7 * ACCRINT
8
9-### How do we parse formula names that contain delimiters?
10-For example how do we parse `=F.DIST` to `=FDIST`? Currently doesn't work.
11-
12 ### Moment.js issue.
13 There are an awful lot of tests that fail when we use formulajs' version of moment. We should probably replace it.
14diff --git a/lib/parser.js b/lib/parser.js
15index af9617f..4206cfd 100644
16--- a/lib/parser.js
17+++ b/lib/parser.js
18@@ -951,7 +951,44 @@ var Parser = (function(){
19 break;
20 }
21 },
22- rules: [/^(?:\s+)/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:[A-Za-z]{1,}[A-Za-z_0-9]+(?=[(]))/,/^(?:([0]?[1-9]|1[0-2])[:][0-5][0-9]([:][0-5][0-9])?[ ]?(AM|am|aM|Am|PM|pm|pM|Pm))/,/^(?:([0]?[0-9]|1[0-9]|2[0-3])[:][0-5][0-9]([:][0-5][0-9])?)/,/^(?:\$[A-Za-z]+\$[0-9]+)/,/^(?:[A-Za-z]+[0-9]+)/,/^(?:[A-Za-z]+(?=[(]))/,/^(?:[A-Za-z]{1,}[A-Za-z_0-9]+)/,/^(?:[A-Za-z_]+)/,/^(?:[0-9]+)/,/^(?:\[(.*)?\])/,/^(?:\$)/,/^(?:&)/,/^(?: )/,/^(?:[.])/,/^(?::)/,/^(?:;)/,/^(?:,)/,/^(?:\*)/,/^(?:\/)/,/^(?:-)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\))/,/^(?:>)/,/^(?:<)/,/^(?:NOT\b)/,/^(?:")/,/^(?:')/,/^(?:!)/,/^(?:=)/,/^(?:%)/,/^(?:[#])/,/^(?:$)/],
23+ // NOTE: Alterations made in some regular-expressions to allow for formulas containing dot-notation. Eg: F.INV
24+ rules: [ /^(?:\s+)/,
25+ /^(?:"(\\["]|[^"])*")/,
26+ /^(?:'(\\[']|[^'])*')/,
27+ /^(?:[A-Za-z.]{1,}[A-Za-z_0-9]+(?=[(]))/, // Changed from /^(?:[A-Za-z]{1,}[A-Za-z_0-9]+(?=[(]))/
28+ /^(?:([0]?[1-9]|1[0-2])[:][0-5][0-9]([:][0-5][0-9])?[ ]?(AM|am|aM|Am|PM|pm|pM|Pm))/,
29+ /^(?:([0]?[0-9]|1[0-9]|2[0-3])[:][0-5][0-9]([:][0-5][0-9])?)/,
30+ /^(?:\$[A-Za-z]+\$[0-9]+)/,
31+ /^(?:[A-Za-z]+[0-9]+)/,
32+ /^(?:[A-Za-z.]+(?=[(]))/, //Changed from /^(?:[A-Za-z.]+(?=[(]))/
33+ /^(?:[A-Za-z]{1,}[A-Za-z_0-9]+)/,
34+ /^(?:[A-Za-z_]+)/,
35+ /^(?:[0-9]+)/,
36+ /^(?:\[(.*)?\])/,
37+ /^(?:\$)/,
38+ /^(?:&)/,
39+ /^(?: )/,
40+ /^(?:[.])/,
41+ /^(?::)/,
42+ /^(?:;)/,
43+ /^(?:,)/,
44+ /^(?:\*)/,
45+ /^(?:\/)/,
46+ /^(?:-)/,
47+ /^(?:\+)/,
48+ /^(?:\^)/,
49+ /^(?:\()/,
50+ /^(?:\))/,
51+ /^(?:>)/,
52+ /^(?:<)/,
53+ /^(?:NOT\b)/,
54+ /^(?:")/,
55+ /^(?:')/,
56+ /^(?:!)/,
57+ /^(?:=)/,
58+ /^(?:%)/,
59+ /^(?:[#])/,
60+ /^(?:$)/ ],
61 conditions: {"INITIAL":{"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],"inclusive":true}}
62 });
63 return lexer;
64diff --git a/src/SupportedFormulas.ts b/src/SupportedFormulas.ts
65index 52b9eb7..605f5ec 100644
66--- a/src/SupportedFormulas.ts
67+++ b/src/SupportedFormulas.ts
68@@ -1,6 +1,5 @@
69 /// <reference path="../node_modules/moment/moment.d.ts"/>
70 import * as moment from "moment";
71-import * as Formula from "formulajs"
72
73 const SUPPORTED_FORMULAS = [
74 'ABS', 'ACCRINT', 'ACOS', 'ACOSH', 'ACOTH', 'AND', 'ARABIC', 'ASIN', 'ASINH', 'ATAN', 'ATAN2', 'ATANH', 'AVEDEV', 'AVERAGE', 'AVERAGEA', 'AVERAGEIF',
75diff --git a/tests.sh b/tests.sh
76index 588d0f1..f08b91d 100755
77--- a/tests.sh
78+++ b/tests.sh
79@@ -2,6 +2,7 @@
80
81 echo "$(date) Compiling Tests"
82 tsc --outDir test_output tests/*.ts
83+cp lib/parser.js test_output/src/
84
85 echo "$(date) Running All Tests"
86 for test_file in test_output/tests/*.js