@leankylin-sheet/formula-parser 3.1.29 → 3.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/error.d.ts +10 -0
  2. package/dist/evaluate-by-operator/evaluate-by-operator.d.ts +2 -0
  3. package/dist/evaluate-by-operator/operator/add.d.ts +6 -0
  4. package/dist/evaluate-by-operator/operator/ampersand.d.ts +6 -0
  5. package/dist/evaluate-by-operator/operator/divide.d.ts +6 -0
  6. package/dist/evaluate-by-operator/operator/equal.d.ts +6 -0
  7. package/dist/evaluate-by-operator/operator/formula-function.d.ts +7 -0
  8. package/dist/evaluate-by-operator/operator/greater-than-or-equal.d.ts +6 -0
  9. package/dist/evaluate-by-operator/operator/greater-than.d.ts +6 -0
  10. package/dist/evaluate-by-operator/operator/less-than-or-equal.d.ts +6 -0
  11. package/dist/evaluate-by-operator/operator/less-than.d.ts +6 -0
  12. package/dist/evaluate-by-operator/operator/minus.d.ts +6 -0
  13. package/dist/evaluate-by-operator/operator/multiply.d.ts +6 -0
  14. package/dist/evaluate-by-operator/operator/not-equal.d.ts +6 -0
  15. package/dist/evaluate-by-operator/operator/power.d.ts +6 -0
  16. package/dist/grammar-parser/grammar-parser.d.ts +4 -0
  17. package/dist/helper/cell.d.ts +6 -0
  18. package/dist/helper/number.d.ts +2 -0
  19. package/dist/helper/string.d.ts +1 -0
  20. package/{es/index.js → dist/index.d.ts} +5 -5
  21. package/{lib/grammar-parser/grammar-parser.js → dist/index.esm.js} +856 -46
  22. package/{es/grammar-parser/grammar-parser.js → dist/index.js} +903 -42
  23. package/dist/parser.d.ts +20 -0
  24. package/dist/supported-formulas.d.ts +2 -0
  25. package/package.json +6 -18
  26. package/LICENSE +0 -21
  27. package/es/error.js +0 -45
  28. package/es/evaluate-by-operator/evaluate-by-operator.js +0 -70
  29. package/es/evaluate-by-operator/operator/add.js +0 -16
  30. package/es/evaluate-by-operator/operator/ampersand.js +0 -10
  31. package/es/evaluate-by-operator/operator/divide.js +0 -21
  32. package/es/evaluate-by-operator/operator/equal.js +0 -5
  33. package/es/evaluate-by-operator/operator/formula-function.js +0 -40
  34. package/es/evaluate-by-operator/operator/greater-than-or-equal.js +0 -5
  35. package/es/evaluate-by-operator/operator/greater-than.js +0 -5
  36. package/es/evaluate-by-operator/operator/less-than-or-equal.js +0 -5
  37. package/es/evaluate-by-operator/operator/less-than.js +0 -5
  38. package/es/evaluate-by-operator/operator/minus.js +0 -16
  39. package/es/evaluate-by-operator/operator/multiply.js +0 -16
  40. package/es/evaluate-by-operator/operator/not-equal.js +0 -5
  41. package/es/evaluate-by-operator/operator/power.js +0 -11
  42. package/es/grammar-parser/grammar-parser.jison +0 -230
  43. package/es/helper/cell.js +0 -117
  44. package/es/helper/number.js +0 -25
  45. package/es/helper/string.js +0 -13
  46. package/es/parser.js +0 -306
  47. package/es/supported-formulas.js +0 -3
  48. package/lib/error.js +0 -53
  49. package/lib/evaluate-by-operator/evaluate-by-operator.js +0 -77
  50. package/lib/evaluate-by-operator/operator/add.js +0 -23
  51. package/lib/evaluate-by-operator/operator/ampersand.js +0 -17
  52. package/lib/evaluate-by-operator/operator/divide.js +0 -28
  53. package/lib/evaluate-by-operator/operator/equal.js +0 -12
  54. package/lib/evaluate-by-operator/operator/formula-function.js +0 -51
  55. package/lib/evaluate-by-operator/operator/greater-than-or-equal.js +0 -12
  56. package/lib/evaluate-by-operator/operator/greater-than.js +0 -12
  57. package/lib/evaluate-by-operator/operator/less-than-or-equal.js +0 -12
  58. package/lib/evaluate-by-operator/operator/less-than.js +0 -12
  59. package/lib/evaluate-by-operator/operator/minus.js +0 -23
  60. package/lib/evaluate-by-operator/operator/multiply.js +0 -23
  61. package/lib/evaluate-by-operator/operator/not-equal.js +0 -12
  62. package/lib/evaluate-by-operator/operator/power.js +0 -18
  63. package/lib/grammar-parser/grammar-parser.jison +0 -230
  64. package/lib/helper/cell.js +0 -128
  65. package/lib/helper/number.js +0 -32
  66. package/lib/helper/string.js +0 -19
  67. package/lib/index.js +0 -115
  68. package/lib/parser.js +0 -314
  69. package/lib/supported-formulas.js +0 -12
@@ -0,0 +1,20 @@
1
+ export default Parser;
2
+ declare class Parser {
3
+ parser: GrammarParser;
4
+ variables: any;
5
+ functions: any;
6
+ options: any;
7
+ parse(expression: string, options: {
8
+ sheetId: string;
9
+ }): any;
10
+ setVariable(name: string, value: any): Parser;
11
+ getVariable(name: string): any;
12
+ private _callVariable;
13
+ setFunction(name: string, fn: Function): Parser;
14
+ getFunction(name: string): any;
15
+ private _callFunction;
16
+ private _callCellValue;
17
+ private _callRangeValue;
18
+ private _throwError;
19
+ }
20
+ import { Parser as GrammarParser } from "./grammar-parser/grammar-parser";
@@ -0,0 +1,2 @@
1
+ export default SUPPORTED_FORMULAS;
2
+ declare const SUPPORTED_FORMULAS: string[];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@leankylin-sheet/formula-parser",
3
- "version": "3.1.29",
3
+ "version": "3.1.31",
4
4
  "description": "Formula parser",
5
- "main": "lib/index.js",
6
- "module": "es/index.js",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "typings": "dist/index.d.ts",
7
8
  "files": [
8
- "es",
9
- "lib"
9
+ "dist"
10
10
  ],
11
11
  "scripts": {
12
12
  "clean": "rimraf tmp coverage",
@@ -29,23 +29,11 @@
29
29
  "author": "Handsoncode <hello@handsontable.com>",
30
30
  "license": "MIT",
31
31
  "devDependencies": {
32
- "@babel/cli": "^7.12.10",
33
- "@babel/core": "^7.12.10",
34
- "@babel/preset-env": "^7.12.10",
35
- "babel-eslint": "^10.1.0",
36
- "babel-loader": "^8.2.2",
37
32
  "cross-env": "^5.2.0",
38
- "eslint": "^8.31.0",
39
- "eslint-config-airbnb-base": "^11.2.0",
40
- "eslint-plugin-import": "^2.14.0",
41
33
  "fs-extra": "^9.0.1",
42
34
  "generate-release": "^1.1.1",
43
- "jest": "^26.6.3",
44
- "jest-cli": "^29.3.1",
45
35
  "jison": "^0.4.17",
46
- "rimraf": "^3.0.2",
47
- "webpack": "^4.44.2",
48
- "webpack-cli": "^4.2.0"
36
+ "rimraf": "^3.0.2"
49
37
  },
50
38
  "dependencies": {
51
39
  "@formulajs/formulajs": "^2.9.3",
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- (The MIT License)
2
-
3
- Copyright (c) Handsoncode sp. z o.o. <hello@handsoncode.net>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/es/error.js DELETED
@@ -1,45 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
4
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
5
- export var ERROR = 'ERROR';
6
- export var ERROR_DIV_ZERO = 'DIV/0';
7
- export var ERROR_NAME = 'NAME';
8
- export var ERROR_NOT_AVAILABLE = 'N/A';
9
- export var ERROR_NULL = 'NULL';
10
- export var ERROR_NUM = 'NUM';
11
- export var ERROR_REF = 'REF';
12
- export var ERROR_VALUE = 'VALUE';
13
- var errors = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ERROR, '#ERROR!'), ERROR_DIV_ZERO, '#DIV/0!'), ERROR_NAME, '#NAME?'), ERROR_NOT_AVAILABLE, '#N/A'), ERROR_NULL, '#NULL!'), ERROR_NUM, '#NUM!'), ERROR_REF, '#REF!'), ERROR_VALUE, '#VALUE!');
14
-
15
- /**
16
- * Return error type based on provided error id.
17
- *
18
- * @param {String} type Error type.
19
- * @returns {String|null} Returns error id.
20
- */
21
- export default function error(type) {
22
- var result;
23
- type = (type + '').replace(/#|!|\?/g, '');
24
- if (errors[type]) {
25
- result = errors[type];
26
- }
27
- return result ? result : null;
28
- }
29
-
30
- /**
31
- * Check if error type is strict valid with knows errors.
32
- *
33
- * @param {String} Error type.
34
- * @return {Boolean}
35
- */
36
- export function isValidStrict(type) {
37
- var valid = false;
38
- for (var i in errors) {
39
- if (Object.prototype.hasOwnProperty.call(errors, i) && errors[i] === type) {
40
- valid = true;
41
- break;
42
- }
43
- }
44
- return valid;
45
- }
@@ -1,70 +0,0 @@
1
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
- /* eslint-disable import/no-named-as-default-member */
8
- import add from './operator/add';
9
- import ampersand from './operator/ampersand';
10
- import divide from './operator/divide';
11
- import equal from './operator/equal';
12
- import formulaFunction from './operator/formula-function';
13
- import greaterThan from './operator/greater-than';
14
- import greaterThanOrEqual from './operator/greater-than-or-equal';
15
- import lessThan from './operator/less-than';
16
- import lessThanOrEqual from './operator/less-than-or-equal';
17
- import minus from './operator/minus';
18
- import multiply from './operator/multiply';
19
- import notEqual from './operator/not-equal';
20
- import power from './operator/power';
21
- import { ERROR_NAME } from './../error';
22
- var availableOperators = Object.create(null);
23
-
24
- /**
25
- * Evaluate values by operator id.git
26
- *
27
- * @param {String} operator Operator id.
28
- * @param {Array} [params=[]] Arguments to evaluate.
29
- * @returns {*}
30
- */
31
- export default function evaluateByOperator(operator) {
32
- var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
33
- operator = operator.toUpperCase();
34
- if (!availableOperators[operator]) {
35
- throw Error(ERROR_NAME);
36
- }
37
- return availableOperators[operator].apply(availableOperators, _toConsumableArray(params));
38
- }
39
-
40
- /**
41
- * Register operator.
42
- *
43
- * @param {String|Array} symbol Symbol to register.
44
- * @param {Function} func Logic to register for this symbol.
45
- */
46
- export function registerOperation(symbol, func) {
47
- if (!Array.isArray(symbol)) {
48
- symbol = [symbol.toUpperCase()];
49
- }
50
- symbol.forEach(function (s) {
51
- if (func.isFactory) {
52
- availableOperators[s] = func(s);
53
- } else {
54
- availableOperators[s] = func;
55
- }
56
- });
57
- }
58
- registerOperation(add.SYMBOL, add);
59
- registerOperation(ampersand.SYMBOL, ampersand);
60
- registerOperation(divide.SYMBOL, divide);
61
- registerOperation(equal.SYMBOL, equal);
62
- registerOperation(power.SYMBOL, power);
63
- registerOperation(formulaFunction.SYMBOL, formulaFunction);
64
- registerOperation(greaterThan.SYMBOL, greaterThan);
65
- registerOperation(greaterThanOrEqual.SYMBOL, greaterThanOrEqual);
66
- registerOperation(lessThan.SYMBOL, lessThan);
67
- registerOperation(lessThanOrEqual.SYMBOL, lessThanOrEqual);
68
- registerOperation(multiply.SYMBOL, multiply);
69
- registerOperation(notEqual.SYMBOL, notEqual);
70
- registerOperation(minus.SYMBOL, minus);
@@ -1,16 +0,0 @@
1
- import { toNumber } from './../../helper/number';
2
- import { ERROR_VALUE } from './../../error';
3
- export var SYMBOL = '+';
4
- export default function func(first) {
5
- for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
6
- rest[_key - 1] = arguments[_key];
7
- }
8
- var result = rest.reduce(function (acc, value) {
9
- return acc + toNumber(value || 0);
10
- }, toNumber(first || 0));
11
- if (isNaN(result)) {
12
- throw Error(ERROR_VALUE);
13
- }
14
- return result;
15
- }
16
- func.SYMBOL = SYMBOL;
@@ -1,10 +0,0 @@
1
- export var SYMBOL = '&';
2
- export default function func() {
3
- for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
4
- params[_key] = arguments[_key];
5
- }
6
- return params.reduce(function (acc, value) {
7
- return acc + value.toString();
8
- }, '');
9
- }
10
- func.SYMBOL = SYMBOL;
@@ -1,21 +0,0 @@
1
- import { toNumber } from './../../helper/number';
2
- import { ERROR_DIV_ZERO, ERROR_VALUE } from './../../error';
3
- export var SYMBOL = '/';
4
- export default function func(first) {
5
- for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
6
- rest[_key - 1] = arguments[_key];
7
- }
8
- var result = rest.reduce(function (acc, value) {
9
- return acc / toNumber(value);
10
- }, toNumber(first));
11
- if (result === Infinity) {
12
- return ERROR_DIV_ZERO;
13
- // throw Error(ERROR_DIV_ZERO);
14
- }
15
- if (isNaN(result)) {
16
- return ERROR_VALUE;
17
- // throw Error(ERROR_VALUE);
18
- }
19
- return result;
20
- }
21
- func.SYMBOL = SYMBOL;
@@ -1,5 +0,0 @@
1
- export var SYMBOL = '=';
2
- export default function func(exp1, exp2) {
3
- return exp1 === exp2;
4
- }
5
- func.SYMBOL = SYMBOL;
@@ -1,40 +0,0 @@
1
- import * as formulajs from '@formulajs/formulajs';
2
- import SUPPORTED_FORMULAS from './../../supported-formulas';
3
- import { ERROR_NAME } from './../../error';
4
- export var SYMBOL = SUPPORTED_FORMULAS;
5
- export default function func(symbol) {
6
- return function __formulaFunction() {
7
- symbol = symbol.toUpperCase();
8
- var symbolParts = symbol.split('.');
9
- var foundFormula = false;
10
- var result;
11
- if (symbolParts.length === 1) {
12
- if (formulajs[symbolParts[0]]) {
13
- foundFormula = true;
14
- result = formulajs[symbolParts[0]].apply(formulajs, arguments);
15
- }
16
- } else {
17
- var length = symbolParts.length;
18
- var index = 0;
19
- var nestedFormula = formulajs;
20
- while (index < length) {
21
- nestedFormula = nestedFormula[symbolParts[index]];
22
- index++;
23
- if (!nestedFormula) {
24
- nestedFormula = null;
25
- break;
26
- }
27
- }
28
- if (nestedFormula) {
29
- foundFormula = true;
30
- result = nestedFormula.apply(void 0, arguments);
31
- }
32
- }
33
- if (!foundFormula) {
34
- throw Error(ERROR_NAME);
35
- }
36
- return result;
37
- };
38
- }
39
- func.isFactory = true;
40
- func.SYMBOL = SYMBOL;
@@ -1,5 +0,0 @@
1
- export var SYMBOL = '>=';
2
- export default function func(exp1, exp2) {
3
- return exp1 >= exp2;
4
- }
5
- func.SYMBOL = SYMBOL;
@@ -1,5 +0,0 @@
1
- export var SYMBOL = '>';
2
- export default function func(exp1, exp2) {
3
- return exp1 > exp2;
4
- }
5
- func.SYMBOL = SYMBOL;
@@ -1,5 +0,0 @@
1
- export var SYMBOL = '<=';
2
- export default function func(exp1, exp2) {
3
- return exp1 <= exp2;
4
- }
5
- func.SYMBOL = SYMBOL;
@@ -1,5 +0,0 @@
1
- export var SYMBOL = '<';
2
- export default function func(exp1, exp2) {
3
- return exp1 < exp2;
4
- }
5
- func.SYMBOL = SYMBOL;
@@ -1,16 +0,0 @@
1
- import { toNumber } from './../../helper/number';
2
- import { ERROR_VALUE } from './../../error';
3
- export var SYMBOL = '-';
4
- export default function func(first) {
5
- for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
6
- rest[_key - 1] = arguments[_key];
7
- }
8
- var result = rest.reduce(function (acc, value) {
9
- return acc - toNumber(value);
10
- }, toNumber(first));
11
- if (isNaN(result)) {
12
- throw Error(ERROR_VALUE);
13
- }
14
- return result;
15
- }
16
- func.SYMBOL = SYMBOL;
@@ -1,16 +0,0 @@
1
- import { toNumber } from './../../helper/number';
2
- import { ERROR_VALUE } from './../../error';
3
- export var SYMBOL = '*';
4
- export default function func(first) {
5
- for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
6
- rest[_key - 1] = arguments[_key];
7
- }
8
- var result = rest.reduce(function (acc, value) {
9
- return acc * toNumber(value);
10
- }, toNumber(first));
11
- if (isNaN(result)) {
12
- throw Error(ERROR_VALUE);
13
- }
14
- return result;
15
- }
16
- func.SYMBOL = SYMBOL;
@@ -1,5 +0,0 @@
1
- export var SYMBOL = '<>';
2
- export default function func(exp1, exp2) {
3
- return exp1 !== exp2;
4
- }
5
- func.SYMBOL = SYMBOL;
@@ -1,11 +0,0 @@
1
- import { toNumber } from './../../helper/number';
2
- import { ERROR_VALUE } from './../../error';
3
- export var SYMBOL = '^';
4
- export default function func(exp1, exp2) {
5
- var result = Math.pow(toNumber(exp1), toNumber(exp2));
6
- if (isNaN(result)) {
7
- throw Error(ERROR_VALUE);
8
- }
9
- return result;
10
- }
11
- func.SYMBOL = SYMBOL;
@@ -1,230 +0,0 @@
1
- /* description: Parses end evaluates mathematical expressions. */
2
- /* lexical grammar */
3
- %lex
4
- %%
5
- \s+ {/* skip whitespace */}
6
- '"'("\\"["]|[^"])*'"' {return 'STRING';}
7
- "'"('\\'[']|[^'])*"'" {return 'STRING';}
8
- [A-Za-z]{1,}[A-Za-z_0-9\.]+(?=[(]) {return 'FUNCTION';}
9
- '#'[A-Z0-9\/]+('!'|'?')? {return 'ERROR';}
10
- '$'[A-Za-z]+'$'[0-9]+ {return 'ABSOLUTE_CELL';}
11
- '$'[A-Za-z]+[0-9]+ {return 'MIXED_CELL';}
12
- [A-Za-z]+'$'[0-9]+ {return 'MIXED_CELL';}
13
- [A-Za-z]+[0-9]+ {return 'RELATIVE_CELL';}
14
- [A-Za-z\.]+(?=[(]) {return 'FUNCTION';}
15
- [A-Za-z]{1,}[A-Za-z_0-9]+ {return 'VARIABLE';}
16
- [A-Za-z_]+ {return 'VARIABLE';}
17
- [0-9]+ {return 'NUMBER';}
18
- '['(.*)?']' {return 'ARRAY';}
19
- "&" {return '&';}
20
- " " {return ' ';}
21
- [.] {return 'DECIMAL';}
22
- ":" {return ':';}
23
- ";" {return ';';}
24
- "," {return ',';}
25
- "*" {return '*';}
26
- "/" {return '/';}
27
- "-" {return '-';}
28
- "+" {return '+';}
29
- "^" {return '^';}
30
- "(" {return '(';}
31
- ")" {return ')';}
32
- ">" {return '>';}
33
- "<" {return '<';}
34
- "NOT" {return 'NOT';}
35
- '"' {return '"';}
36
- "'" {return "'";}
37
- "!" {return "!";}
38
- "=" {return '=';}
39
- "%" {return '%';}
40
- [#] {return '#';}
41
- <<EOF>> {return 'EOF';}
42
- /lex
43
-
44
- /* operator associations and precedence (low-top, high-bottom) */
45
- %left '='
46
- %left '<=' '>=' '<>' 'NOT' '||'
47
- %left '>' '<'
48
- %left '+' '-'
49
- %left '*' '/'
50
- %left '^'
51
- %left '&'
52
- %left '%'
53
- %left UMINUS
54
-
55
- %start expressions
56
-
57
- %% /* language grammar */
58
-
59
- expressions
60
- : expression EOF {
61
- return $1;
62
- }
63
- ;
64
-
65
- expression
66
- : variableSequence {
67
- $$ = yy.callVariable($1[0]);
68
- }
69
- | number {
70
- $$ = yy.toNumber($1);
71
- }
72
- | STRING {
73
- $$ = yy.trimEdges($1);
74
- }
75
- | expression '&' expression {
76
- $$ = yy.evaluateByOperator('&', [$1, $3]);
77
- }
78
- | expression '=' expression {
79
- $$ = yy.evaluateByOperator('=', [$1, $3]);
80
- }
81
- | expression '+' expression {
82
- $$ = yy.evaluateByOperator('+', [$1, $3]);
83
- }
84
- | '(' expression ')' {
85
- $$ = $2;
86
- }
87
- | expression '<' '=' expression {
88
- $$ = yy.evaluateByOperator('<=', [$1, $4]);
89
- }
90
- | expression '>' '=' expression {
91
- $$ = yy.evaluateByOperator('>=', [$1, $4]);
92
- }
93
- | expression '<' '>' expression {
94
- $$ = yy.evaluateByOperator('<>', [$1, $4]);
95
- }
96
- | expression NOT expression {
97
- $$ = yy.evaluateByOperator('NOT', [$1, $3]);
98
- }
99
- | expression '>' expression {
100
- $$ = yy.evaluateByOperator('>', [$1, $3]);
101
- }
102
- | expression '<' expression {
103
- $$ = yy.evaluateByOperator('<', [$1, $3]);
104
- }
105
- | expression '-' expression {
106
- $$ = yy.evaluateByOperator('-', [$1, $3]);
107
- }
108
- | expression '*' expression {
109
- $$ = yy.evaluateByOperator('*', [$1, $3]);
110
- }
111
- | expression '/' expression {
112
- $$ = yy.evaluateByOperator('/', [$1, $3]);
113
- }
114
- | expression '^' expression {
115
- $$ = yy.evaluateByOperator('^', [$1, $3]);
116
- }
117
- | '-' expression {
118
- var n1 = yy.invertNumber($2);
119
-
120
- $$ = n1;
121
-
122
- if (isNaN($$)) {
123
- $$ = 0;
124
- }
125
- }
126
- | '+' expression {
127
- var n1 = yy.toNumber($2);
128
-
129
- $$ = n1;
130
-
131
- if (isNaN($$)) {
132
- $$ = 0;
133
- }
134
- }
135
- | FUNCTION '(' ')' {
136
- $$ = yy.callFunction($1);
137
- }
138
- | FUNCTION '(' expseq ')' {
139
- $$ = yy.callFunction($1, $3);
140
- }
141
- | cell
142
- | error
143
- | error error
144
- ;
145
-
146
- cell
147
- : ABSOLUTE_CELL {
148
- $$ = yy.cellValue($1);
149
- }
150
- | RELATIVE_CELL {
151
- $$ = yy.cellValue($1);
152
- }
153
- | MIXED_CELL {
154
- $$ = yy.cellValue($1);
155
- }
156
- | ABSOLUTE_CELL ':' ABSOLUTE_CELL {
157
- $$ = yy.rangeValue($1, $3);
158
- }
159
- | ABSOLUTE_CELL ':' RELATIVE_CELL {
160
- $$ = yy.rangeValue($1, $3);
161
- }
162
- | ABSOLUTE_CELL ':' MIXED_CELL {
163
- $$ = yy.rangeValue($1, $3);
164
- }
165
- | RELATIVE_CELL ':' ABSOLUTE_CELL {
166
- $$ = yy.rangeValue($1, $3);
167
- }
168
- | RELATIVE_CELL ':' RELATIVE_CELL {
169
- $$ = yy.rangeValue($1, $3);
170
- }
171
- | RELATIVE_CELL ':' MIXED_CELL {
172
- $$ = yy.rangeValue($1, $3);
173
- }
174
- | MIXED_CELL ':' ABSOLUTE_CELL {
175
- $$ = yy.rangeValue($1, $3);
176
- }
177
- | MIXED_CELL ':' RELATIVE_CELL {
178
- $$ = yy.rangeValue($1, $3);
179
- }
180
- | MIXED_CELL ':' MIXED_CELL {
181
- $$ = yy.rangeValue($1, $3);
182
- }
183
- ;
184
-
185
- expseq
186
- : expression {
187
- $$ = [$1];
188
- }
189
- | ARRAY {
190
- $$ = yy.trimEdges(yytext).split(',');
191
- }
192
- | expseq ';' expression {
193
- $1.push($3);
194
- $$ = $1;
195
- }
196
- | expseq ',' expression {
197
- $1.push($3);
198
- $$ = $1;
199
- }
200
- ;
201
-
202
- variableSequence
203
- : VARIABLE {
204
- $$ = [$1];
205
- }
206
- | variableSequence DECIMAL VARIABLE {
207
- $$ = (Array.isArray($1) ? $1 : [$1]);
208
- $$.push($3);
209
- }
210
- ;
211
-
212
- number
213
- : NUMBER {
214
- $$ = $1;
215
- }
216
- | NUMBER DECIMAL NUMBER {
217
- $$ = ($1 + '.' + $3) * 1;
218
- }
219
- | number '%' {
220
- $$ = $1 * 0.01;
221
- }
222
- ;
223
-
224
- error
225
- : ERROR {
226
- $$ = yy.throwError($1);
227
- }
228
- ;
229
-
230
- %%