@evergis/condition
Advanced tools
Comparing version 1.2.4 to 1.2.5
@@ -5,2 +5,4 @@ 'use strict'; | ||
var dateFns = require('date-fns'); | ||
function _classCallCheck(instance, Constructor) { | ||
@@ -25,5 +27,26 @@ if (!(instance instanceof Constructor)) { | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inherits(subClass, superClass) { | ||
@@ -41,2 +64,5 @@ if (typeof superClass !== "function" && superClass !== null) { | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
@@ -67,3 +93,3 @@ } | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
@@ -141,2 +167,4 @@ } catch (e) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
@@ -175,3 +203,3 @@ | ||
function _get(target, property, receiver) { | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
@@ -187,3 +215,3 @@ _get = Reflect.get; | ||
if (desc.get) { | ||
return desc.get.call(receiver); | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
@@ -195,47 +223,5 @@ | ||
return _get(target, property, receiver || target); | ||
return _get.apply(this, arguments); | ||
} | ||
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); | ||
} | ||
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; | ||
} | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { | ||
var it; | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
return function () { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
it = o[Symbol.iterator](); | ||
return it.next.bind(it); | ||
} | ||
(function (TokenType) { | ||
@@ -271,9 +257,11 @@ TokenType[TokenType["Number"] = 0] = "Number"; | ||
TokenType[TokenType["Function"] = 28] = "Function"; | ||
TokenType[TokenType["Between"] = 29] = "Between"; | ||
TokenType[TokenType["Outside"] = 30] = "Outside"; | ||
})(exports.TokenType || (exports.TokenType = {})); | ||
var DEFAULT_TOKEN_POSITION = { | ||
const DEFAULT_TOKEN_POSITION = { | ||
start: 0, | ||
end: 0 | ||
}; | ||
var Token = function Token(type, value, position) { | ||
let Token = /*#__PURE__*/_createClass(function Token(type, value, position) { | ||
if (position === void 0) { | ||
@@ -288,5 +276,5 @@ position = DEFAULT_TOKEN_POSITION; | ||
this.position = position; | ||
}; | ||
}); | ||
var ExpressionNode = /*#__PURE__*/function () { | ||
let ExpressionNode = /*#__PURE__*/function () { | ||
function ExpressionNode(token, left, right) { | ||
@@ -320,3 +308,3 @@ if (left === void 0) { | ||
}(); | ||
var ValueNode = /*#__PURE__*/function (_ExpressionNode) { | ||
let ValueNode = /*#__PURE__*/function (_ExpressionNode) { | ||
_inherits(ValueNode, _ExpressionNode); | ||
@@ -342,3 +330,3 @@ | ||
ValueNode.TOKENS = [exports.TokenType.String, exports.TokenType.Number, exports.TokenType.DynamicIdentifier, exports.TokenType.Date]; | ||
var AttributeNode = /*#__PURE__*/function (_ExpressionNode2) { | ||
let AttributeNode = /*#__PURE__*/function (_ExpressionNode2) { | ||
_inherits(AttributeNode, _ExpressionNode2); | ||
@@ -364,3 +352,3 @@ | ||
AttributeNode.TOKENS = [exports.TokenType.Identifier]; | ||
var OperationNode = /*#__PURE__*/function (_ExpressionNode3) { | ||
let OperationNode = /*#__PURE__*/function (_ExpressionNode3) { | ||
_inherits(OperationNode, _ExpressionNode3); | ||
@@ -385,4 +373,4 @@ | ||
}(ExpressionNode); | ||
OperationNode.TOKENS = [exports.TokenType.ArEq, exports.TokenType.ArNotEq, exports.TokenType.ArGr, exports.TokenType.ArGre, exports.TokenType.ArLs, exports.TokenType.ArLse, exports.TokenType.ArPlus, exports.TokenType.ArMinus, exports.TokenType.ArDiv, exports.TokenType.ArMul]; | ||
var BoolOperationNode = /*#__PURE__*/function (_ExpressionNode4) { | ||
OperationNode.TOKENS = [exports.TokenType.ArEq, exports.TokenType.ArNotEq, exports.TokenType.ArGr, exports.TokenType.ArGre, exports.TokenType.ArLs, exports.TokenType.ArLse, exports.TokenType.ArPlus, exports.TokenType.ArMinus, exports.TokenType.ArDiv, exports.TokenType.ArMul, exports.TokenType.Between, exports.TokenType.Outside]; | ||
let BoolOperationNode = /*#__PURE__*/function (_ExpressionNode4) { | ||
_inherits(BoolOperationNode, _ExpressionNode4); | ||
@@ -408,3 +396,3 @@ | ||
BoolOperationNode.TOKENS = [exports.TokenType.BoolAnd, exports.TokenType.BoolOr]; | ||
var FunctionNode = /*#__PURE__*/function (_ExpressionNode5) { | ||
let FunctionNode = /*#__PURE__*/function (_ExpressionNode5) { | ||
_inherits(FunctionNode, _ExpressionNode5); | ||
@@ -443,3 +431,3 @@ | ||
var OperationPrecedence = /*#__PURE__*/new Map(); | ||
const OperationPrecedence = /*#__PURE__*/new Map(); | ||
OperationPrecedence.set(exports.TokenType.ExprOpen, 0); | ||
@@ -460,4 +448,6 @@ OperationPrecedence.set(exports.TokenType.ExprClose, 0); | ||
OperationPrecedence.set(exports.TokenType.Function, 5); | ||
OperationPrecedence.set(exports.TokenType.Between, 5); | ||
OperationPrecedence.set(exports.TokenType.Outside, 5); | ||
var TokenError = /*#__PURE__*/function (_Error) { | ||
let TokenError = /*#__PURE__*/function (_Error) { | ||
_inherits(TokenError, _Error); | ||
@@ -478,5 +468,6 @@ | ||
_this.position = position; | ||
var _position = position, | ||
start = _position.start, | ||
end = _position.end; | ||
const { | ||
start, | ||
end | ||
} = position; | ||
_this.message = _this.name + "(c\u0438\u043C\u0432\u043E\u043B: " + (start + 1) + ", " + (end + 1) + "):" + message + "."; | ||
@@ -486,6 +477,6 @@ return _this; | ||
return TokenError; | ||
return _createClass(TokenError); | ||
}( /*#__PURE__*/_wrapNativeSuper(Error)); | ||
var LintError = /*#__PURE__*/function (_TokenError) { | ||
let LintError = /*#__PURE__*/function (_TokenError) { | ||
_inherits(LintError, _TokenError); | ||
@@ -510,20 +501,12 @@ | ||
return LintError; | ||
return _createClass(LintError); | ||
}(TokenError); | ||
var last = function last(el) { | ||
return el[el.length - 1]; | ||
}; | ||
const last = el => el[el.length - 1]; | ||
var isOperand = function isOperand(token) { | ||
return ValueNode.is(token) || AttributeNode.is(token); | ||
}; | ||
const isOperand = token => ValueNode.is(token) || AttributeNode.is(token); | ||
var isOperation = function isOperation(token) { | ||
return OperationNode.is(token) || BoolOperationNode.is(token) || FunctionNode.is(token); | ||
}; | ||
const isOperation = token => OperationNode.is(token) || BoolOperationNode.is(token) || FunctionNode.is(token); | ||
var isHigherPrecedence = function isHigherPrecedence(tokenOne, tokenTwo) { | ||
return OperationPrecedence.get(tokenOne.type) > OperationPrecedence.get(tokenTwo.type); | ||
}; // TODO parentheses | ||
const isHigherPrecedence = (tokenOne, tokenTwo) => OperationPrecedence.get(tokenOne.type) > OperationPrecedence.get(tokenTwo.type); // TODO parentheses | ||
@@ -536,8 +519,6 @@ /* | ||
function shuntingYard(tokens) { | ||
var output = []; | ||
var operators = []; | ||
let output = []; | ||
const operators = []; | ||
for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) { | ||
var token = _step.value; | ||
for (const token of tokens) { | ||
if (isOperand(token)) { | ||
@@ -548,4 +529,6 @@ output.push(token); | ||
if (isOperation(token)) { | ||
while (last(operators) && isHigherPrecedence(last(operators), token) && last(operators).type !== exports.TokenType.ExprOpen) { | ||
output.push(operators.pop()); | ||
if (![exports.TokenType.Between, exports.TokenType.Outside].includes(token.type)) { | ||
while (last(operators) && isHigherPrecedence(last(operators), token) && last(operators).type !== exports.TokenType.ExprOpen) { | ||
output.push(operators.pop()); | ||
} | ||
} | ||
@@ -561,3 +544,3 @@ | ||
if (token.type === exports.TokenType.ExprClose) { | ||
var closeParen = token; | ||
const closeParen = token; | ||
@@ -579,3 +562,3 @@ while (last(operators) && last(operators).type !== exports.TokenType.ExprOpen) { | ||
if (operators.length) { | ||
var lastToken = last(operators); | ||
const lastToken = last(operators); | ||
@@ -586,3 +569,3 @@ if (lastToken.type === exports.TokenType.ExprOpen) { | ||
output = [].concat(output, operators.reverse()); | ||
output = [...output, ...operators.reverse()]; | ||
} | ||
@@ -593,3 +576,3 @@ | ||
var ExpressionAstError = /*#__PURE__*/function (_TokenError) { | ||
let ExpressionAstError = /*#__PURE__*/function (_TokenError) { | ||
_inherits(ExpressionAstError, _TokenError); | ||
@@ -614,6 +597,6 @@ | ||
return ExpressionAstError; | ||
return _createClass(ExpressionAstError); | ||
}(TokenError); | ||
var ExpressionVisitor = /*#__PURE__*/function () { | ||
let ExpressionVisitor = /*#__PURE__*/function () { | ||
function ExpressionVisitor() { | ||
@@ -666,3 +649,3 @@ _classCallCheck(this, ExpressionVisitor); | ||
var LintVisitor = /*#__PURE__*/function (_ExpressionVisitor) { | ||
let LintVisitor = /*#__PURE__*/function (_ExpressionVisitor) { | ||
_inherits(LintVisitor, _ExpressionVisitor); | ||
@@ -725,3 +708,3 @@ | ||
value: function checkBoolOpNode(node) { | ||
var message = "\u041E\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044F \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u0435 \u0432\u0438\u0434\u0430 'a == 2 " + node.token.value + " b == 3'"; | ||
const message = "\u041E\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044F \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u0435 \u0432\u0438\u0434\u0430 'a == 2 " + node.token.value + " b == 3'"; | ||
@@ -747,3 +730,5 @@ if (!this.isOperationNode(node.left)) { | ||
if (node.left) { | ||
var token = node.left.token; | ||
const { | ||
token | ||
} = node.left; | ||
this.Error("'" + token.value + "' \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0435 \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u044F", token); | ||
@@ -753,4 +738,6 @@ } | ||
if (node.right) { | ||
var _token = node.right.token; | ||
this.Error("'" + _token.value + "' \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0435 \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u044F", _token); | ||
const { | ||
token | ||
} = node.right; | ||
this.Error("'" + token.value + "' \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0435 \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u044F", token); | ||
} | ||
@@ -768,3 +755,3 @@ } | ||
value: function checkFunctionNode(node) { | ||
var result = node.func.check(this.attributes); | ||
const result = node.func.check(this.attributes); | ||
@@ -778,3 +765,5 @@ if (result instanceof Error) { | ||
value: function Error(description, token) { | ||
var position = token.position; | ||
const { | ||
position | ||
} = token; | ||
throw new LintError(description, position); | ||
@@ -785,7 +774,7 @@ } | ||
value: function acceptLeafs(node) { | ||
var x = node.left && node.left.accept(this); | ||
var y = node.right && node.right.accept(this); | ||
const x = node.left && node.left.accept(this); | ||
const y = node.right && node.right.accept(this); | ||
return { | ||
x: x, | ||
y: y | ||
x, | ||
y | ||
}; | ||
@@ -803,3 +792,3 @@ } | ||
var EvaluateVisitor = /*#__PURE__*/function (_LintVisitor) { | ||
let EvaluateVisitor = /*#__PURE__*/function (_LintVisitor) { | ||
_inherits(EvaluateVisitor, _LintVisitor); | ||
@@ -827,6 +816,6 @@ | ||
var _this$acceptLeafs = this.acceptLeafs(node), | ||
x = _this$acceptLeafs.x, | ||
y = _this$acceptLeafs.y; | ||
const { | ||
x, | ||
y | ||
} = this.acceptLeafs(node); | ||
return node.token.type === exports.TokenType.BoolAnd ? x && y : x || y; | ||
@@ -841,5 +830,6 @@ } | ||
var _this$acceptLeafs2 = this.acceptLeafs(node), | ||
x = _this$acceptLeafs2.x, | ||
y = _this$acceptLeafs2.y; | ||
const { | ||
x, | ||
y | ||
} = this.acceptLeafs(node); | ||
@@ -913,3 +903,3 @@ switch (node.token.type) { | ||
var EqlFunction = /*#__PURE__*/function () { | ||
let EqlFunction = /*#__PURE__*/function () { | ||
function EqlFunction(args) { | ||
@@ -930,3 +920,3 @@ _classCallCheck(this, EqlFunction); | ||
value: function evaluateArguments(attributes) { | ||
return this.args.map(function (arg) { | ||
return this.args.map(arg => { | ||
if (arg instanceof OperationNode) { | ||
@@ -937,6 +927,8 @@ return arg.accept(new EvaluateVisitor(attributes)); | ||
if (typeof arg.value === 'string') { | ||
var value = attributes[arg.value]; | ||
const value = attributes[arg.value]; | ||
if (typeof value !== 'number') { | ||
var position = arg.position; | ||
const { | ||
position | ||
} = arg; | ||
throw new LintError('Аргумент функции должен быть числовым типом', position); | ||
@@ -954,3 +946,3 @@ } | ||
value: function check(attributes, argsCount) { | ||
var args = this.evaluateArguments(attributes); | ||
const args = this.evaluateArguments(attributes); | ||
@@ -968,3 +960,3 @@ if (args.length !== argsCount) { | ||
var Sin = /*#__PURE__*/function (_EqlFunction) { | ||
let Sin = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(Sin, _EqlFunction); | ||
@@ -983,4 +975,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(Sin.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(Sin.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1001,3 +992,3 @@ return +Math.sin(arg).toFixed(3); | ||
var ArcSin = /*#__PURE__*/function (_EqlFunction) { | ||
let ArcSin = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(ArcSin, _EqlFunction); | ||
@@ -1016,4 +1007,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(ArcSin.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(ArcSin.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1034,3 +1024,3 @@ return +Math.asin(arg).toFixed(3); | ||
var Cos = /*#__PURE__*/function (_EqlFunction) { | ||
let Cos = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(Cos, _EqlFunction); | ||
@@ -1049,4 +1039,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(Cos.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(Cos.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1067,3 +1056,3 @@ return +Math.cos(arg).toFixed(3); | ||
var ArcCos = /*#__PURE__*/function (_EqlFunction) { | ||
let ArcCos = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(ArcCos, _EqlFunction); | ||
@@ -1082,4 +1071,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(ArcCos.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(ArcCos.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1100,3 +1088,3 @@ return +Math.acos(arg).toFixed(3); | ||
var ArcTan2 = /*#__PURE__*/function (_EqlFunction) { | ||
let ArcTan2 = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(ArcTan2, _EqlFunction); | ||
@@ -1115,5 +1103,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(ArcTan2.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg1 = _get$call[0], | ||
arg2 = _get$call[1]; | ||
const [arg1, arg2] = _get(_getPrototypeOf(ArcTan2.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1134,3 +1120,3 @@ return +Math.atan2(arg1, arg2).toFixed(3); | ||
var Tan = /*#__PURE__*/function (_EqlFunction) { | ||
let Tan = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(Tan, _EqlFunction); | ||
@@ -1149,4 +1135,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(Tan.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(Tan.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1167,3 +1152,3 @@ return +Math.tan(arg).toFixed(3); | ||
var ArcTan = /*#__PURE__*/function (_EqlFunction) { | ||
let ArcTan = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(ArcTan, _EqlFunction); | ||
@@ -1182,4 +1167,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(ArcTan.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(ArcTan.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1200,3 +1184,3 @@ return +Math.atan(arg).toFixed(3); | ||
var Sqrt = /*#__PURE__*/function (_EqlFunction) { | ||
let Sqrt = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(Sqrt, _EqlFunction); | ||
@@ -1215,4 +1199,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(Sqrt.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(Sqrt.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1233,6 +1216,16 @@ return +Math.sqrt(arg).toFixed(3); | ||
var _EqlFunctions; | ||
var EqlFunctions = (_EqlFunctions = {}, _EqlFunctions[Sin.Name] = Sin, _EqlFunctions[ArcSin.Name] = ArcSin, _EqlFunctions[Cos.Name] = Cos, _EqlFunctions[ArcCos.Name] = ArcCos, _EqlFunctions[Tan.Name] = Tan, _EqlFunctions[ArcTan.Name] = ArcTan, _EqlFunctions[ArcTan2.Name] = ArcTan2, _EqlFunctions[Sqrt.Name] = Sqrt, _EqlFunctions); | ||
const EqlFunctions = { | ||
[Sin.Name]: Sin, | ||
[ArcSin.Name]: ArcSin, | ||
[Cos.Name]: Cos, | ||
[ArcCos.Name]: ArcCos, | ||
[Tan.Name]: Tan, | ||
[ArcTan.Name]: ArcTan, | ||
[ArcTan2.Name]: ArcTan2, | ||
[Sqrt.Name]: Sqrt | ||
}; | ||
var ExpressionAst = /*#__PURE__*/function () { | ||
const formatValue = value => !dateFns.isValid(value) ? "#'" + value + "'" : value; | ||
let ExpressionAst = /*#__PURE__*/function () { | ||
function ExpressionAst(tokens) { | ||
@@ -1249,51 +1242,2 @@ _classCallCheck(this, ExpressionAst); | ||
_createClass(ExpressionAst, [{ | ||
key: "nextToken", | ||
value: function nextToken() { | ||
this.currentPosition += 1; | ||
} // @ts-ignore | ||
}, { | ||
key: "checkRoot", | ||
value: function checkRoot() { | ||
if (!this.tree) { | ||
return; | ||
} | ||
} | ||
}, { | ||
key: "flashStack", | ||
value: function flashStack(stack) { | ||
if (!this.tree || !stack.length) { | ||
return; | ||
} | ||
while (stack.length) { | ||
var node = stack.pop(); | ||
if (node) { | ||
this.insert(this.tree, node); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "insert", | ||
value: function insert(tree, node) { | ||
if (tree.right === null) { | ||
tree.right = node; | ||
return; | ||
} else { | ||
this.insert(tree.right, node); | ||
} | ||
} | ||
}, { | ||
key: "Error", | ||
value: function Error(description, token) { | ||
var position = token.position; | ||
var start = position.start, | ||
end = position.end; | ||
throw new ExpressionAstError(description, { | ||
start: start, | ||
end: end | ||
}); | ||
} | ||
}, { | ||
key: "value", | ||
@@ -1306,3 +1250,3 @@ get: function get() { | ||
this.tokens = shuntingYard(this.tokens); | ||
var stack = []; | ||
const stack = []; | ||
@@ -1319,3 +1263,3 @@ for (; this.currentPosition < this.tokens.length; this.nextToken()) { | ||
if (FunctionNode.is(this.currentToken)) { | ||
var FnConstructor = EqlFunctions[this.currentToken.value]; | ||
const FnConstructor = EqlFunctions[this.currentToken.value]; | ||
@@ -1326,6 +1270,6 @@ if (!FnConstructor) { | ||
var args = []; | ||
const args = []; | ||
for (var i = 0; i < FnConstructor.ArgsCount; i++) { | ||
var node = stack.pop() || null; | ||
for (let i = 0; i < FnConstructor.ArgsCount; i++) { | ||
const node = stack.pop() || null; | ||
@@ -1340,3 +1284,3 @@ if (node instanceof OperationNode) { | ||
var fn = new FnConstructor(args); | ||
const fn = new FnConstructor(args); | ||
stack.push(new FunctionNode(this.currentToken, fn)); | ||
@@ -1346,21 +1290,37 @@ } | ||
if (OperationNode.is(this.currentToken)) { | ||
var _node = new OperationNode(this.currentToken); | ||
const node = new OperationNode(this.currentToken); | ||
if (stack.length > 1) { | ||
_node.right = stack.pop() || null; | ||
if ([exports.TokenType.Between, exports.TokenType.Outside].includes(this.currentToken.type)) { | ||
var _value1$token$positio, _value2$token$positio; | ||
const value2 = stack.pop() || null; | ||
const value1 = stack.pop() || null; | ||
node.left = stack.pop() || null; | ||
node.right = new ValueNode(_extends({}, this.currentToken, { | ||
value: formatValue(value1 == null ? void 0 : value1.token.value) + " - " + formatValue(value2 == null ? void 0 : value2.token.value), | ||
position: { | ||
start: (value1 == null ? void 0 : (_value1$token$positio = value1.token.position) == null ? void 0 : _value1$token$positio.start) || 0, | ||
end: (value2 == null ? void 0 : (_value2$token$positio = value2.token.position) == null ? void 0 : _value2$token$positio.end) || 0 | ||
} | ||
})); | ||
} else { | ||
if (stack.length > 1) { | ||
node.right = stack.pop() || null; | ||
} | ||
node.left = stack.pop() || null; | ||
} | ||
_node.left = stack.pop() || null; | ||
stack.push(_node); | ||
stack.push(node); | ||
} | ||
if (BoolOperationNode.is(this.currentToken)) { | ||
var _node2 = new BoolOperationNode(this.currentToken); | ||
const node = new BoolOperationNode(this.currentToken); | ||
if (stack.length > 1) { | ||
_node2.right = stack.pop() || null; | ||
node.right = stack.pop() || null; | ||
} | ||
_node2.left = stack.pop() || null; | ||
stack.push(_node2); | ||
node.left = stack.pop() || null; | ||
stack.push(node); | ||
} | ||
@@ -1375,2 +1335,8 @@ } | ||
}, { | ||
key: "nextToken", | ||
value: function nextToken() { | ||
this.currentPosition += 1; | ||
} // @ts-ignore | ||
}, { | ||
key: "currentToken", | ||
@@ -1380,2 +1346,49 @@ get: function get() { | ||
} | ||
}, { | ||
key: "checkRoot", | ||
value: function checkRoot() { | ||
if (!this.tree) { | ||
return; | ||
} | ||
} | ||
}, { | ||
key: "flashStack", | ||
value: function flashStack(stack) { | ||
if (!this.tree || !stack.length) { | ||
return; | ||
} | ||
while (stack.length) { | ||
const node = stack.pop(); | ||
if (node) { | ||
this.insert(this.tree, node); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "insert", | ||
value: function insert(tree, node) { | ||
if (tree.right === null) { | ||
tree.right = node; | ||
return; | ||
} else { | ||
this.insert(tree.right, node); | ||
} | ||
} | ||
}, { | ||
key: "Error", | ||
value: function Error(description, token) { | ||
const { | ||
position | ||
} = token; | ||
const { | ||
start, | ||
end | ||
} = position; | ||
throw new ExpressionAstError(description, { | ||
start, | ||
end | ||
}); | ||
} | ||
}]); | ||
@@ -1386,3 +1399,3 @@ | ||
var ExpressionTokenizerError = /*#__PURE__*/function (_TokenError) { | ||
let ExpressionTokenizerError = /*#__PURE__*/function (_TokenError) { | ||
_inherits(ExpressionTokenizerError, _TokenError); | ||
@@ -1407,9 +1420,7 @@ | ||
return ExpressionTokenizerError; | ||
return _createClass(ExpressionTokenizerError); | ||
}(TokenError); | ||
var OperationAccept = /*#__PURE__*/function () { | ||
let OperationAccept = /*#__PURE__*/function () { | ||
function OperationAccept(value, type, operations) { | ||
var _this = this; | ||
if (operations === void 0) { | ||
@@ -1424,5 +1435,3 @@ operations = []; | ||
this.tokenType = type; | ||
operations.map(function (opAccept) { | ||
return _this.acceptMap.set(opAccept.value, opAccept); | ||
}); | ||
operations.map(opAccept => this.acceptMap.set(opAccept.value, opAccept)); | ||
} | ||
@@ -1440,5 +1449,3 @@ | ||
var AcceptTree = /*#__PURE__*/new OperationAccept('', exports.TokenType.Null, [/*#__PURE__*/new OperationAccept('>', exports.TokenType.ArGr, [/*#__PURE__*/new OperationAccept('=', exports.TokenType.ArGre)]), /*#__PURE__*/new OperationAccept('<', exports.TokenType.ArLs, [/*#__PURE__*/new OperationAccept('=', exports.TokenType.ArLse)]), /*#__PURE__*/new OperationAccept('!', exports.TokenType.BoolNot, [/*#__PURE__*/new OperationAccept('=', exports.TokenType.ArNotEq)]), /*#__PURE__*/new OperationAccept('&', exports.TokenType.Null, [/*#__PURE__*/new OperationAccept('&', exports.TokenType.BoolAnd)]), /*#__PURE__*/new OperationAccept('=', exports.TokenType.ArEq, [/*#__PURE__*/new OperationAccept('=', exports.TokenType.ArEq)]), /*#__PURE__*/new OperationAccept('|', exports.TokenType.Null, [/*#__PURE__*/new OperationAccept('|', exports.TokenType.BoolOr)]), /*#__PURE__*/new OperationAccept('+', exports.TokenType.ArPlus), /*#__PURE__*/new OperationAccept('-', exports.TokenType.ArMinus), /*#__PURE__*/new OperationAccept('*', exports.TokenType.ArMul), /*#__PURE__*/new OperationAccept('/', exports.TokenType.ArDiv), /*#__PURE__*/new OperationAccept('(', exports.TokenType.ExprOpen), /*#__PURE__*/new OperationAccept(')', exports.TokenType.ExprClose), /*#__PURE__*/new OperationAccept('[', exports.TokenType.ArrayOpen), /*#__PURE__*/new OperationAccept(']', exports.TokenType.ArrayClose), /*#__PURE__*/new OperationAccept(',', exports.TokenType.Separator)]); | ||
var Char = /*#__PURE__*/function () { | ||
let Char = /*#__PURE__*/function () { | ||
function Char() { | ||
@@ -1499,2 +1506,4 @@ _classCallCheck(this, Char); | ||
Char.OPEN_BRACKET = '('; | ||
Char.BETWEEN = 'between'; | ||
Char.OUTSIDE = '!between'; | ||
Char.SINGLE_QUOTE = "'"; | ||
@@ -1511,32 +1520,26 @@ Char.DOUBLE_QUOTE = '"'; | ||
var Time = function Time() { | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
} | ||
let Time = /*#__PURE__*/_createClass(function Time() { | ||
_classCallCheck(this, Time); | ||
}; | ||
}); | ||
Time.sToMs = function (seconds) { | ||
return seconds * 1000; | ||
}; | ||
Time.sToMs = seconds => seconds * 1000; | ||
Time.mToMs = function (minutes) { | ||
return Time.sToMs(minutes) * 60; | ||
}; | ||
Time.mToMs = minutes => Time.sToMs(minutes) * 60; | ||
Time.hToMs = function (hours) { | ||
return Time.mToMs(hours) * 60; | ||
}; | ||
Time.hToMs = hours => Time.mToMs(hours) * 60; | ||
Time.dToMs = function (days) { | ||
return Time.hToMs(days) * 24; | ||
}; | ||
Time.dToMs = days => Time.hToMs(days) * 24; | ||
Time.mthToMs = function (months) { | ||
return Time.dToMs(months) * 30; | ||
}; | ||
Time.mthToMs = months => Time.dToMs(months) * 30; | ||
Time.yToMs = function (years) { | ||
return Time.mthToMs(years) * 365; | ||
}; | ||
Time.yToMs = years => Time.mthToMs(years) * 365; | ||
var TOKENIZER_MAX_SIZE = 1000; | ||
var ExpressionTokenizer = /*#__PURE__*/function () { | ||
const AcceptTree = /*#__PURE__*/new OperationAccept('', exports.TokenType.Null, [/*#__PURE__*/new OperationAccept(Char.BETWEEN, exports.TokenType.Between), /*#__PURE__*/new OperationAccept(Char.OUTSIDE, exports.TokenType.Outside), /*#__PURE__*/new OperationAccept('>', exports.TokenType.ArGr, [/*#__PURE__*/new OperationAccept('=', exports.TokenType.ArGre)]), /*#__PURE__*/new OperationAccept('<', exports.TokenType.ArLs, [/*#__PURE__*/new OperationAccept('=', exports.TokenType.ArLse)]), /*#__PURE__*/new OperationAccept('!', exports.TokenType.BoolNot, [/*#__PURE__*/new OperationAccept('=', exports.TokenType.ArNotEq)]), /*#__PURE__*/new OperationAccept('&', exports.TokenType.Null, [/*#__PURE__*/new OperationAccept('&', exports.TokenType.BoolAnd)]), /*#__PURE__*/new OperationAccept('=', exports.TokenType.ArEq, [/*#__PURE__*/new OperationAccept('=', exports.TokenType.ArEq)]), /*#__PURE__*/new OperationAccept('|', exports.TokenType.Null, [/*#__PURE__*/new OperationAccept('|', exports.TokenType.BoolOr)]), /*#__PURE__*/new OperationAccept('+', exports.TokenType.ArPlus), /*#__PURE__*/new OperationAccept('-', exports.TokenType.ArMinus), /*#__PURE__*/new OperationAccept('*', exports.TokenType.ArMul), /*#__PURE__*/new OperationAccept('/', exports.TokenType.ArDiv), /*#__PURE__*/new OperationAccept('(', exports.TokenType.ExprOpen), /*#__PURE__*/new OperationAccept(')', exports.TokenType.ExprClose), /*#__PURE__*/new OperationAccept('[', exports.TokenType.ArrayOpen), /*#__PURE__*/new OperationAccept(']', exports.TokenType.ArrayClose), /*#__PURE__*/new OperationAccept(',', exports.TokenType.Separator)]); | ||
const TOKENIZER_MAX_SIZE = 1000; | ||
let ExpressionTokenizer = /*#__PURE__*/function () { | ||
function ExpressionTokenizer(input) { | ||
@@ -1559,3 +1562,3 @@ _classCallCheck(this, ExpressionTokenizer); | ||
while (true) { | ||
var token = this.nextToken(); | ||
const token = this.nextToken(); | ||
@@ -1588,4 +1591,15 @@ if (!token) { | ||
this.resetStart(); | ||
var acceptOp = AcceptTree.accept(this.current); | ||
if (this.input.slice(this.currentPosition).startsWith(Char.OUTSIDE)) { | ||
this.currentPosition += Char.OUTSIDE.length; | ||
return this.createToken(exports.TokenType.Outside, Char.OUTSIDE); | ||
} | ||
if (this.input.slice(this.currentPosition).startsWith(Char.BETWEEN)) { | ||
this.currentPosition += Char.BETWEEN.length; | ||
return this.createToken(exports.TokenType.Between, Char.BETWEEN); | ||
} | ||
const acceptOp = AcceptTree.accept(this.current); | ||
if (acceptOp !== null) { | ||
@@ -1634,6 +1648,6 @@ return this.captureSpecial(acceptOp); | ||
// TODO | ||
var end = this.currentPosition - (tokenType === exports.TokenType.EndOfString ? 0 : 1); | ||
const end = this.currentPosition - (tokenType === exports.TokenType.EndOfString ? 0 : 1); | ||
return new Token(tokenType, value, { | ||
start: this.start, | ||
end: end | ||
end | ||
}); | ||
@@ -1647,9 +1661,14 @@ } | ||
}, { | ||
key: "current", | ||
get: function get() { | ||
return this.input[this.currentPosition]; | ||
} | ||
}, { | ||
key: "captureSpecial", | ||
value: function captureSpecial(op) { | ||
var value = this.current; | ||
let value = this.current; | ||
this.nextSymbol(); | ||
for (; this.currentPosition < this.input.length; this.nextSymbol()) { | ||
var next = op.accept(this.current); | ||
const next = op.accept(this.current); | ||
@@ -1664,3 +1683,3 @@ if (next === null || next.tokenType === exports.TokenType.Null) { | ||
var isUnaryOp = this.current && Char.isDigit(this.current) && op.tokenType === exports.TokenType.ArMinus; // TODO change if unary operations will needed... why is that here? | ||
const isUnaryOp = this.current && Char.isDigit(this.current) && op.tokenType === exports.TokenType.ArMinus; // TODO change if unary operations will needed... why is that here? | ||
@@ -1680,7 +1699,7 @@ if (isUnaryOp) { | ||
value: function captureNumber() { | ||
var result = ''; | ||
var firstPoint = false; | ||
let result = ''; | ||
let firstPoint = false; | ||
for (; this.currentPosition < this.input.length; this.nextSymbol()) { | ||
var skip = Char.isWhiteSpace(this.current) || !Char.isDigit(this.current) && !Char.isFloating(this.current) && this.current !== Char.POINT; | ||
const skip = Char.isWhiteSpace(this.current) || !Char.isDigit(this.current) && !Char.isFloating(this.current) && this.current !== Char.POINT; | ||
@@ -1702,3 +1721,3 @@ if (skip) { | ||
var numValue = parseFloat(result); | ||
const numValue = parseFloat(result); | ||
@@ -1714,6 +1733,6 @@ if (Number.isNaN(numValue)) { | ||
value: function captureIdentifier() { | ||
var result = ''; | ||
let result = ''; | ||
for (; this.currentPosition < this.input.length; this.nextSymbol()) { | ||
var skip = !(Char.isLetterOrDigit(this.current) || Char.isUnderscore(this.current)); | ||
const skip = !(Char.isLetterOrDigit(this.current) || Char.isUnderscore(this.current)); | ||
@@ -1728,3 +1747,5 @@ if (skip) { | ||
if (this.current === Char.OPEN_BRACKET) { | ||
return this.createToken(exports.TokenType.Function, result); | ||
const isBetween = this.tokens.some(token => token.type === exports.TokenType.Between); | ||
const isOutside = this.tokens.some(token => token.type === exports.TokenType.Outside); | ||
return this.createToken(isOutside ? exports.TokenType.Outside : isBetween ? exports.TokenType.Between : exports.TokenType.Function, result); | ||
} | ||
@@ -1750,3 +1771,3 @@ | ||
this.nextSymbol(); | ||
var result = ''; | ||
let result = ''; | ||
@@ -1772,5 +1793,5 @@ for (; this.currentPosition < this.input.length; this.nextSymbol()) { | ||
value: function captureString() { | ||
var result = ''; | ||
var escaping = false; | ||
var start = this.current; | ||
let result = ''; | ||
let escaping = false; | ||
const start = this.current; | ||
this.nextSymbol(); | ||
@@ -1804,3 +1825,3 @@ | ||
var stringToken = this.captureString(); | ||
const stringToken = this.captureString(); | ||
return this.createToken(exports.TokenType.Date, stringToken.value); | ||
@@ -1811,3 +1832,3 @@ } | ||
value: function captureTimeSpan() { | ||
var result = ''; | ||
let result = ''; | ||
@@ -1822,3 +1843,3 @@ for (; this.currentPosition < this.input.length; this.nextSymbol()) { | ||
var number = parseFloat(result); | ||
const number = parseFloat(result); | ||
@@ -1833,3 +1854,3 @@ if (Number.isNaN(number)) { | ||
var timeSpanUnit = ''; | ||
let timeSpanUnit = ''; | ||
@@ -1841,3 +1862,3 @@ while (Char.isLetter(this.current)) { | ||
var time = 0; | ||
let time = 0; | ||
@@ -1892,7 +1913,2 @@ switch (timeSpanUnit) { | ||
} | ||
}, { | ||
key: "current", | ||
get: function get() { | ||
return this.input[this.currentPosition]; | ||
} | ||
}]); | ||
@@ -1903,7 +1919,3 @@ | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
} | ||
var ConditionVisitor = /*#__PURE__*/function (_ExpressionVisitor) { | ||
let ConditionVisitor = /*#__PURE__*/function (_ExpressionVisitor) { | ||
_inherits(ConditionVisitor, _ExpressionVisitor); | ||
@@ -1924,10 +1936,10 @@ | ||
var leftExpression = node.left && node.left.accept(this); | ||
var rightExpression = node.right && node.right.accept(this); | ||
const leftExpression = node.left && node.left.accept(this); | ||
const rightExpression = node.right && node.right.accept(this); | ||
if (node.left instanceof BoolOperationNode && node.right instanceof BoolOperationNode) { | ||
this.checkBoolOperations(node.token.type, [].concat(leftExpression.boolOperations, rightExpression.boolOperations)); | ||
this.checkBoolOperations(node.token.type, [...leftExpression.boolOperations, ...rightExpression.boolOperations]); | ||
return { | ||
boolOperations: [].concat(leftExpression.boolOperations, [node.token.type], rightExpression.boolOperations), | ||
expressions: [].concat(leftExpression.expressions, rightExpression.expressions) | ||
boolOperations: [...leftExpression.boolOperations, node.token.type, ...rightExpression.boolOperations], | ||
expressions: [...leftExpression.expressions, ...rightExpression.expressions] | ||
}; | ||
@@ -1939,4 +1951,4 @@ } | ||
return { | ||
boolOperations: [node.token.type].concat(rightExpression.boolOperations), | ||
expressions: [leftExpression].concat(rightExpression.expressions) | ||
boolOperations: [node.token.type, ...rightExpression.boolOperations], | ||
expressions: [leftExpression, ...rightExpression.expressions] | ||
}; | ||
@@ -1948,4 +1960,4 @@ } | ||
return { | ||
boolOperations: [].concat(leftExpression.boolOperations, [node.token.type]), | ||
expressions: [].concat(leftExpression.expressions, [rightExpression]) | ||
boolOperations: [...leftExpression.boolOperations, node.token.type], | ||
expressions: [...leftExpression.expressions, rightExpression] | ||
}; | ||
@@ -1962,12 +1974,14 @@ } | ||
value: function visitOpNode(node) { | ||
var _node$right; | ||
_get(_getPrototypeOf(ConditionVisitor.prototype), "visitOpNode", this).call(this, node); | ||
this.checkExpressionSimple(node); | ||
var attribute = node.left && node.left.accept(this); | ||
var value = node.right && node.right.accept(this); | ||
var operation = node.token.type; | ||
const attribute = node.left && node.left.accept(this); | ||
const value = node.right && ((_node$right = node.right) == null ? void 0 : _node$right.accept(this)); | ||
const operation = node.token.type; | ||
return { | ||
attribute: attribute, | ||
operation: operation, | ||
value: value | ||
attribute, | ||
operation, | ||
value | ||
}; | ||
@@ -1992,5 +2006,3 @@ } | ||
value: function checkBoolOperations(baseOperation, operations) { | ||
if (operations.some(function (op) { | ||
return op !== baseOperation; | ||
})) { | ||
if (operations.some(op => op !== baseOperation)) { | ||
throw new LintError('Выражение должно использовать одинаковые булевы операторы'); | ||
@@ -2011,9 +2023,5 @@ } | ||
var isBoolResult = function isBoolResult(result) { | ||
return isObject(result) && 'boolOperations' in result; | ||
}; | ||
var isExpression = function isExpression(result) { | ||
return isObject(result) && 'attribute' in result; | ||
}; | ||
var ConditionInterpreter = /*#__PURE__*/function () { | ||
const isBoolResult = result => isObject(result) && 'boolOperations' in result; | ||
const isExpression = result => isObject(result) && 'attribute' in result; | ||
let ConditionInterpreter = /*#__PURE__*/function () { | ||
function ConditionInterpreter(condition) { | ||
@@ -2035,5 +2043,5 @@ _classCallCheck(this, ConditionInterpreter); | ||
try { | ||
var tokens = this.tokenizer.tokenize(); | ||
var ast = new ExpressionAst(tokens).value; | ||
var result = ast && ast.accept(new ConditionVisitor()); | ||
const tokens = this.tokenizer.tokenize(); | ||
const ast = new ExpressionAst(tokens).value; | ||
const result = ast && ast.accept(new ConditionVisitor()); | ||
@@ -2064,3 +2072,3 @@ if (isBoolResult(result)) { | ||
var ConditionEvaluator = /*#__PURE__*/function () { | ||
let ConditionEvaluator = /*#__PURE__*/function () { | ||
function ConditionEvaluator(attributes) { | ||
@@ -2076,4 +2084,4 @@ _classCallCheck(this, ConditionEvaluator); | ||
try { | ||
var tokens = new ExpressionTokenizer(condition).tokenize(); | ||
var ast = new ExpressionAst(tokens).value; | ||
const tokens = new ExpressionTokenizer(condition).tokenize(); | ||
const ast = new ExpressionAst(tokens).value; | ||
return ast && ast.accept(new EvaluateVisitor(this.attributes, options)); | ||
@@ -2089,3 +2097,3 @@ } catch (e) { | ||
var ConditionLinter = /*#__PURE__*/function () { | ||
let ConditionLinter = /*#__PURE__*/function () { | ||
function ConditionLinter(attributes) { | ||
@@ -2101,4 +2109,4 @@ _classCallCheck(this, ConditionLinter); | ||
try { | ||
var tokens = new ExpressionTokenizer(condition).tokenize(); | ||
var ast = new ExpressionAst(tokens).value; | ||
const tokens = new ExpressionTokenizer(condition).tokenize(); | ||
const ast = new ExpressionAst(tokens).value; | ||
ast && ast.accept(new LintVisitor(this.attributes)); | ||
@@ -2105,0 +2113,0 @@ return null; |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}function n(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&i(e,t)}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function s(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,t,r){return(u=s()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&i(o,r.prototype),o}).apply(null,arguments)}function a(e){var t="function"==typeof Map?new Map:void 0;return(a=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return u(e,arguments,o(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,e)})(e)}function c(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function p(e){var t=s();return function(){var r,n=o(e);if(t){var i=o(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return c(this,r)}}function l(e,t,r){return(l="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,r){var n=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=o(e)););return e}(e,t);if(n){var i=Object.getOwnPropertyDescriptor(n,t);return i.get?i.get.call(r):i.value}})(e,t,r||e)}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var f;Object.defineProperty(exports,"__esModule",{value:!0}),(f=exports.TokenType||(exports.TokenType={}))[f.Number=0]="Number",f[f.Identifier=1]="Identifier",f[f.DynamicIdentifier=2]="DynamicIdentifier",f[f.String=3]="String",f[f.Date=4]="Date",f[f.TimeSpan=5]="TimeSpan",f[f.Terminal=6]="Terminal",f[f.EndOfString=7]="EndOfString",f[f.Null=8]="Null",f[f.ArIn=9]="ArIn",f[f.ArEq=10]="ArEq",f[f.ArNotEq=11]="ArNotEq",f[f.ArGr=12]="ArGr",f[f.ArGre=13]="ArGre",f[f.ArLs=14]="ArLs",f[f.ArLse=15]="ArLse",f[f.BoolNot=16]="BoolNot",f[f.BoolAnd=17]="BoolAnd",f[f.BoolOr=18]="BoolOr",f[f.ArPlus=19]="ArPlus",f[f.ArMinus=20]="ArMinus",f[f.ArMul=21]="ArMul",f[f.ArDiv=22]="ArDiv",f[f.ExprOpen=23]="ExprOpen",f[f.ExprClose=24]="ExprClose",f[f.ArrayOpen=25]="ArrayOpen",f[f.ArrayClose=26]="ArrayClose",f[f.Separator=27]="Separator",f[f.Function=28]="Function";var y={start:0,end:0},k=function t(r,n,o){void 0===o&&(o=y),e(this,t),this.type=r,this.value=n,this.position=o},v=function(){function t(r,n,o){void 0===n&&(n=null),void 0===o&&(o=null),e(this,t),this.token=r,this.left=n,this.right=o}return r(t,[{key:"accept",value:function(e){return e.visit(this)}}]),t}(),T=function(t){n(i,v);var o=p(i);function i(){return e(this,i),o.apply(this,arguments)}return r(i,null,[{key:"is",value:function(e){return i.TOKENS.includes(e.type)}}]),i}();T.TOKENS=[exports.TokenType.String,exports.TokenType.Number,exports.TokenType.DynamicIdentifier,exports.TokenType.Date];var x=function(t){n(i,v);var o=p(i);function i(){return e(this,i),o.apply(this,arguments)}return r(i,null,[{key:"is",value:function(e){return i.TOKENS.includes(e.type)}}]),i}();x.TOKENS=[exports.TokenType.Identifier];var d=function(t){n(i,v);var o=p(i);function i(){return e(this,i),o.apply(this,arguments)}return r(i,null,[{key:"is",value:function(e){return i.TOKENS.includes(e.type)}}]),i}();d.TOKENS=[exports.TokenType.ArEq,exports.TokenType.ArNotEq,exports.TokenType.ArGr,exports.TokenType.ArGre,exports.TokenType.ArLs,exports.TokenType.ArLse,exports.TokenType.ArPlus,exports.TokenType.ArMinus,exports.TokenType.ArDiv,exports.TokenType.ArMul];var A=function(t){n(i,v);var o=p(i);function i(){return e(this,i),o.apply(this,arguments)}return r(i,null,[{key:"is",value:function(e){return i.TOKENS.includes(e.type)}}]),i}();A.TOKENS=[exports.TokenType.BoolAnd,exports.TokenType.BoolOr];var g=function(t){n(i,v);var o=p(i);function i(t,r,n,s){var u;return void 0===n&&(n=null),void 0===s&&(s=null),e(this,i),(u=o.call(this,t,n,s)).func=r,u}return r(i,null,[{key:"is",value:function(e){return i.TOKENS.includes(e.type)}}]),i}();g.TOKENS=[exports.TokenType.Function];var N=new Map;N.set(exports.TokenType.ExprOpen,0),N.set(exports.TokenType.ExprClose,0),N.set(exports.TokenType.BoolAnd,1),N.set(exports.TokenType.BoolOr,1),N.set(exports.TokenType.ArEq,2),N.set(exports.TokenType.ArNotEq,2),N.set(exports.TokenType.ArGr,2),N.set(exports.TokenType.ArGre,2),N.set(exports.TokenType.ArLs,2),N.set(exports.TokenType.ArLse,2),N.set(exports.TokenType.ArPlus,3),N.set(exports.TokenType.ArMinus,3),N.set(exports.TokenType.ArMul,4),N.set(exports.TokenType.ArDiv,4),N.set(exports.TokenType.Function,5);var E=function(t){n(o,a(Error));var r=p(o);function o(t,n){var i;return void 0===n&&(n=y),e(this,o),(i=r.call(this)).position=n,i.message=i.name+"(cимвол: "+(n.start+1)+", "+(n.end+1)+"):"+t+".",i}return o}(),O=function(t){n(o,E);var r=p(o);function o(t,n){var i;return void 0===n&&(n=y),e(this,o),(i=r.call(this,t,n)).position=n,i.name="LintError",i}return o}(),b=function(e){return e[e.length-1]},m=function(e){return T.is(e)||x.is(e)},S=function(e){return d.is(e)||A.is(e)||g.is(e)},w=function(t){n(o,E);var r=p(o);function o(t,n){var i;return void 0===n&&(n=y),e(this,o),(i=r.call(this,t,n)).position=n,i.name="ExpressionAst",i}return o}(),C=function(){function t(){e(this,t)}return r(t,[{key:"visit",value:function(e){return e instanceof A?this.visitBoolOpNode(e):e instanceof d?this.visitOpNode(e):e instanceof T?this.visitValueNode(e):e instanceof x?this.visitAttributeNode(e):e instanceof g?this.visitFunctionNode(e):void 0}},{key:"visitBoolOpNode",value:function(e){}},{key:"visitOpNode",value:function(e){}},{key:"visitValueNode",value:function(e){}},{key:"visitAttributeNode",value:function(e){}},{key:"visitFunctionNode",value:function(e){}}]),t}(),L=function(t){n(s,C);var i=p(s);function s(t){var r;return e(this,s),(r=i.call(this)).attributes=t,r}return r(s,[{key:"visitBoolOpNode",value:function(e){l(o(s.prototype),"visitBoolOpNode",this).call(this,e),this.checkBoolOpNode(e),this.acceptLeafs(e)}},{key:"visitOpNode",value:function(e){l(o(s.prototype),"visitOpNode",this).call(this,e),this.checkOpNode(e),this.acceptLeafs(e)}},{key:"visitValueNode",value:function(e){l(o(s.prototype),"visitValueNode",this).call(this,e),this.checkLeafNode(e)}},{key:"visitAttributeNode",value:function(e){l(o(s.prototype),"visitAttributeNode",this).call(this,e),this.checkLeafNode(e),this.checkAttributeNode(e)}},{key:"visitFunctionNode",value:function(e){l(o(s.prototype),"visitFunctionNode",this).call(this,e),this.checkLeafNode(e),this.checkFunctionNode(e)}},{key:"checkBoolOpNode",value:function(e){var t="Ожидается выражение вида 'a == 2 "+e.token.value+" b == 3'";this.isOperationNode(e.left)||this.Error(t,e.token),this.isOperationNode(e.right)||this.Error(t,e.token)}},{key:"checkOpNode",value:function(e){e.left&&e.right||this.Error("'"+e.token.value+"' ожидает выражение",e.token)}},{key:"checkLeafNode",value:function(e){if(e.left){var t=e.left.token;this.Error("'"+t.value+"' не может использоваться вне выражения",t)}if(e.right){var r=e.right.token;this.Error("'"+r.value+"' не может использоваться вне выражения",r)}}},{key:"checkAttributeNode",value:function(e){e.token.value&&void 0!==this.attributes[e.token.value]||this.Error("Атрибут '"+e.token.value+"' не найден в атрибутах слоя",e.token)}},{key:"checkFunctionNode",value:function(e){var t=e.func.check(this.attributes);t instanceof Error&&this.Error(t.message,e.token)}},{key:"Error",value:function(e,t){throw new O(e,t.position)}},{key:"acceptLeafs",value:function(e){return{x:e.left&&e.left.accept(this),y:e.right&&e.right.accept(this)}}},{key:"isOperationNode",value:function(e){return e instanceof A||e instanceof d}}]),s}(),M=function(t){n(s,L);var i=p(s);function s(t,r){var n;return e(this,s),(n=i.call(this,t)).attributes=t,n.silent=!(!r||!r.silent),n}return r(s,[{key:"visitBoolOpNode",value:function(e){this.silent||l(o(s.prototype),"visitBoolOpNode",this).call(this,e);var t=this.acceptLeafs(e),r=t.x,n=t.y;return e.token.type===exports.TokenType.BoolAnd?r&&n:r||n}},{key:"visitOpNode",value:function(e){this.silent||l(o(s.prototype),"visitOpNode",this).call(this,e);var t=this.acceptLeafs(e),r=t.x,n=t.y;switch(e.token.type){case exports.TokenType.ArEq:return r===n;case exports.TokenType.ArNotEq:return r!==n;case exports.TokenType.ArGre:return r>=n;case exports.TokenType.ArLse:return r<=n;case exports.TokenType.ArGr:return r>n;case exports.TokenType.ArLs:return r<n;case exports.TokenType.ArPlus:return r+n;case exports.TokenType.ArMinus:return r-n;case exports.TokenType.ArMul:return r*n;case exports.TokenType.ArDiv:return r/n;default:return!1}}},{key:"visitValueNode",value:function(e){return this.silent||l(o(s.prototype),"visitValueNode",this).call(this,e),e.token.value}},{key:"visitAttributeNode",value:function(e){return this.silent||l(o(s.prototype),"visitAttributeNode",this).call(this,e),this.attributes[e.token.value]}},{key:"visitFunctionNode",value:function(e){return this.silent||l(o(s.prototype),"visitFunctionNode",this).call(this,e),e.func.calc(this.attributes)}}]),s}(),B=function(){function t(r){e(this,t),this.args=r}return r(t,[{key:"calc",value:function(e){return 0}},{key:"evaluateArguments",value:function(e){return this.args.map((function(t){if(t instanceof d)return t.accept(new M(e));if("string"==typeof t.value){if("number"!=typeof e[t.value])throw new O("Аргумент функции должен быть числовым типом",t.position);return e[t.value]}return t.value}))}},{key:"check",value:function(e,t){return this.evaluateArguments(e).length!==t?new Error("Передано неверное количество аргументов"):null}}]),t}(),P=function(t){n(s,B);var i=p(s);function s(){return e(this,s),i.apply(this,arguments)}return r(s,[{key:"calc",value:function(e){var t=l(o(s.prototype),"evaluateArguments",this).call(this,e);return+Math.sin(t[0]).toFixed(3)}},{key:"check",value:function(e){return l(o(s.prototype),"check",this).call(this,e,s.ArgsCount)}}]),s}();P.ArgsCount=1,P.Name="sin";var F=function(t){n(s,B);var i=p(s);function s(){return e(this,s),i.apply(this,arguments)}return r(s,[{key:"calc",value:function(e){var t=l(o(s.prototype),"evaluateArguments",this).call(this,e);return+Math.asin(t[0]).toFixed(3)}},{key:"check",value:function(e){return l(o(s.prototype),"check",this).call(this,e,s.ArgsCount)}}]),s}();F.ArgsCount=1,F.Name="arcsin";var D=function(t){n(s,B);var i=p(s);function s(){return e(this,s),i.apply(this,arguments)}return r(s,[{key:"calc",value:function(e){var t=l(o(s.prototype),"evaluateArguments",this).call(this,e);return+Math.cos(t[0]).toFixed(3)}},{key:"check",value:function(e){return l(o(s.prototype),"check",this).call(this,e,s.ArgsCount)}}]),s}();D.ArgsCount=1,D.Name="cos";var I=function(t){n(s,B);var i=p(s);function s(){return e(this,s),i.apply(this,arguments)}return r(s,[{key:"calc",value:function(e){var t=l(o(s.prototype),"evaluateArguments",this).call(this,e);return+Math.acos(t[0]).toFixed(3)}},{key:"check",value:function(e){return l(o(s.prototype),"check",this).call(this,e,s.ArgsCount)}}]),s}();I.ArgsCount=1,I.Name="arccos";var _=function(t){n(s,B);var i=p(s);function s(){return e(this,s),i.apply(this,arguments)}return r(s,[{key:"calc",value:function(e){var t=l(o(s.prototype),"evaluateArguments",this).call(this,e);return+Math.atan2(t[0],t[1]).toFixed(3)}},{key:"check",value:function(e){return l(o(s.prototype),"check",this).call(this,e,s.ArgsCount)}}]),s}();_.ArgsCount=2,_.Name="arctan2";var R=function(t){n(s,B);var i=p(s);function s(){return e(this,s),i.apply(this,arguments)}return r(s,[{key:"calc",value:function(e){var t=l(o(s.prototype),"evaluateArguments",this).call(this,e);return+Math.tan(t[0]).toFixed(3)}},{key:"check",value:function(e){return l(o(s.prototype),"check",this).call(this,e,s.ArgsCount)}}]),s}();R.ArgsCount=1,R.Name="tan";var K=function(t){n(s,B);var i=p(s);function s(){return e(this,s),i.apply(this,arguments)}return r(s,[{key:"calc",value:function(e){var t=l(o(s.prototype),"evaluateArguments",this).call(this,e);return+Math.atan(t[0]).toFixed(3)}},{key:"check",value:function(e){return l(o(s.prototype),"check",this).call(this,e,s.ArgsCount)}}]),s}();K.ArgsCount=1,K.Name="arctan";var q,G=function(t){n(s,B);var i=p(s);function s(){return e(this,s),i.apply(this,arguments)}return r(s,[{key:"calc",value:function(e){var t=l(o(s.prototype),"evaluateArguments",this).call(this,e);return+Math.sqrt(t[0]).toFixed(3)}},{key:"check",value:function(e){return l(o(s.prototype),"check",this).call(this,e,s.ArgsCount)}}]),s}();G.ArgsCount=1,G.Name="sqrt";var U=((q={})[P.Name]=P,q[F.Name]=F,q[D.Name]=D,q[I.Name]=I,q[R.Name]=R,q[K.Name]=K,q[_.Name]=_,q[G.Name]=G,q),j=function(){function t(r){e(this,t),this.tokens=r,this.tree=null,this.currentPosition=0}return r(t,[{key:"nextToken",value:function(){this.currentPosition+=1}},{key:"checkRoot",value:function(){}},{key:"flashStack",value:function(e){if(this.tree&&e.length)for(;e.length;){var t=e.pop();t&&this.insert(this.tree,t)}}},{key:"insert",value:function(e,t){null!==e.right?this.insert(e.right,t):e.right=t}},{key:"Error",value:function(e,t){var r=t.position;throw new w(e,{start:r.start,end:r.end})}},{key:"value",get:function(){if(this.tree)return this.tree;this.tokens=function(e){for(var t,r,n,o=[],i=[],s=function(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return h(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?h(e,void 0):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}(e);!(t=s()).done;){var u=t.value;if(m(u)&&o.push(u),S(u)){for(;b(i)&&(r=b(i),n=u,N.get(r.type)>N.get(n.type))&&b(i).type!==exports.TokenType.ExprOpen;)o.push(i.pop());i.push(u)}if(u.type===exports.TokenType.ExprOpen&&i.push(u),u.type===exports.TokenType.ExprClose){for(var a=u;b(i)&&b(i).type!==exports.TokenType.ExprOpen;)o.push(i.pop());if(0===i.length)throw new O("Пропущена открывающая скобка",a.position);b(i).type===exports.TokenType.ExprOpen&&i.pop()}}if(i.length){var c=b(i);if(c.type===exports.TokenType.ExprOpen)throw new O("Пропущена закрывающая скобка",c.position);o=[].concat(o,i.reverse())}return o}(this.tokens);for(var e=[];this.currentPosition<this.tokens.length;this.nextToken()){if(T.is(this.currentToken)&&e.push(new T(this.currentToken)),x.is(this.currentToken)&&e.push(new x(this.currentToken)),g.is(this.currentToken)){var t=U[this.currentToken.value];t||this.Error("Функция '"+this.currentToken.value+"' не определена",this.currentToken);for(var r=[],n=0;n<t.ArgsCount;n++){var o=e.pop()||null;o instanceof d?r.push(o):o&&o.token&&r.push(o.token)}var i=new t(r);e.push(new g(this.currentToken,i))}if(d.is(this.currentToken)){var s=new d(this.currentToken);e.length>1&&(s.right=e.pop()||null),s.left=e.pop()||null,e.push(s)}if(A.is(this.currentToken)){var u=new A(this.currentToken);e.length>1&&(u.right=e.pop()||null),u.left=e.pop()||null,e.push(u)}}return this.tree=e.pop()||null,this.flashStack(e),this.checkRoot(),this.tree}},{key:"currentToken",get:function(){return this.tokens[this.currentPosition]}}]),t}(),V=function(t){n(o,E);var r=p(o);function o(t,n){var i;return void 0===n&&(n=y),e(this,o),(i=r.call(this,t,n)).position=n,i.name="ExpressionTokenizer",i}return o}(),H=function(){function t(r,n,o){var i=this;void 0===o&&(o=[]),e(this,t),this.acceptMap=new Map,this.value=r,this.tokenType=n,o.map((function(e){return i.acceptMap.set(e.value,e)}))}return r(t,[{key:"accept",value:function(e){return this.acceptMap.get(e)||null}}]),t}(),z=new H("",exports.TokenType.Null,[new H(">",exports.TokenType.ArGr,[new H("=",exports.TokenType.ArGre)]),new H("<",exports.TokenType.ArLs,[new H("=",exports.TokenType.ArLse)]),new H("!",exports.TokenType.BoolNot,[new H("=",exports.TokenType.ArNotEq)]),new H("&",exports.TokenType.Null,[new H("&",exports.TokenType.BoolAnd)]),new H("=",exports.TokenType.ArEq,[new H("=",exports.TokenType.ArEq)]),new H("|",exports.TokenType.Null,[new H("|",exports.TokenType.BoolOr)]),new H("+",exports.TokenType.ArPlus),new H("-",exports.TokenType.ArMinus),new H("*",exports.TokenType.ArMul),new H("/",exports.TokenType.ArDiv),new H("(",exports.TokenType.ExprOpen),new H(")",exports.TokenType.ExprClose),new H("[",exports.TokenType.ArrayOpen),new H("]",exports.TokenType.ArrayClose),new H(",",exports.TokenType.Separator)]),Q=function(){function t(){e(this,t)}return r(t,null,[{key:"isChar",value:function(e){return"string"==typeof e&&1===e.length}},{key:"isDigit",value:function(e){return this.isChar(e)&&/\d/.test(e)}},{key:"isLetter",value:function(e){return this.isChar(e)&&/\w/.test(e)}},{key:"isWhiteSpace",value:function(e){return this.isChar(e)&&e===t.WHITE_SPACE}},{key:"isLetterOrDigit",value:function(e){return t.isLetter(e)||t.isDigit(e)}},{key:"isUnderscore",value:function(e){return t.isChar(e)&&e===t.UNDERSCORE}},{key:"isFloating",value:function(e){return t.isChar(e)&&("f"===e||"F"===e)}},{key:"escapeSpecChars",value:function(e){return e.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"').replace(/\t/g,"\\\\t").replace(/\v/g,"\\\\v").replace(/\0/g,"\\\\0").replace(/\f/g,"\\\\f").replace(/\n/g,"\\\\n").replace(/\r/g,"\\\\r")}},{key:"unEscapeSpecChars",value:function(e){return e.replace(/\\'/g,"'").replace(/\\"/g,'"').replace(/\\\\/g,"\\").replace(/\\\\t/g,"\t").replace(/\\\\v/g,"\v").replace(/\\\\0/g,"\0").replace(/\\\\f/g,"\f").replace(/\\\\n/g,"\n").replace(/\\\\r/g,"\r")}}]),t}();Q.LEFT_BRACKET="{",Q.OPEN_BRACKET="(",Q.SINGLE_QUOTE="'",Q.DOUBLE_QUOTE='"',Q.HASH_SYMBOL="#",Q.RIGHT_BRACKET="}",Q.CLOSE_BRACKET=")",Q.BACK_SLASH="\\",Q.WHITE_SPACE=" ",Q.UNDERSCORE="_",Q.PERCENTAGE="%",Q.POINT=".";var W=function t(){e(this,t)};W.sToMs=function(e){return 1e3*e},W.mToMs=function(e){return 60*W.sToMs(e)},W.hToMs=function(e){return 60*W.mToMs(e)},W.dToMs=function(e){return 24*W.hToMs(e)},W.mthToMs=function(e){return 30*W.dToMs(e)},W.yToMs=function(e){return 365*W.mthToMs(e)};var Y=function(){function t(r){e(this,t),this.start=0,this.currentPosition=0,this.tokens=[],this.input=r||""}return r(t,[{key:"tokenize",value:function(){if(this.isEndOfString())return this.tokens;for(;;){var e=this.nextToken();if(!e)break;if(this.tokens.push(e),this.tokens.length>1e3&&this.Error("Привышен лимит запроса: 1000"),e.type===exports.TokenType.EndOfString)break}return this.tokens}},{key:"nextToken",value:function(){for(;this.currentPosition<this.input.length;this.nextSymbol())if(!Q.isWhiteSpace(this.current)){this.resetStart();var e=z.accept(this.current);if(null!==e)return this.captureSpecial(e);if(Q.isDigit(this.current)||this.current===Q.POINT)return this.captureNumber();if(Q.isLetter(this.current)||Q.isUnderscore(this.current))return this.captureIdentifier();if(this.current===Q.LEFT_BRACKET)return this.captureDynamicIdentifier();if(this.current===Q.DOUBLE_QUOTE||this.current===Q.SINGLE_QUOTE)return this.captureString();if(this.current===Q.HASH_SYMBOL)return this.captureDate()}return this.resetStart(),this.createToken(exports.TokenType.EndOfString)}},{key:"resetStart",value:function(){this.start=this.currentPosition}},{key:"createToken",value:function(e,t){void 0===t&&(t=null);var r=this.currentPosition-(e===exports.TokenType.EndOfString?0:1);return new k(e,t,{start:this.start,end:r})}},{key:"nextSymbol",value:function(){this.currentPosition+=1}},{key:"captureSpecial",value:function(e){var t=this.current;for(this.nextSymbol();this.currentPosition<this.input.length;this.nextSymbol()){var r=e.accept(this.current);if(null===r||r.tokenType===exports.TokenType.Null)break;t+=this.current,e=r}return this.current&&Q.isDigit(this.current)&&e.tokenType===exports.TokenType.ArMinus?this.createToken(exports.TokenType.Number,-(this.captureNumber().value||0)):(e.tokenType===exports.TokenType.Null&&this.Error("Неизвеcтная операция '"+e.value+"'"),this.createToken(e.tokenType,t))}},{key:"captureNumber",value:function(){for(var e="",t=!1;this.currentPosition<this.input.length&&!Q.isWhiteSpace(this.current)&&(Q.isDigit(this.current)||Q.isFloating(this.current)||this.current===Q.POINT);this.nextSymbol())this.current===Q.POINT&&(t=!0),e+=this.current;t&&Q.isFloating(e[e.length-1])&&(e=e.slice(0,-1));var r=parseFloat(e);return Number.isNaN(r)&&this.Error("Неверный числовой формат: "+e),this.createToken(exports.TokenType.Number,r)}},{key:"captureIdentifier",value:function(){for(var e="";this.currentPosition<this.input.length&&(Q.isLetterOrDigit(this.current)||Q.isUnderscore(this.current));this.nextSymbol())e+=this.current;return this.current===Q.OPEN_BRACKET?this.createToken(exports.TokenType.Function,e):"true"===e||"True"===e||"TRUE"===e?this.createToken(exports.TokenType.Terminal,!0):"false"===e||"False"===e||"FALSE"===e?this.createToken(exports.TokenType.Terminal,!1):"in"===e||"IN"===e?this.createToken(exports.TokenType.ArIn):this.createToken(exports.TokenType.Identifier,e)}},{key:"captureDynamicIdentifier",value:function(){this.nextSymbol();for(var e="";this.currentPosition<this.input.length;this.nextSymbol()){if(this.current===Q.RIGHT_BRACKET){this.nextSymbol();break}e+=this.current}return this.createToken(exports.TokenType.DynamicIdentifier,"null"===e||"Null"===e||"NULL"===e?null:e)}},{key:"captureString",value:function(){var e="",t=!1,r=this.current;for(this.nextSymbol();this.currentPosition<this.input.length;this.nextSymbol())if(t||this.current!==Q.BACK_SLASH){if(!t&&this.current===r)return this.nextSymbol(),this.createToken(exports.TokenType.String,e);e+=this.current,t=!1}else t=!0;this.Error("Открытая строка")}},{key:"captureDate",value:function(){if(this.nextSymbol(),![Q.SINGLE_QUOTE,Q.DOUBLE_QUOTE,Q.BACK_SLASH].includes(this.current))return this.captureTimeSpan();var e=this.captureString();return this.createToken(exports.TokenType.Date,e.value)}},{key:"captureTimeSpan",value:function(){for(var e="";this.currentPosition<this.input.length&&Q.isDigit(this.current);this.nextSymbol())e+=this.current;var t=parseFloat(e);Number.isNaN(t)&&this.Error("Неверный формат числа для значения timespan: "+e+". Должно быть положительным целочисленным значением."),Q.isLetter(this.current)||this.Error("Для значения задана неверная единица измерения "+this.current);for(var r="";Q.isLetter(this.current);)r+=this.current,this.nextSymbol();var n=0;switch(r){case"ms":n=t;break;case"s":n=W.sToMs(t);break;case"m":n=W.mToMs(t);break;case"h":n=W.hToMs(t);break;case"d":n=W.dToMs(t);break;case"mth":n=W.mthToMs(t);break;case"y":n=W.yToMs(t);break;default:this.Error("Неверная единица измерения для timespan: "+r)}return this.createToken(exports.TokenType.TimeSpan,n)}},{key:"isEndOfString",value:function(){return this.tokens.length>0&&this.tokens[this.tokens.length-1].type===exports.TokenType.EndOfString}},{key:"Error",value:function(e){throw new V(e,{start:this.start,end:this.start})}},{key:"current",get:function(){return this.input[this.currentPosition]}}]),t}();function $(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}var J=function(t){n(s,C);var i=p(s);function s(){return e(this,s),i.apply(this,arguments)}return r(s,[{key:"visitBoolOpNode",value:function(e){l(o(s.prototype),"visitBoolOpNode",this).call(this,e);var t=e.left&&e.left.accept(this),r=e.right&&e.right.accept(this);return e.left instanceof A&&e.right instanceof A?(this.checkBoolOperations(e.token.type,[].concat(t.boolOperations,r.boolOperations)),{boolOperations:[].concat(t.boolOperations,[e.token.type],r.boolOperations),expressions:[].concat(t.expressions,r.expressions)}):e.right instanceof A?(this.checkBoolOperations(e.token.type,r.boolOperations),{boolOperations:[e.token.type].concat(r.boolOperations),expressions:[t].concat(r.expressions)}):e.left instanceof A?(this.checkBoolOperations(e.token.type,t.boolOperations),{boolOperations:[].concat(t.boolOperations,[e.token.type]),expressions:[].concat(t.expressions,[r])}):{boolOperations:[e.token.type],expressions:[t,r]}}},{key:"visitOpNode",value:function(e){l(o(s.prototype),"visitOpNode",this).call(this,e),this.checkExpressionSimple(e);var t=e.left&&e.left.accept(this),r=e.right&&e.right.accept(this);return{attribute:t,operation:e.token.type,value:r}}},{key:"visitValueNode",value:function(e){return l(o(s.prototype),"visitValueNode",this).call(this,e),e.token.value}},{key:"visitAttributeNode",value:function(e){return l(o(s.prototype),"visitAttributeNode",this).call(this,e),e.token.value}},{key:"checkBoolOperations",value:function(e,t){if(t.some((function(t){return t!==e})))throw new O("Выражение должно использовать одинаковые булевы операторы")}},{key:"checkExpressionSimple",value:function(e){if(!(e.left instanceof x&&e.right instanceof T||e.right instanceof T))throw new O("Выражение должно быть простым")}}]),s}(),X=function(e){return $(e)&&"boolOperations"in e},Z=function(e){return $(e)&&"attribute"in e},ee=function(){function t(r){e(this,t),this.result=null,this.tokenizer=new Y(r)}return r(t,[{key:"value",get:function(){if(this.result)return this.result;try{var e=this.tokenizer.tokenize(),t=new j(e).value,r=t&&t.accept(new J);return this.result=X(r)?r:Z(r)?{boolOperations:[],expressions:[r]}:{boolOperations:[],expressions:[]},this.result}catch(e){return e}}}]),t}(),te=function(){function t(r){e(this,t),this.attributes=r}return r(t,[{key:"evaluate",value:function(e,t){try{var r=new Y(e).tokenize(),n=new j(r).value;return n&&n.accept(new M(this.attributes,t))}catch(e){return e}}}]),t}(),re=function(){function t(r){e(this,t),this.attributes=r}return r(t,[{key:"lint",value:function(e){try{var t=new Y(e).tokenize(),r=new j(t).value;return r&&r.accept(new L(this.attributes)),null}catch(e){return e}}}]),t}();exports.ArcCos=I,exports.ArcSin=F,exports.ArcTan=K,exports.ArcTan2=_,exports.AttributeNode=x,exports.BoolOperationNode=A,exports.Char=Q,exports.ConditionEvaluator=te,exports.ConditionInterpreter=ee,exports.ConditionLinter=re,exports.ConditionVisitor=J,exports.Cos=D,exports.DEFAULT_TOKEN_POSITION=y,exports.EqlFunction=B,exports.EqlFunctions=U,exports.EvaluateVisitor=M,exports.ExpressionAst=j,exports.ExpressionAstError=w,exports.ExpressionNode=v,exports.ExpressionTokenizer=Y,exports.ExpressionTokenizerError=V,exports.ExpressionVisitor=C,exports.FunctionNode=g,exports.LintError=O,exports.LintVisitor=L,exports.OperationNode=d,exports.Sin=P,exports.Sqrt=G,exports.Tan=R,exports.Time=W,exports.Token=k,exports.TokenError=E,exports.ValueNode=T,exports.isBoolResult=X,exports.isExpression=Z,exports.isObject=$; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("date-fns");function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&c(e,t)}function u(e){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,t){return(c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function p(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function a(e,t,n){return(a=p()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&c(o,n.prototype),o}).apply(null,arguments)}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return a(e,arguments,u(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,e)})(e)}function h(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function f(e){var t=p();return function(){var n,r=u(e);if(t){var o=u(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return h(this,n)}}function y(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=u(e)););return e}function k(){return(k="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var r=y(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(arguments.length<3?e:n):o.value}}).apply(this,arguments)}(e=exports.TokenType||(exports.TokenType={}))[e.Number=0]="Number",e[e.Identifier=1]="Identifier",e[e.DynamicIdentifier=2]="DynamicIdentifier",e[e.String=3]="String",e[e.Date=4]="Date",e[e.TimeSpan=5]="TimeSpan",e[e.Terminal=6]="Terminal",e[e.EndOfString=7]="EndOfString",e[e.Null=8]="Null",e[e.ArIn=9]="ArIn",e[e.ArEq=10]="ArEq",e[e.ArNotEq=11]="ArNotEq",e[e.ArGr=12]="ArGr",e[e.ArGre=13]="ArGre",e[e.ArLs=14]="ArLs",e[e.ArLse=15]="ArLse",e[e.BoolNot=16]="BoolNot",e[e.BoolAnd=17]="BoolAnd",e[e.BoolOr=18]="BoolOr",e[e.ArPlus=19]="ArPlus",e[e.ArMinus=20]="ArMinus",e[e.ArMul=21]="ArMul",e[e.ArDiv=22]="ArDiv",e[e.ExprOpen=23]="ExprOpen",e[e.ExprClose=24]="ExprClose",e[e.ArrayOpen=25]="ArrayOpen",e[e.ArrayClose=26]="ArrayClose",e[e.Separator=27]="Separator",e[e.Function=28]="Function",e[e.Between=29]="Between",e[e.Outside=30]="Outside";const T={start:0,end:0};let v=o((function e(t,r,o){void 0===o&&(o=T),n(this,e),this.type=t,this.value=r,this.position=o})),x=function(){function e(t,r,o){void 0===r&&(r=null),void 0===o&&(o=null),n(this,e),this.token=t,this.left=r,this.right=o}return o(e,[{key:"accept",value:function(e){return e.visit(this)}}]),e}(),d=function(e){s(r,x);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,null,[{key:"is",value:function(e){return r.TOKENS.includes(e.type)}}]),r}();d.TOKENS=[exports.TokenType.String,exports.TokenType.Number,exports.TokenType.DynamicIdentifier,exports.TokenType.Date];let E=function(e){s(r,x);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,null,[{key:"is",value:function(e){return r.TOKENS.includes(e.type)}}]),r}();E.TOKENS=[exports.TokenType.Identifier];let g=function(e){s(r,x);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,null,[{key:"is",value:function(e){return r.TOKENS.includes(e.type)}}]),r}();g.TOKENS=[exports.TokenType.ArEq,exports.TokenType.ArNotEq,exports.TokenType.ArGr,exports.TokenType.ArGre,exports.TokenType.ArLs,exports.TokenType.ArLse,exports.TokenType.ArPlus,exports.TokenType.ArMinus,exports.TokenType.ArDiv,exports.TokenType.ArMul,exports.TokenType.Between,exports.TokenType.Outside];let A=function(e){s(r,x);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,null,[{key:"is",value:function(e){return r.TOKENS.includes(e.type)}}]),r}();A.TOKENS=[exports.TokenType.BoolAnd,exports.TokenType.BoolOr];let O=function(e){s(r,x);var t=f(r);function r(e,o,i,s){var u;return void 0===i&&(i=null),void 0===s&&(s=null),n(this,r),(u=t.call(this,e,i,s)).func=o,u}return o(r,null,[{key:"is",value:function(e){return r.TOKENS.includes(e.type)}}]),r}();O.TOKENS=[exports.TokenType.Function];const N=new Map;N.set(exports.TokenType.ExprOpen,0),N.set(exports.TokenType.ExprClose,0),N.set(exports.TokenType.BoolAnd,1),N.set(exports.TokenType.BoolOr,1),N.set(exports.TokenType.ArEq,2),N.set(exports.TokenType.ArNotEq,2),N.set(exports.TokenType.ArGr,2),N.set(exports.TokenType.ArGre,2),N.set(exports.TokenType.ArLs,2),N.set(exports.TokenType.ArLse,2),N.set(exports.TokenType.ArPlus,3),N.set(exports.TokenType.ArMinus,3),N.set(exports.TokenType.ArMul,4),N.set(exports.TokenType.ArDiv,4),N.set(exports.TokenType.Function,5),N.set(exports.TokenType.Between,5),N.set(exports.TokenType.Outside,5);let b=function(e){s(r,l(Error));var t=f(r);function r(e,o){var i;void 0===o&&(o=T),n(this,r),(i=t.call(this)).position=o;const{start:s,end:u}=o;return i.message=i.name+"(cимвол: "+(s+1)+", "+(u+1)+"):"+e+".",i}return o(r)}(),m=function(e){s(r,b);var t=f(r);function r(e,o){var i;return void 0===o&&(o=T),n(this,r),(i=t.call(this,e,o)).position=o,i.name="LintError",i}return o(r)}();const w=e=>e[e.length-1],S=e=>d.is(e)||E.is(e),B=e=>g.is(e)||A.is(e)||O.is(e);let C=function(e){s(r,b);var t=f(r);function r(e,o){var i;return void 0===o&&(o=T),n(this,r),(i=t.call(this,e,o)).position=o,i.name="ExpressionAst",i}return o(r)}(),L=function(){function e(){n(this,e)}return o(e,[{key:"visit",value:function(e){return e instanceof A?this.visitBoolOpNode(e):e instanceof g?this.visitOpNode(e):e instanceof d?this.visitValueNode(e):e instanceof E?this.visitAttributeNode(e):e instanceof O?this.visitFunctionNode(e):void 0}},{key:"visitBoolOpNode",value:function(e){}},{key:"visitOpNode",value:function(e){}},{key:"visitValueNode",value:function(e){}},{key:"visitAttributeNode",value:function(e){}},{key:"visitFunctionNode",value:function(e){}}]),e}(),M=function(e){s(r,L);var t=f(r);function r(e){var o;return n(this,r),(o=t.call(this)).attributes=e,o}return o(r,[{key:"visitBoolOpNode",value:function(e){k(u(r.prototype),"visitBoolOpNode",this).call(this,e),this.checkBoolOpNode(e),this.acceptLeafs(e)}},{key:"visitOpNode",value:function(e){k(u(r.prototype),"visitOpNode",this).call(this,e),this.checkOpNode(e),this.acceptLeafs(e)}},{key:"visitValueNode",value:function(e){k(u(r.prototype),"visitValueNode",this).call(this,e),this.checkLeafNode(e)}},{key:"visitAttributeNode",value:function(e){k(u(r.prototype),"visitAttributeNode",this).call(this,e),this.checkLeafNode(e),this.checkAttributeNode(e)}},{key:"visitFunctionNode",value:function(e){k(u(r.prototype),"visitFunctionNode",this).call(this,e),this.checkLeafNode(e),this.checkFunctionNode(e)}},{key:"checkBoolOpNode",value:function(e){const t="Ожидается выражение вида 'a == 2 "+e.token.value+" b == 3'";this.isOperationNode(e.left)||this.Error(t,e.token),this.isOperationNode(e.right)||this.Error(t,e.token)}},{key:"checkOpNode",value:function(e){e.left&&e.right||this.Error("'"+e.token.value+"' ожидает выражение",e.token)}},{key:"checkLeafNode",value:function(e){if(e.left){const{token:t}=e.left;this.Error("'"+t.value+"' не может использоваться вне выражения",t)}if(e.right){const{token:t}=e.right;this.Error("'"+t.value+"' не может использоваться вне выражения",t)}}},{key:"checkAttributeNode",value:function(e){e.token.value&&void 0!==this.attributes[e.token.value]||this.Error("Атрибут '"+e.token.value+"' не найден в атрибутах слоя",e.token)}},{key:"checkFunctionNode",value:function(e){const t=e.func.check(this.attributes);t instanceof Error&&this.Error(t.message,e.token)}},{key:"Error",value:function(e,t){const{position:n}=t;throw new m(e,n)}},{key:"acceptLeafs",value:function(e){return{x:e.left&&e.left.accept(this),y:e.right&&e.right.accept(this)}}},{key:"isOperationNode",value:function(e){return e instanceof A||e instanceof g}}]),r}(),P=function(e){s(r,M);var t=f(r);function r(e,o){var i;return n(this,r),(i=t.call(this,e)).attributes=e,i.silent=!(!o||!o.silent),i}return o(r,[{key:"visitBoolOpNode",value:function(e){this.silent||k(u(r.prototype),"visitBoolOpNode",this).call(this,e);const{x:t,y:n}=this.acceptLeafs(e);return e.token.type===exports.TokenType.BoolAnd?t&&n:t||n}},{key:"visitOpNode",value:function(e){this.silent||k(u(r.prototype),"visitOpNode",this).call(this,e);const{x:t,y:n}=this.acceptLeafs(e);switch(e.token.type){case exports.TokenType.ArEq:return t===n;case exports.TokenType.ArNotEq:return t!==n;case exports.TokenType.ArGre:return t>=n;case exports.TokenType.ArLse:return t<=n;case exports.TokenType.ArGr:return t>n;case exports.TokenType.ArLs:return t<n;case exports.TokenType.ArPlus:return t+n;case exports.TokenType.ArMinus:return t-n;case exports.TokenType.ArMul:return t*n;case exports.TokenType.ArDiv:return t/n;default:return!1}}},{key:"visitValueNode",value:function(e){return this.silent||k(u(r.prototype),"visitValueNode",this).call(this,e),e.token.value}},{key:"visitAttributeNode",value:function(e){return this.silent||k(u(r.prototype),"visitAttributeNode",this).call(this,e),this.attributes[e.token.value]}},{key:"visitFunctionNode",value:function(e){return this.silent||k(u(r.prototype),"visitFunctionNode",this).call(this,e),e.func.calc(this.attributes)}}]),r}(),D=function(){function e(t){n(this,e),this.args=t}return o(e,[{key:"calc",value:function(e){return 0}},{key:"evaluateArguments",value:function(e){return this.args.map(t=>{if(t instanceof g)return t.accept(new P(e));if("string"==typeof t.value){if("number"!=typeof e[t.value]){const{position:e}=t;throw new m("Аргумент функции должен быть числовым типом",e)}return e[t.value]}return t.value})}},{key:"check",value:function(e,t){return this.evaluateArguments(e).length!==t?new Error("Передано неверное количество аргументов"):null}}]),e}(),F=function(e){s(r,D);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,[{key:"calc",value:function(e){const[t]=k(u(r.prototype),"evaluateArguments",this).call(this,e);return+Math.sin(t).toFixed(3)}},{key:"check",value:function(e){return k(u(r.prototype),"check",this).call(this,e,r.ArgsCount)}}]),r}();F.ArgsCount=1,F.Name="sin";let I=function(e){s(r,D);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,[{key:"calc",value:function(e){const[t]=k(u(r.prototype),"evaluateArguments",this).call(this,e);return+Math.asin(t).toFixed(3)}},{key:"check",value:function(e){return k(u(r.prototype),"check",this).call(this,e,r.ArgsCount)}}]),r}();I.ArgsCount=1,I.Name="arcsin";let _=function(e){s(r,D);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,[{key:"calc",value:function(e){const[t]=k(u(r.prototype),"evaluateArguments",this).call(this,e);return+Math.cos(t).toFixed(3)}},{key:"check",value:function(e){return k(u(r.prototype),"check",this).call(this,e,r.ArgsCount)}}]),r}();_.ArgsCount=1,_.Name="cos";let R=function(e){s(r,D);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,[{key:"calc",value:function(e){const[t]=k(u(r.prototype),"evaluateArguments",this).call(this,e);return+Math.acos(t).toFixed(3)}},{key:"check",value:function(e){return k(u(r.prototype),"check",this).call(this,e,r.ArgsCount)}}]),r}();R.ArgsCount=1,R.Name="arccos";let U=function(e){s(r,D);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,[{key:"calc",value:function(e){const[t,n]=k(u(r.prototype),"evaluateArguments",this).call(this,e);return+Math.atan2(t,n).toFixed(3)}},{key:"check",value:function(e){return k(u(r.prototype),"check",this).call(this,e,r.ArgsCount)}}]),r}();U.ArgsCount=2,U.Name="arctan2";let K=function(e){s(r,D);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,[{key:"calc",value:function(e){const[t]=k(u(r.prototype),"evaluateArguments",this).call(this,e);return+Math.tan(t).toFixed(3)}},{key:"check",value:function(e){return k(u(r.prototype),"check",this).call(this,e,r.ArgsCount)}}]),r}();K.ArgsCount=1,K.Name="tan";let q=function(e){s(r,D);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,[{key:"calc",value:function(e){const[t]=k(u(r.prototype),"evaluateArguments",this).call(this,e);return+Math.atan(t).toFixed(3)}},{key:"check",value:function(e){return k(u(r.prototype),"check",this).call(this,e,r.ArgsCount)}}]),r}();q.ArgsCount=1,q.Name="arctan";let j=function(e){s(r,D);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,[{key:"calc",value:function(e){const[t]=k(u(r.prototype),"evaluateArguments",this).call(this,e);return+Math.sqrt(t).toFixed(3)}},{key:"check",value:function(e){return k(u(r.prototype),"check",this).call(this,e,r.ArgsCount)}}]),r}();j.ArgsCount=1,j.Name="sqrt";const G={[F.Name]:F,[I.Name]:I,[_.Name]:_,[R.Name]:R,[K.Name]:K,[q.Name]:q,[U.Name]:U,[j.Name]:j},V=e=>t.isValid(e)?e:"#'"+e+"'";let W=function(){function e(t){n(this,e),this.tokens=t,this.tree=null,this.currentPosition=0}return o(e,[{key:"value",get:function(){if(this.tree)return this.tree;this.tokens=function(e){let t=[];const n=[];for(const i of e){if(S(i)&&t.push(i),B(i)){if(![exports.TokenType.Between,exports.TokenType.Outside].includes(i.type))for(;w(n)&&(r=w(n),o=i,N.get(r.type)>N.get(o.type))&&w(n).type!==exports.TokenType.ExprOpen;)t.push(n.pop());n.push(i)}if(i.type===exports.TokenType.ExprOpen&&n.push(i),i.type===exports.TokenType.ExprClose){const e=i;for(;w(n)&&w(n).type!==exports.TokenType.ExprOpen;)t.push(n.pop());if(0===n.length)throw new m("Пропущена открывающая скобка",e.position);w(n).type===exports.TokenType.ExprOpen&&n.pop()}}var r,o;if(n.length){const e=w(n);if(e.type===exports.TokenType.ExprOpen)throw new m("Пропущена закрывающая скобка",e.position);t=[...t,...n.reverse()]}return t}(this.tokens);const e=[];for(;this.currentPosition<this.tokens.length;this.nextToken()){if(d.is(this.currentToken)&&e.push(new d(this.currentToken)),E.is(this.currentToken)&&e.push(new E(this.currentToken)),O.is(this.currentToken)){const t=G[this.currentToken.value];t||this.Error("Функция '"+this.currentToken.value+"' не определена",this.currentToken);const n=[];for(let r=0;r<t.ArgsCount;r++){const t=e.pop()||null;t instanceof g?n.push(t):t&&t.token&&n.push(t.token)}const r=new t(n);e.push(new O(this.currentToken,r))}if(g.is(this.currentToken)){const r=new g(this.currentToken);if([exports.TokenType.Between,exports.TokenType.Outside].includes(this.currentToken.type)){var t,n;const o=e.pop()||null,s=e.pop()||null;r.left=e.pop()||null,r.right=new d(i({},this.currentToken,{value:V(null==s?void 0:s.token.value)+" - "+V(null==o?void 0:o.token.value),position:{start:(null==s||null==(t=s.token.position)?void 0:t.start)||0,end:(null==o||null==(n=o.token.position)?void 0:n.end)||0}}))}else e.length>1&&(r.right=e.pop()||null),r.left=e.pop()||null;e.push(r)}if(A.is(this.currentToken)){const t=new A(this.currentToken);e.length>1&&(t.right=e.pop()||null),t.left=e.pop()||null,e.push(t)}}return this.tree=e.pop()||null,this.flashStack(e),this.checkRoot(),this.tree}},{key:"nextToken",value:function(){this.currentPosition+=1}},{key:"currentToken",get:function(){return this.tokens[this.currentPosition]}},{key:"checkRoot",value:function(){}},{key:"flashStack",value:function(e){if(this.tree&&e.length)for(;e.length;){const t=e.pop();t&&this.insert(this.tree,t)}}},{key:"insert",value:function(e,t){null!==e.right?this.insert(e.right,t):e.right=t}},{key:"Error",value:function(e,t){const{position:n}=t,{start:r,end:o}=n;throw new C(e,{start:r,end:o})}}]),e}(),H=function(e){s(r,b);var t=f(r);function r(e,o){var i;return void 0===o&&(o=T),n(this,r),(i=t.call(this,e,o)).position=o,i.name="ExpressionTokenizer",i}return o(r)}(),z=function(){function e(t,r,o){void 0===o&&(o=[]),n(this,e),this.acceptMap=new Map,this.value=t,this.tokenType=r,o.map(e=>this.acceptMap.set(e.value,e))}return o(e,[{key:"accept",value:function(e){return this.acceptMap.get(e)||null}}]),e}(),Q=function(){function e(){n(this,e)}return o(e,null,[{key:"isChar",value:function(e){return"string"==typeof e&&1===e.length}},{key:"isDigit",value:function(e){return this.isChar(e)&&/\d/.test(e)}},{key:"isLetter",value:function(e){return this.isChar(e)&&/\w/.test(e)}},{key:"isWhiteSpace",value:function(t){return this.isChar(t)&&t===e.WHITE_SPACE}},{key:"isLetterOrDigit",value:function(t){return e.isLetter(t)||e.isDigit(t)}},{key:"isUnderscore",value:function(t){return e.isChar(t)&&t===e.UNDERSCORE}},{key:"isFloating",value:function(t){return e.isChar(t)&&("f"===t||"F"===t)}},{key:"escapeSpecChars",value:function(e){return e.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,'\\"').replace(/\t/g,"\\\\t").replace(/\v/g,"\\\\v").replace(/\0/g,"\\\\0").replace(/\f/g,"\\\\f").replace(/\n/g,"\\\\n").replace(/\r/g,"\\\\r")}},{key:"unEscapeSpecChars",value:function(e){return e.replace(/\\'/g,"'").replace(/\\"/g,'"').replace(/\\\\/g,"\\").replace(/\\\\t/g,"\t").replace(/\\\\v/g,"\v").replace(/\\\\0/g,"\0").replace(/\\\\f/g,"\f").replace(/\\\\n/g,"\n").replace(/\\\\r/g,"\r")}}]),e}();function Y(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}Q.LEFT_BRACKET="{",Q.OPEN_BRACKET="(",Q.BETWEEN="between",Q.OUTSIDE="!between",Q.SINGLE_QUOTE="'",Q.DOUBLE_QUOTE='"',Q.HASH_SYMBOL="#",Q.RIGHT_BRACKET="}",Q.CLOSE_BRACKET=")",Q.BACK_SLASH="\\",Q.WHITE_SPACE=" ",Q.UNDERSCORE="_",Q.PERCENTAGE="%",Q.POINT=".";let J=o((function e(){n(this,e)}));J.sToMs=e=>1e3*e,J.mToMs=e=>60*J.sToMs(e),J.hToMs=e=>60*J.mToMs(e),J.dToMs=e=>24*J.hToMs(e),J.mthToMs=e=>30*J.dToMs(e),J.yToMs=e=>365*J.mthToMs(e);const X=new z("",exports.TokenType.Null,[new z(Q.BETWEEN,exports.TokenType.Between),new z(Q.OUTSIDE,exports.TokenType.Outside),new z(">",exports.TokenType.ArGr,[new z("=",exports.TokenType.ArGre)]),new z("<",exports.TokenType.ArLs,[new z("=",exports.TokenType.ArLse)]),new z("!",exports.TokenType.BoolNot,[new z("=",exports.TokenType.ArNotEq)]),new z("&",exports.TokenType.Null,[new z("&",exports.TokenType.BoolAnd)]),new z("=",exports.TokenType.ArEq,[new z("=",exports.TokenType.ArEq)]),new z("|",exports.TokenType.Null,[new z("|",exports.TokenType.BoolOr)]),new z("+",exports.TokenType.ArPlus),new z("-",exports.TokenType.ArMinus),new z("*",exports.TokenType.ArMul),new z("/",exports.TokenType.ArDiv),new z("(",exports.TokenType.ExprOpen),new z(")",exports.TokenType.ExprClose),new z("[",exports.TokenType.ArrayOpen),new z("]",exports.TokenType.ArrayClose),new z(",",exports.TokenType.Separator)]);let Z=function(){function e(t){n(this,e),this.start=0,this.currentPosition=0,this.tokens=[],this.input=t||""}return o(e,[{key:"tokenize",value:function(){if(this.isEndOfString())return this.tokens;for(;;){const e=this.nextToken();if(!e)break;if(this.tokens.push(e),this.tokens.length>1e3&&this.Error("Привышен лимит запроса: 1000"),e.type===exports.TokenType.EndOfString)break}return this.tokens}},{key:"nextToken",value:function(){for(;this.currentPosition<this.input.length;this.nextSymbol()){if(Q.isWhiteSpace(this.current))continue;if(this.resetStart(),this.input.slice(this.currentPosition).startsWith(Q.OUTSIDE))return this.currentPosition+=Q.OUTSIDE.length,this.createToken(exports.TokenType.Outside,Q.OUTSIDE);if(this.input.slice(this.currentPosition).startsWith(Q.BETWEEN))return this.currentPosition+=Q.BETWEEN.length,this.createToken(exports.TokenType.Between,Q.BETWEEN);const e=X.accept(this.current);if(null!==e)return this.captureSpecial(e);if(Q.isDigit(this.current)||this.current===Q.POINT)return this.captureNumber();if(Q.isLetter(this.current)||Q.isUnderscore(this.current))return this.captureIdentifier();if(this.current===Q.LEFT_BRACKET)return this.captureDynamicIdentifier();if(this.current===Q.DOUBLE_QUOTE||this.current===Q.SINGLE_QUOTE)return this.captureString();if(this.current===Q.HASH_SYMBOL)return this.captureDate()}return this.resetStart(),this.createToken(exports.TokenType.EndOfString)}},{key:"resetStart",value:function(){this.start=this.currentPosition}},{key:"createToken",value:function(e,t){void 0===t&&(t=null);const n=this.currentPosition-(e===exports.TokenType.EndOfString?0:1);return new v(e,t,{start:this.start,end:n})}},{key:"nextSymbol",value:function(){this.currentPosition+=1}},{key:"current",get:function(){return this.input[this.currentPosition]}},{key:"captureSpecial",value:function(e){let t=this.current;for(this.nextSymbol();this.currentPosition<this.input.length;this.nextSymbol()){const n=e.accept(this.current);if(null===n||n.tokenType===exports.TokenType.Null)break;t+=this.current,e=n}return this.current&&Q.isDigit(this.current)&&e.tokenType===exports.TokenType.ArMinus?this.createToken(exports.TokenType.Number,-(this.captureNumber().value||0)):(e.tokenType===exports.TokenType.Null&&this.Error("Неизвеcтная операция '"+e.value+"'"),this.createToken(e.tokenType,t))}},{key:"captureNumber",value:function(){let e="",t=!1;for(;this.currentPosition<this.input.length&&!Q.isWhiteSpace(this.current)&&(Q.isDigit(this.current)||Q.isFloating(this.current)||this.current===Q.POINT);this.nextSymbol())this.current===Q.POINT&&(t=!0),e+=this.current;t&&Q.isFloating(e[e.length-1])&&(e=e.slice(0,-1));const n=parseFloat(e);return Number.isNaN(n)&&this.Error("Неверный числовой формат: "+e),this.createToken(exports.TokenType.Number,n)}},{key:"captureIdentifier",value:function(){let e="";for(;this.currentPosition<this.input.length&&(Q.isLetterOrDigit(this.current)||Q.isUnderscore(this.current));this.nextSymbol())e+=this.current;if(this.current===Q.OPEN_BRACKET){const t=this.tokens.some(e=>e.type===exports.TokenType.Between),n=this.tokens.some(e=>e.type===exports.TokenType.Outside);return this.createToken(n?exports.TokenType.Outside:t?exports.TokenType.Between:exports.TokenType.Function,e)}return"true"===e||"True"===e||"TRUE"===e?this.createToken(exports.TokenType.Terminal,!0):"false"===e||"False"===e||"FALSE"===e?this.createToken(exports.TokenType.Terminal,!1):"in"===e||"IN"===e?this.createToken(exports.TokenType.ArIn):this.createToken(exports.TokenType.Identifier,e)}},{key:"captureDynamicIdentifier",value:function(){this.nextSymbol();let e="";for(;this.currentPosition<this.input.length;this.nextSymbol()){if(this.current===Q.RIGHT_BRACKET){this.nextSymbol();break}e+=this.current}return this.createToken(exports.TokenType.DynamicIdentifier,"null"===e||"Null"===e||"NULL"===e?null:e)}},{key:"captureString",value:function(){let e="",t=!1;const n=this.current;for(this.nextSymbol();this.currentPosition<this.input.length;this.nextSymbol())if(t||this.current!==Q.BACK_SLASH){if(!t&&this.current===n)return this.nextSymbol(),this.createToken(exports.TokenType.String,e);e+=this.current,t=!1}else t=!0;this.Error("Открытая строка")}},{key:"captureDate",value:function(){if(this.nextSymbol(),![Q.SINGLE_QUOTE,Q.DOUBLE_QUOTE,Q.BACK_SLASH].includes(this.current))return this.captureTimeSpan();const e=this.captureString();return this.createToken(exports.TokenType.Date,e.value)}},{key:"captureTimeSpan",value:function(){let e="";for(;this.currentPosition<this.input.length&&Q.isDigit(this.current);this.nextSymbol())e+=this.current;const t=parseFloat(e);Number.isNaN(t)&&this.Error("Неверный формат числа для значения timespan: "+e+". Должно быть положительным целочисленным значением."),Q.isLetter(this.current)||this.Error("Для значения задана неверная единица измерения "+this.current);let n="";for(;Q.isLetter(this.current);)n+=this.current,this.nextSymbol();let r=0;switch(n){case"ms":r=t;break;case"s":r=J.sToMs(t);break;case"m":r=J.mToMs(t);break;case"h":r=J.hToMs(t);break;case"d":r=J.dToMs(t);break;case"mth":r=J.mthToMs(t);break;case"y":r=J.yToMs(t);break;default:this.Error("Неверная единица измерения для timespan: "+n)}return this.createToken(exports.TokenType.TimeSpan,r)}},{key:"isEndOfString",value:function(){return this.tokens.length>0&&this.tokens[this.tokens.length-1].type===exports.TokenType.EndOfString}},{key:"Error",value:function(e){throw new H(e,{start:this.start,end:this.start})}}]),e}(),$=function(e){s(r,L);var t=f(r);function r(){return n(this,r),t.apply(this,arguments)}return o(r,[{key:"visitBoolOpNode",value:function(e){k(u(r.prototype),"visitBoolOpNode",this).call(this,e);const t=e.left&&e.left.accept(this),n=e.right&&e.right.accept(this);return e.left instanceof A&&e.right instanceof A?(this.checkBoolOperations(e.token.type,[...t.boolOperations,...n.boolOperations]),{boolOperations:[...t.boolOperations,e.token.type,...n.boolOperations],expressions:[...t.expressions,...n.expressions]}):e.right instanceof A?(this.checkBoolOperations(e.token.type,n.boolOperations),{boolOperations:[e.token.type,...n.boolOperations],expressions:[t,...n.expressions]}):e.left instanceof A?(this.checkBoolOperations(e.token.type,t.boolOperations),{boolOperations:[...t.boolOperations,e.token.type],expressions:[...t.expressions,n]}):{boolOperations:[e.token.type],expressions:[t,n]}}},{key:"visitOpNode",value:function(e){var t;k(u(r.prototype),"visitOpNode",this).call(this,e),this.checkExpressionSimple(e);const n=e.left&&e.left.accept(this),o=e.right&&(null==(t=e.right)?void 0:t.accept(this));return{attribute:n,operation:e.token.type,value:o}}},{key:"visitValueNode",value:function(e){return k(u(r.prototype),"visitValueNode",this).call(this,e),e.token.value}},{key:"visitAttributeNode",value:function(e){return k(u(r.prototype),"visitAttributeNode",this).call(this,e),e.token.value}},{key:"checkBoolOperations",value:function(e,t){if(t.some(t=>t!==e))throw new m("Выражение должно использовать одинаковые булевы операторы")}},{key:"checkExpressionSimple",value:function(e){if(!(e.left instanceof E&&e.right instanceof d||e.right instanceof d))throw new m("Выражение должно быть простым")}}]),r}();const ee=e=>Y(e)&&"boolOperations"in e,te=e=>Y(e)&&"attribute"in e;let ne=function(){function e(t){n(this,e),this.result=null,this.tokenizer=new Z(t)}return o(e,[{key:"value",get:function(){if(this.result)return this.result;try{const e=this.tokenizer.tokenize(),t=new W(e).value,n=t&&t.accept(new $);return this.result=ee(n)?n:te(n)?{boolOperations:[],expressions:[n]}:{boolOperations:[],expressions:[]},this.result}catch(e){return e}}}]),e}(),re=function(){function e(t){n(this,e),this.attributes=t}return o(e,[{key:"evaluate",value:function(e,t){try{const n=new Z(e).tokenize(),r=new W(n).value;return r&&r.accept(new P(this.attributes,t))}catch(e){return e}}}]),e}(),oe=function(){function e(t){n(this,e),this.attributes=t}return o(e,[{key:"lint",value:function(e){try{const t=new Z(e).tokenize(),n=new W(t).value;return n&&n.accept(new M(this.attributes)),null}catch(e){return e}}}]),e}();exports.ArcCos=R,exports.ArcSin=I,exports.ArcTan=q,exports.ArcTan2=U,exports.AttributeNode=E,exports.BoolOperationNode=A,exports.Char=Q,exports.ConditionEvaluator=re,exports.ConditionInterpreter=ne,exports.ConditionLinter=oe,exports.ConditionVisitor=$,exports.Cos=_,exports.DEFAULT_TOKEN_POSITION=T,exports.EqlFunction=D,exports.EqlFunctions=G,exports.EvaluateVisitor=P,exports.ExpressionAst=W,exports.ExpressionAstError=C,exports.ExpressionNode=x,exports.ExpressionTokenizer=Z,exports.ExpressionTokenizerError=H,exports.ExpressionVisitor=L,exports.FunctionNode=O,exports.LintError=m,exports.LintVisitor=M,exports.OperationNode=g,exports.Sin=F,exports.Sqrt=j,exports.Tan=K,exports.Time=J,exports.Token=v,exports.TokenError=b,exports.ValueNode=d,exports.isBoolResult=ee,exports.isExpression=te,exports.isObject=Y; | ||
//# sourceMappingURL=condition.cjs.production.min.js.map |
@@ -0,1 +1,3 @@ | ||
import { isValid } from 'date-fns'; | ||
function _classCallCheck(instance, Constructor) { | ||
@@ -20,5 +22,26 @@ if (!(instance instanceof Constructor)) { | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inherits(subClass, superClass) { | ||
@@ -36,2 +59,5 @@ if (typeof superClass !== "function" && superClass !== null) { | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
@@ -62,3 +88,3 @@ } | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
@@ -136,2 +162,4 @@ } catch (e) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
@@ -170,3 +198,3 @@ | ||
function _get(target, property, receiver) { | ||
function _get() { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
@@ -182,3 +210,3 @@ _get = Reflect.get; | ||
if (desc.get) { | ||
return desc.get.call(receiver); | ||
return desc.get.call(arguments.length < 3 ? target : receiver); | ||
} | ||
@@ -190,47 +218,5 @@ | ||
return _get(target, property, receiver || target); | ||
return _get.apply(this, arguments); | ||
} | ||
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); | ||
} | ||
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; | ||
} | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { | ||
var it; | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
return function () { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
it = o[Symbol.iterator](); | ||
return it.next.bind(it); | ||
} | ||
var TokenType; | ||
@@ -268,9 +254,11 @@ | ||
TokenType[TokenType["Function"] = 28] = "Function"; | ||
TokenType[TokenType["Between"] = 29] = "Between"; | ||
TokenType[TokenType["Outside"] = 30] = "Outside"; | ||
})(TokenType || (TokenType = {})); | ||
var DEFAULT_TOKEN_POSITION = { | ||
const DEFAULT_TOKEN_POSITION = { | ||
start: 0, | ||
end: 0 | ||
}; | ||
var Token = function Token(type, value, position) { | ||
let Token = /*#__PURE__*/_createClass(function Token(type, value, position) { | ||
if (position === void 0) { | ||
@@ -285,5 +273,5 @@ position = DEFAULT_TOKEN_POSITION; | ||
this.position = position; | ||
}; | ||
}); | ||
var ExpressionNode = /*#__PURE__*/function () { | ||
let ExpressionNode = /*#__PURE__*/function () { | ||
function ExpressionNode(token, left, right) { | ||
@@ -317,3 +305,3 @@ if (left === void 0) { | ||
}(); | ||
var ValueNode = /*#__PURE__*/function (_ExpressionNode) { | ||
let ValueNode = /*#__PURE__*/function (_ExpressionNode) { | ||
_inherits(ValueNode, _ExpressionNode); | ||
@@ -339,3 +327,3 @@ | ||
ValueNode.TOKENS = [TokenType.String, TokenType.Number, TokenType.DynamicIdentifier, TokenType.Date]; | ||
var AttributeNode = /*#__PURE__*/function (_ExpressionNode2) { | ||
let AttributeNode = /*#__PURE__*/function (_ExpressionNode2) { | ||
_inherits(AttributeNode, _ExpressionNode2); | ||
@@ -361,3 +349,3 @@ | ||
AttributeNode.TOKENS = [TokenType.Identifier]; | ||
var OperationNode = /*#__PURE__*/function (_ExpressionNode3) { | ||
let OperationNode = /*#__PURE__*/function (_ExpressionNode3) { | ||
_inherits(OperationNode, _ExpressionNode3); | ||
@@ -382,4 +370,4 @@ | ||
}(ExpressionNode); | ||
OperationNode.TOKENS = [TokenType.ArEq, TokenType.ArNotEq, TokenType.ArGr, TokenType.ArGre, TokenType.ArLs, TokenType.ArLse, TokenType.ArPlus, TokenType.ArMinus, TokenType.ArDiv, TokenType.ArMul]; | ||
var BoolOperationNode = /*#__PURE__*/function (_ExpressionNode4) { | ||
OperationNode.TOKENS = [TokenType.ArEq, TokenType.ArNotEq, TokenType.ArGr, TokenType.ArGre, TokenType.ArLs, TokenType.ArLse, TokenType.ArPlus, TokenType.ArMinus, TokenType.ArDiv, TokenType.ArMul, TokenType.Between, TokenType.Outside]; | ||
let BoolOperationNode = /*#__PURE__*/function (_ExpressionNode4) { | ||
_inherits(BoolOperationNode, _ExpressionNode4); | ||
@@ -405,3 +393,3 @@ | ||
BoolOperationNode.TOKENS = [TokenType.BoolAnd, TokenType.BoolOr]; | ||
var FunctionNode = /*#__PURE__*/function (_ExpressionNode5) { | ||
let FunctionNode = /*#__PURE__*/function (_ExpressionNode5) { | ||
_inherits(FunctionNode, _ExpressionNode5); | ||
@@ -440,3 +428,3 @@ | ||
var OperationPrecedence = /*#__PURE__*/new Map(); | ||
const OperationPrecedence = /*#__PURE__*/new Map(); | ||
OperationPrecedence.set(TokenType.ExprOpen, 0); | ||
@@ -457,4 +445,6 @@ OperationPrecedence.set(TokenType.ExprClose, 0); | ||
OperationPrecedence.set(TokenType.Function, 5); | ||
OperationPrecedence.set(TokenType.Between, 5); | ||
OperationPrecedence.set(TokenType.Outside, 5); | ||
var TokenError = /*#__PURE__*/function (_Error) { | ||
let TokenError = /*#__PURE__*/function (_Error) { | ||
_inherits(TokenError, _Error); | ||
@@ -475,5 +465,6 @@ | ||
_this.position = position; | ||
var _position = position, | ||
start = _position.start, | ||
end = _position.end; | ||
const { | ||
start, | ||
end | ||
} = position; | ||
_this.message = _this.name + "(c\u0438\u043C\u0432\u043E\u043B: " + (start + 1) + ", " + (end + 1) + "):" + message + "."; | ||
@@ -483,6 +474,6 @@ return _this; | ||
return TokenError; | ||
return _createClass(TokenError); | ||
}( /*#__PURE__*/_wrapNativeSuper(Error)); | ||
var LintError = /*#__PURE__*/function (_TokenError) { | ||
let LintError = /*#__PURE__*/function (_TokenError) { | ||
_inherits(LintError, _TokenError); | ||
@@ -507,20 +498,12 @@ | ||
return LintError; | ||
return _createClass(LintError); | ||
}(TokenError); | ||
var last = function last(el) { | ||
return el[el.length - 1]; | ||
}; | ||
const last = el => el[el.length - 1]; | ||
var isOperand = function isOperand(token) { | ||
return ValueNode.is(token) || AttributeNode.is(token); | ||
}; | ||
const isOperand = token => ValueNode.is(token) || AttributeNode.is(token); | ||
var isOperation = function isOperation(token) { | ||
return OperationNode.is(token) || BoolOperationNode.is(token) || FunctionNode.is(token); | ||
}; | ||
const isOperation = token => OperationNode.is(token) || BoolOperationNode.is(token) || FunctionNode.is(token); | ||
var isHigherPrecedence = function isHigherPrecedence(tokenOne, tokenTwo) { | ||
return OperationPrecedence.get(tokenOne.type) > OperationPrecedence.get(tokenTwo.type); | ||
}; // TODO parentheses | ||
const isHigherPrecedence = (tokenOne, tokenTwo) => OperationPrecedence.get(tokenOne.type) > OperationPrecedence.get(tokenTwo.type); // TODO parentheses | ||
@@ -533,8 +516,6 @@ /* | ||
function shuntingYard(tokens) { | ||
var output = []; | ||
var operators = []; | ||
let output = []; | ||
const operators = []; | ||
for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) { | ||
var token = _step.value; | ||
for (const token of tokens) { | ||
if (isOperand(token)) { | ||
@@ -545,4 +526,6 @@ output.push(token); | ||
if (isOperation(token)) { | ||
while (last(operators) && isHigherPrecedence(last(operators), token) && last(operators).type !== TokenType.ExprOpen) { | ||
output.push(operators.pop()); | ||
if (![TokenType.Between, TokenType.Outside].includes(token.type)) { | ||
while (last(operators) && isHigherPrecedence(last(operators), token) && last(operators).type !== TokenType.ExprOpen) { | ||
output.push(operators.pop()); | ||
} | ||
} | ||
@@ -558,3 +541,3 @@ | ||
if (token.type === TokenType.ExprClose) { | ||
var closeParen = token; | ||
const closeParen = token; | ||
@@ -576,3 +559,3 @@ while (last(operators) && last(operators).type !== TokenType.ExprOpen) { | ||
if (operators.length) { | ||
var lastToken = last(operators); | ||
const lastToken = last(operators); | ||
@@ -583,3 +566,3 @@ if (lastToken.type === TokenType.ExprOpen) { | ||
output = [].concat(output, operators.reverse()); | ||
output = [...output, ...operators.reverse()]; | ||
} | ||
@@ -590,3 +573,3 @@ | ||
var ExpressionAstError = /*#__PURE__*/function (_TokenError) { | ||
let ExpressionAstError = /*#__PURE__*/function (_TokenError) { | ||
_inherits(ExpressionAstError, _TokenError); | ||
@@ -611,6 +594,6 @@ | ||
return ExpressionAstError; | ||
return _createClass(ExpressionAstError); | ||
}(TokenError); | ||
var ExpressionVisitor = /*#__PURE__*/function () { | ||
let ExpressionVisitor = /*#__PURE__*/function () { | ||
function ExpressionVisitor() { | ||
@@ -663,3 +646,3 @@ _classCallCheck(this, ExpressionVisitor); | ||
var LintVisitor = /*#__PURE__*/function (_ExpressionVisitor) { | ||
let LintVisitor = /*#__PURE__*/function (_ExpressionVisitor) { | ||
_inherits(LintVisitor, _ExpressionVisitor); | ||
@@ -722,3 +705,3 @@ | ||
value: function checkBoolOpNode(node) { | ||
var message = "\u041E\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044F \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u0435 \u0432\u0438\u0434\u0430 'a == 2 " + node.token.value + " b == 3'"; | ||
const message = "\u041E\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044F \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u0435 \u0432\u0438\u0434\u0430 'a == 2 " + node.token.value + " b == 3'"; | ||
@@ -744,3 +727,5 @@ if (!this.isOperationNode(node.left)) { | ||
if (node.left) { | ||
var token = node.left.token; | ||
const { | ||
token | ||
} = node.left; | ||
this.Error("'" + token.value + "' \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0435 \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u044F", token); | ||
@@ -750,4 +735,6 @@ } | ||
if (node.right) { | ||
var _token = node.right.token; | ||
this.Error("'" + _token.value + "' \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0435 \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u044F", _token); | ||
const { | ||
token | ||
} = node.right; | ||
this.Error("'" + token.value + "' \u043D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0435 \u0432\u044B\u0440\u0430\u0436\u0435\u043D\u0438\u044F", token); | ||
} | ||
@@ -765,3 +752,3 @@ } | ||
value: function checkFunctionNode(node) { | ||
var result = node.func.check(this.attributes); | ||
const result = node.func.check(this.attributes); | ||
@@ -775,3 +762,5 @@ if (result instanceof Error) { | ||
value: function Error(description, token) { | ||
var position = token.position; | ||
const { | ||
position | ||
} = token; | ||
throw new LintError(description, position); | ||
@@ -782,7 +771,7 @@ } | ||
value: function acceptLeafs(node) { | ||
var x = node.left && node.left.accept(this); | ||
var y = node.right && node.right.accept(this); | ||
const x = node.left && node.left.accept(this); | ||
const y = node.right && node.right.accept(this); | ||
return { | ||
x: x, | ||
y: y | ||
x, | ||
y | ||
}; | ||
@@ -800,3 +789,3 @@ } | ||
var EvaluateVisitor = /*#__PURE__*/function (_LintVisitor) { | ||
let EvaluateVisitor = /*#__PURE__*/function (_LintVisitor) { | ||
_inherits(EvaluateVisitor, _LintVisitor); | ||
@@ -824,6 +813,6 @@ | ||
var _this$acceptLeafs = this.acceptLeafs(node), | ||
x = _this$acceptLeafs.x, | ||
y = _this$acceptLeafs.y; | ||
const { | ||
x, | ||
y | ||
} = this.acceptLeafs(node); | ||
return node.token.type === TokenType.BoolAnd ? x && y : x || y; | ||
@@ -838,5 +827,6 @@ } | ||
var _this$acceptLeafs2 = this.acceptLeafs(node), | ||
x = _this$acceptLeafs2.x, | ||
y = _this$acceptLeafs2.y; | ||
const { | ||
x, | ||
y | ||
} = this.acceptLeafs(node); | ||
@@ -910,3 +900,3 @@ switch (node.token.type) { | ||
var EqlFunction = /*#__PURE__*/function () { | ||
let EqlFunction = /*#__PURE__*/function () { | ||
function EqlFunction(args) { | ||
@@ -927,3 +917,3 @@ _classCallCheck(this, EqlFunction); | ||
value: function evaluateArguments(attributes) { | ||
return this.args.map(function (arg) { | ||
return this.args.map(arg => { | ||
if (arg instanceof OperationNode) { | ||
@@ -934,6 +924,8 @@ return arg.accept(new EvaluateVisitor(attributes)); | ||
if (typeof arg.value === 'string') { | ||
var value = attributes[arg.value]; | ||
const value = attributes[arg.value]; | ||
if (typeof value !== 'number') { | ||
var position = arg.position; | ||
const { | ||
position | ||
} = arg; | ||
throw new LintError('Аргумент функции должен быть числовым типом', position); | ||
@@ -951,3 +943,3 @@ } | ||
value: function check(attributes, argsCount) { | ||
var args = this.evaluateArguments(attributes); | ||
const args = this.evaluateArguments(attributes); | ||
@@ -965,3 +957,3 @@ if (args.length !== argsCount) { | ||
var Sin = /*#__PURE__*/function (_EqlFunction) { | ||
let Sin = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(Sin, _EqlFunction); | ||
@@ -980,4 +972,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(Sin.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(Sin.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -998,3 +989,3 @@ return +Math.sin(arg).toFixed(3); | ||
var ArcSin = /*#__PURE__*/function (_EqlFunction) { | ||
let ArcSin = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(ArcSin, _EqlFunction); | ||
@@ -1013,4 +1004,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(ArcSin.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(ArcSin.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1031,3 +1021,3 @@ return +Math.asin(arg).toFixed(3); | ||
var Cos = /*#__PURE__*/function (_EqlFunction) { | ||
let Cos = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(Cos, _EqlFunction); | ||
@@ -1046,4 +1036,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(Cos.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(Cos.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1064,3 +1053,3 @@ return +Math.cos(arg).toFixed(3); | ||
var ArcCos = /*#__PURE__*/function (_EqlFunction) { | ||
let ArcCos = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(ArcCos, _EqlFunction); | ||
@@ -1079,4 +1068,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(ArcCos.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(ArcCos.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1097,3 +1085,3 @@ return +Math.acos(arg).toFixed(3); | ||
var ArcTan2 = /*#__PURE__*/function (_EqlFunction) { | ||
let ArcTan2 = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(ArcTan2, _EqlFunction); | ||
@@ -1112,5 +1100,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(ArcTan2.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg1 = _get$call[0], | ||
arg2 = _get$call[1]; | ||
const [arg1, arg2] = _get(_getPrototypeOf(ArcTan2.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1131,3 +1117,3 @@ return +Math.atan2(arg1, arg2).toFixed(3); | ||
var Tan = /*#__PURE__*/function (_EqlFunction) { | ||
let Tan = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(Tan, _EqlFunction); | ||
@@ -1146,4 +1132,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(Tan.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(Tan.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1164,3 +1149,3 @@ return +Math.tan(arg).toFixed(3); | ||
var ArcTan = /*#__PURE__*/function (_EqlFunction) { | ||
let ArcTan = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(ArcTan, _EqlFunction); | ||
@@ -1179,4 +1164,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(ArcTan.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(ArcTan.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1197,3 +1181,3 @@ return +Math.atan(arg).toFixed(3); | ||
var Sqrt = /*#__PURE__*/function (_EqlFunction) { | ||
let Sqrt = /*#__PURE__*/function (_EqlFunction) { | ||
_inherits(Sqrt, _EqlFunction); | ||
@@ -1212,4 +1196,3 @@ | ||
value: function calc(attributes) { | ||
var _get$call = _get(_getPrototypeOf(Sqrt.prototype), "evaluateArguments", this).call(this, attributes), | ||
arg = _get$call[0]; | ||
const [arg] = _get(_getPrototypeOf(Sqrt.prototype), "evaluateArguments", this).call(this, attributes); | ||
@@ -1230,6 +1213,16 @@ return +Math.sqrt(arg).toFixed(3); | ||
var _EqlFunctions; | ||
var EqlFunctions = (_EqlFunctions = {}, _EqlFunctions[Sin.Name] = Sin, _EqlFunctions[ArcSin.Name] = ArcSin, _EqlFunctions[Cos.Name] = Cos, _EqlFunctions[ArcCos.Name] = ArcCos, _EqlFunctions[Tan.Name] = Tan, _EqlFunctions[ArcTan.Name] = ArcTan, _EqlFunctions[ArcTan2.Name] = ArcTan2, _EqlFunctions[Sqrt.Name] = Sqrt, _EqlFunctions); | ||
const EqlFunctions = { | ||
[Sin.Name]: Sin, | ||
[ArcSin.Name]: ArcSin, | ||
[Cos.Name]: Cos, | ||
[ArcCos.Name]: ArcCos, | ||
[Tan.Name]: Tan, | ||
[ArcTan.Name]: ArcTan, | ||
[ArcTan2.Name]: ArcTan2, | ||
[Sqrt.Name]: Sqrt | ||
}; | ||
var ExpressionAst = /*#__PURE__*/function () { | ||
const formatValue = value => !isValid(value) ? "#'" + value + "'" : value; | ||
let ExpressionAst = /*#__PURE__*/function () { | ||
function ExpressionAst(tokens) { | ||
@@ -1246,51 +1239,2 @@ _classCallCheck(this, ExpressionAst); | ||
_createClass(ExpressionAst, [{ | ||
key: "nextToken", | ||
value: function nextToken() { | ||
this.currentPosition += 1; | ||
} // @ts-ignore | ||
}, { | ||
key: "checkRoot", | ||
value: function checkRoot() { | ||
if (!this.tree) { | ||
return; | ||
} | ||
} | ||
}, { | ||
key: "flashStack", | ||
value: function flashStack(stack) { | ||
if (!this.tree || !stack.length) { | ||
return; | ||
} | ||
while (stack.length) { | ||
var node = stack.pop(); | ||
if (node) { | ||
this.insert(this.tree, node); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "insert", | ||
value: function insert(tree, node) { | ||
if (tree.right === null) { | ||
tree.right = node; | ||
return; | ||
} else { | ||
this.insert(tree.right, node); | ||
} | ||
} | ||
}, { | ||
key: "Error", | ||
value: function Error(description, token) { | ||
var position = token.position; | ||
var start = position.start, | ||
end = position.end; | ||
throw new ExpressionAstError(description, { | ||
start: start, | ||
end: end | ||
}); | ||
} | ||
}, { | ||
key: "value", | ||
@@ -1303,3 +1247,3 @@ get: function get() { | ||
this.tokens = shuntingYard(this.tokens); | ||
var stack = []; | ||
const stack = []; | ||
@@ -1316,3 +1260,3 @@ for (; this.currentPosition < this.tokens.length; this.nextToken()) { | ||
if (FunctionNode.is(this.currentToken)) { | ||
var FnConstructor = EqlFunctions[this.currentToken.value]; | ||
const FnConstructor = EqlFunctions[this.currentToken.value]; | ||
@@ -1323,6 +1267,6 @@ if (!FnConstructor) { | ||
var args = []; | ||
const args = []; | ||
for (var i = 0; i < FnConstructor.ArgsCount; i++) { | ||
var node = stack.pop() || null; | ||
for (let i = 0; i < FnConstructor.ArgsCount; i++) { | ||
const node = stack.pop() || null; | ||
@@ -1337,3 +1281,3 @@ if (node instanceof OperationNode) { | ||
var fn = new FnConstructor(args); | ||
const fn = new FnConstructor(args); | ||
stack.push(new FunctionNode(this.currentToken, fn)); | ||
@@ -1343,21 +1287,37 @@ } | ||
if (OperationNode.is(this.currentToken)) { | ||
var _node = new OperationNode(this.currentToken); | ||
const node = new OperationNode(this.currentToken); | ||
if (stack.length > 1) { | ||
_node.right = stack.pop() || null; | ||
if ([TokenType.Between, TokenType.Outside].includes(this.currentToken.type)) { | ||
var _value1$token$positio, _value2$token$positio; | ||
const value2 = stack.pop() || null; | ||
const value1 = stack.pop() || null; | ||
node.left = stack.pop() || null; | ||
node.right = new ValueNode(_extends({}, this.currentToken, { | ||
value: formatValue(value1 == null ? void 0 : value1.token.value) + " - " + formatValue(value2 == null ? void 0 : value2.token.value), | ||
position: { | ||
start: (value1 == null ? void 0 : (_value1$token$positio = value1.token.position) == null ? void 0 : _value1$token$positio.start) || 0, | ||
end: (value2 == null ? void 0 : (_value2$token$positio = value2.token.position) == null ? void 0 : _value2$token$positio.end) || 0 | ||
} | ||
})); | ||
} else { | ||
if (stack.length > 1) { | ||
node.right = stack.pop() || null; | ||
} | ||
node.left = stack.pop() || null; | ||
} | ||
_node.left = stack.pop() || null; | ||
stack.push(_node); | ||
stack.push(node); | ||
} | ||
if (BoolOperationNode.is(this.currentToken)) { | ||
var _node2 = new BoolOperationNode(this.currentToken); | ||
const node = new BoolOperationNode(this.currentToken); | ||
if (stack.length > 1) { | ||
_node2.right = stack.pop() || null; | ||
node.right = stack.pop() || null; | ||
} | ||
_node2.left = stack.pop() || null; | ||
stack.push(_node2); | ||
node.left = stack.pop() || null; | ||
stack.push(node); | ||
} | ||
@@ -1372,2 +1332,8 @@ } | ||
}, { | ||
key: "nextToken", | ||
value: function nextToken() { | ||
this.currentPosition += 1; | ||
} // @ts-ignore | ||
}, { | ||
key: "currentToken", | ||
@@ -1377,2 +1343,49 @@ get: function get() { | ||
} | ||
}, { | ||
key: "checkRoot", | ||
value: function checkRoot() { | ||
if (!this.tree) { | ||
return; | ||
} | ||
} | ||
}, { | ||
key: "flashStack", | ||
value: function flashStack(stack) { | ||
if (!this.tree || !stack.length) { | ||
return; | ||
} | ||
while (stack.length) { | ||
const node = stack.pop(); | ||
if (node) { | ||
this.insert(this.tree, node); | ||
} | ||
} | ||
} | ||
}, { | ||
key: "insert", | ||
value: function insert(tree, node) { | ||
if (tree.right === null) { | ||
tree.right = node; | ||
return; | ||
} else { | ||
this.insert(tree.right, node); | ||
} | ||
} | ||
}, { | ||
key: "Error", | ||
value: function Error(description, token) { | ||
const { | ||
position | ||
} = token; | ||
const { | ||
start, | ||
end | ||
} = position; | ||
throw new ExpressionAstError(description, { | ||
start, | ||
end | ||
}); | ||
} | ||
}]); | ||
@@ -1383,3 +1396,3 @@ | ||
var ExpressionTokenizerError = /*#__PURE__*/function (_TokenError) { | ||
let ExpressionTokenizerError = /*#__PURE__*/function (_TokenError) { | ||
_inherits(ExpressionTokenizerError, _TokenError); | ||
@@ -1404,9 +1417,7 @@ | ||
return ExpressionTokenizerError; | ||
return _createClass(ExpressionTokenizerError); | ||
}(TokenError); | ||
var OperationAccept = /*#__PURE__*/function () { | ||
let OperationAccept = /*#__PURE__*/function () { | ||
function OperationAccept(value, type, operations) { | ||
var _this = this; | ||
if (operations === void 0) { | ||
@@ -1421,5 +1432,3 @@ operations = []; | ||
this.tokenType = type; | ||
operations.map(function (opAccept) { | ||
return _this.acceptMap.set(opAccept.value, opAccept); | ||
}); | ||
operations.map(opAccept => this.acceptMap.set(opAccept.value, opAccept)); | ||
} | ||
@@ -1437,5 +1446,3 @@ | ||
var AcceptTree = /*#__PURE__*/new OperationAccept('', TokenType.Null, [/*#__PURE__*/new OperationAccept('>', TokenType.ArGr, [/*#__PURE__*/new OperationAccept('=', TokenType.ArGre)]), /*#__PURE__*/new OperationAccept('<', TokenType.ArLs, [/*#__PURE__*/new OperationAccept('=', TokenType.ArLse)]), /*#__PURE__*/new OperationAccept('!', TokenType.BoolNot, [/*#__PURE__*/new OperationAccept('=', TokenType.ArNotEq)]), /*#__PURE__*/new OperationAccept('&', TokenType.Null, [/*#__PURE__*/new OperationAccept('&', TokenType.BoolAnd)]), /*#__PURE__*/new OperationAccept('=', TokenType.ArEq, [/*#__PURE__*/new OperationAccept('=', TokenType.ArEq)]), /*#__PURE__*/new OperationAccept('|', TokenType.Null, [/*#__PURE__*/new OperationAccept('|', TokenType.BoolOr)]), /*#__PURE__*/new OperationAccept('+', TokenType.ArPlus), /*#__PURE__*/new OperationAccept('-', TokenType.ArMinus), /*#__PURE__*/new OperationAccept('*', TokenType.ArMul), /*#__PURE__*/new OperationAccept('/', TokenType.ArDiv), /*#__PURE__*/new OperationAccept('(', TokenType.ExprOpen), /*#__PURE__*/new OperationAccept(')', TokenType.ExprClose), /*#__PURE__*/new OperationAccept('[', TokenType.ArrayOpen), /*#__PURE__*/new OperationAccept(']', TokenType.ArrayClose), /*#__PURE__*/new OperationAccept(',', TokenType.Separator)]); | ||
var Char = /*#__PURE__*/function () { | ||
let Char = /*#__PURE__*/function () { | ||
function Char() { | ||
@@ -1496,2 +1503,4 @@ _classCallCheck(this, Char); | ||
Char.OPEN_BRACKET = '('; | ||
Char.BETWEEN = 'between'; | ||
Char.OUTSIDE = '!between'; | ||
Char.SINGLE_QUOTE = "'"; | ||
@@ -1508,32 +1517,26 @@ Char.DOUBLE_QUOTE = '"'; | ||
var Time = function Time() { | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
} | ||
let Time = /*#__PURE__*/_createClass(function Time() { | ||
_classCallCheck(this, Time); | ||
}; | ||
}); | ||
Time.sToMs = function (seconds) { | ||
return seconds * 1000; | ||
}; | ||
Time.sToMs = seconds => seconds * 1000; | ||
Time.mToMs = function (minutes) { | ||
return Time.sToMs(minutes) * 60; | ||
}; | ||
Time.mToMs = minutes => Time.sToMs(minutes) * 60; | ||
Time.hToMs = function (hours) { | ||
return Time.mToMs(hours) * 60; | ||
}; | ||
Time.hToMs = hours => Time.mToMs(hours) * 60; | ||
Time.dToMs = function (days) { | ||
return Time.hToMs(days) * 24; | ||
}; | ||
Time.dToMs = days => Time.hToMs(days) * 24; | ||
Time.mthToMs = function (months) { | ||
return Time.dToMs(months) * 30; | ||
}; | ||
Time.mthToMs = months => Time.dToMs(months) * 30; | ||
Time.yToMs = function (years) { | ||
return Time.mthToMs(years) * 365; | ||
}; | ||
Time.yToMs = years => Time.mthToMs(years) * 365; | ||
var TOKENIZER_MAX_SIZE = 1000; | ||
var ExpressionTokenizer = /*#__PURE__*/function () { | ||
const AcceptTree = /*#__PURE__*/new OperationAccept('', TokenType.Null, [/*#__PURE__*/new OperationAccept(Char.BETWEEN, TokenType.Between), /*#__PURE__*/new OperationAccept(Char.OUTSIDE, TokenType.Outside), /*#__PURE__*/new OperationAccept('>', TokenType.ArGr, [/*#__PURE__*/new OperationAccept('=', TokenType.ArGre)]), /*#__PURE__*/new OperationAccept('<', TokenType.ArLs, [/*#__PURE__*/new OperationAccept('=', TokenType.ArLse)]), /*#__PURE__*/new OperationAccept('!', TokenType.BoolNot, [/*#__PURE__*/new OperationAccept('=', TokenType.ArNotEq)]), /*#__PURE__*/new OperationAccept('&', TokenType.Null, [/*#__PURE__*/new OperationAccept('&', TokenType.BoolAnd)]), /*#__PURE__*/new OperationAccept('=', TokenType.ArEq, [/*#__PURE__*/new OperationAccept('=', TokenType.ArEq)]), /*#__PURE__*/new OperationAccept('|', TokenType.Null, [/*#__PURE__*/new OperationAccept('|', TokenType.BoolOr)]), /*#__PURE__*/new OperationAccept('+', TokenType.ArPlus), /*#__PURE__*/new OperationAccept('-', TokenType.ArMinus), /*#__PURE__*/new OperationAccept('*', TokenType.ArMul), /*#__PURE__*/new OperationAccept('/', TokenType.ArDiv), /*#__PURE__*/new OperationAccept('(', TokenType.ExprOpen), /*#__PURE__*/new OperationAccept(')', TokenType.ExprClose), /*#__PURE__*/new OperationAccept('[', TokenType.ArrayOpen), /*#__PURE__*/new OperationAccept(']', TokenType.ArrayClose), /*#__PURE__*/new OperationAccept(',', TokenType.Separator)]); | ||
const TOKENIZER_MAX_SIZE = 1000; | ||
let ExpressionTokenizer = /*#__PURE__*/function () { | ||
function ExpressionTokenizer(input) { | ||
@@ -1556,3 +1559,3 @@ _classCallCheck(this, ExpressionTokenizer); | ||
while (true) { | ||
var token = this.nextToken(); | ||
const token = this.nextToken(); | ||
@@ -1585,4 +1588,15 @@ if (!token) { | ||
this.resetStart(); | ||
var acceptOp = AcceptTree.accept(this.current); | ||
if (this.input.slice(this.currentPosition).startsWith(Char.OUTSIDE)) { | ||
this.currentPosition += Char.OUTSIDE.length; | ||
return this.createToken(TokenType.Outside, Char.OUTSIDE); | ||
} | ||
if (this.input.slice(this.currentPosition).startsWith(Char.BETWEEN)) { | ||
this.currentPosition += Char.BETWEEN.length; | ||
return this.createToken(TokenType.Between, Char.BETWEEN); | ||
} | ||
const acceptOp = AcceptTree.accept(this.current); | ||
if (acceptOp !== null) { | ||
@@ -1631,6 +1645,6 @@ return this.captureSpecial(acceptOp); | ||
// TODO | ||
var end = this.currentPosition - (tokenType === TokenType.EndOfString ? 0 : 1); | ||
const end = this.currentPosition - (tokenType === TokenType.EndOfString ? 0 : 1); | ||
return new Token(tokenType, value, { | ||
start: this.start, | ||
end: end | ||
end | ||
}); | ||
@@ -1644,9 +1658,14 @@ } | ||
}, { | ||
key: "current", | ||
get: function get() { | ||
return this.input[this.currentPosition]; | ||
} | ||
}, { | ||
key: "captureSpecial", | ||
value: function captureSpecial(op) { | ||
var value = this.current; | ||
let value = this.current; | ||
this.nextSymbol(); | ||
for (; this.currentPosition < this.input.length; this.nextSymbol()) { | ||
var next = op.accept(this.current); | ||
const next = op.accept(this.current); | ||
@@ -1661,3 +1680,3 @@ if (next === null || next.tokenType === TokenType.Null) { | ||
var isUnaryOp = this.current && Char.isDigit(this.current) && op.tokenType === TokenType.ArMinus; // TODO change if unary operations will needed... why is that here? | ||
const isUnaryOp = this.current && Char.isDigit(this.current) && op.tokenType === TokenType.ArMinus; // TODO change if unary operations will needed... why is that here? | ||
@@ -1677,7 +1696,7 @@ if (isUnaryOp) { | ||
value: function captureNumber() { | ||
var result = ''; | ||
var firstPoint = false; | ||
let result = ''; | ||
let firstPoint = false; | ||
for (; this.currentPosition < this.input.length; this.nextSymbol()) { | ||
var skip = Char.isWhiteSpace(this.current) || !Char.isDigit(this.current) && !Char.isFloating(this.current) && this.current !== Char.POINT; | ||
const skip = Char.isWhiteSpace(this.current) || !Char.isDigit(this.current) && !Char.isFloating(this.current) && this.current !== Char.POINT; | ||
@@ -1699,3 +1718,3 @@ if (skip) { | ||
var numValue = parseFloat(result); | ||
const numValue = parseFloat(result); | ||
@@ -1711,6 +1730,6 @@ if (Number.isNaN(numValue)) { | ||
value: function captureIdentifier() { | ||
var result = ''; | ||
let result = ''; | ||
for (; this.currentPosition < this.input.length; this.nextSymbol()) { | ||
var skip = !(Char.isLetterOrDigit(this.current) || Char.isUnderscore(this.current)); | ||
const skip = !(Char.isLetterOrDigit(this.current) || Char.isUnderscore(this.current)); | ||
@@ -1725,3 +1744,5 @@ if (skip) { | ||
if (this.current === Char.OPEN_BRACKET) { | ||
return this.createToken(TokenType.Function, result); | ||
const isBetween = this.tokens.some(token => token.type === TokenType.Between); | ||
const isOutside = this.tokens.some(token => token.type === TokenType.Outside); | ||
return this.createToken(isOutside ? TokenType.Outside : isBetween ? TokenType.Between : TokenType.Function, result); | ||
} | ||
@@ -1747,3 +1768,3 @@ | ||
this.nextSymbol(); | ||
var result = ''; | ||
let result = ''; | ||
@@ -1769,5 +1790,5 @@ for (; this.currentPosition < this.input.length; this.nextSymbol()) { | ||
value: function captureString() { | ||
var result = ''; | ||
var escaping = false; | ||
var start = this.current; | ||
let result = ''; | ||
let escaping = false; | ||
const start = this.current; | ||
this.nextSymbol(); | ||
@@ -1801,3 +1822,3 @@ | ||
var stringToken = this.captureString(); | ||
const stringToken = this.captureString(); | ||
return this.createToken(TokenType.Date, stringToken.value); | ||
@@ -1808,3 +1829,3 @@ } | ||
value: function captureTimeSpan() { | ||
var result = ''; | ||
let result = ''; | ||
@@ -1819,3 +1840,3 @@ for (; this.currentPosition < this.input.length; this.nextSymbol()) { | ||
var number = parseFloat(result); | ||
const number = parseFloat(result); | ||
@@ -1830,3 +1851,3 @@ if (Number.isNaN(number)) { | ||
var timeSpanUnit = ''; | ||
let timeSpanUnit = ''; | ||
@@ -1838,3 +1859,3 @@ while (Char.isLetter(this.current)) { | ||
var time = 0; | ||
let time = 0; | ||
@@ -1889,7 +1910,2 @@ switch (timeSpanUnit) { | ||
} | ||
}, { | ||
key: "current", | ||
get: function get() { | ||
return this.input[this.currentPosition]; | ||
} | ||
}]); | ||
@@ -1900,7 +1916,3 @@ | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
} | ||
var ConditionVisitor = /*#__PURE__*/function (_ExpressionVisitor) { | ||
let ConditionVisitor = /*#__PURE__*/function (_ExpressionVisitor) { | ||
_inherits(ConditionVisitor, _ExpressionVisitor); | ||
@@ -1921,10 +1933,10 @@ | ||
var leftExpression = node.left && node.left.accept(this); | ||
var rightExpression = node.right && node.right.accept(this); | ||
const leftExpression = node.left && node.left.accept(this); | ||
const rightExpression = node.right && node.right.accept(this); | ||
if (node.left instanceof BoolOperationNode && node.right instanceof BoolOperationNode) { | ||
this.checkBoolOperations(node.token.type, [].concat(leftExpression.boolOperations, rightExpression.boolOperations)); | ||
this.checkBoolOperations(node.token.type, [...leftExpression.boolOperations, ...rightExpression.boolOperations]); | ||
return { | ||
boolOperations: [].concat(leftExpression.boolOperations, [node.token.type], rightExpression.boolOperations), | ||
expressions: [].concat(leftExpression.expressions, rightExpression.expressions) | ||
boolOperations: [...leftExpression.boolOperations, node.token.type, ...rightExpression.boolOperations], | ||
expressions: [...leftExpression.expressions, ...rightExpression.expressions] | ||
}; | ||
@@ -1936,4 +1948,4 @@ } | ||
return { | ||
boolOperations: [node.token.type].concat(rightExpression.boolOperations), | ||
expressions: [leftExpression].concat(rightExpression.expressions) | ||
boolOperations: [node.token.type, ...rightExpression.boolOperations], | ||
expressions: [leftExpression, ...rightExpression.expressions] | ||
}; | ||
@@ -1945,4 +1957,4 @@ } | ||
return { | ||
boolOperations: [].concat(leftExpression.boolOperations, [node.token.type]), | ||
expressions: [].concat(leftExpression.expressions, [rightExpression]) | ||
boolOperations: [...leftExpression.boolOperations, node.token.type], | ||
expressions: [...leftExpression.expressions, rightExpression] | ||
}; | ||
@@ -1959,12 +1971,14 @@ } | ||
value: function visitOpNode(node) { | ||
var _node$right; | ||
_get(_getPrototypeOf(ConditionVisitor.prototype), "visitOpNode", this).call(this, node); | ||
this.checkExpressionSimple(node); | ||
var attribute = node.left && node.left.accept(this); | ||
var value = node.right && node.right.accept(this); | ||
var operation = node.token.type; | ||
const attribute = node.left && node.left.accept(this); | ||
const value = node.right && ((_node$right = node.right) == null ? void 0 : _node$right.accept(this)); | ||
const operation = node.token.type; | ||
return { | ||
attribute: attribute, | ||
operation: operation, | ||
value: value | ||
attribute, | ||
operation, | ||
value | ||
}; | ||
@@ -1989,5 +2003,3 @@ } | ||
value: function checkBoolOperations(baseOperation, operations) { | ||
if (operations.some(function (op) { | ||
return op !== baseOperation; | ||
})) { | ||
if (operations.some(op => op !== baseOperation)) { | ||
throw new LintError('Выражение должно использовать одинаковые булевы операторы'); | ||
@@ -2008,9 +2020,5 @@ } | ||
var isBoolResult = function isBoolResult(result) { | ||
return isObject(result) && 'boolOperations' in result; | ||
}; | ||
var isExpression = function isExpression(result) { | ||
return isObject(result) && 'attribute' in result; | ||
}; | ||
var ConditionInterpreter = /*#__PURE__*/function () { | ||
const isBoolResult = result => isObject(result) && 'boolOperations' in result; | ||
const isExpression = result => isObject(result) && 'attribute' in result; | ||
let ConditionInterpreter = /*#__PURE__*/function () { | ||
function ConditionInterpreter(condition) { | ||
@@ -2032,5 +2040,5 @@ _classCallCheck(this, ConditionInterpreter); | ||
try { | ||
var tokens = this.tokenizer.tokenize(); | ||
var ast = new ExpressionAst(tokens).value; | ||
var result = ast && ast.accept(new ConditionVisitor()); | ||
const tokens = this.tokenizer.tokenize(); | ||
const ast = new ExpressionAst(tokens).value; | ||
const result = ast && ast.accept(new ConditionVisitor()); | ||
@@ -2061,3 +2069,3 @@ if (isBoolResult(result)) { | ||
var ConditionEvaluator = /*#__PURE__*/function () { | ||
let ConditionEvaluator = /*#__PURE__*/function () { | ||
function ConditionEvaluator(attributes) { | ||
@@ -2073,4 +2081,4 @@ _classCallCheck(this, ConditionEvaluator); | ||
try { | ||
var tokens = new ExpressionTokenizer(condition).tokenize(); | ||
var ast = new ExpressionAst(tokens).value; | ||
const tokens = new ExpressionTokenizer(condition).tokenize(); | ||
const ast = new ExpressionAst(tokens).value; | ||
return ast && ast.accept(new EvaluateVisitor(this.attributes, options)); | ||
@@ -2086,3 +2094,3 @@ } catch (e) { | ||
var ConditionLinter = /*#__PURE__*/function () { | ||
let ConditionLinter = /*#__PURE__*/function () { | ||
function ConditionLinter(attributes) { | ||
@@ -2098,4 +2106,4 @@ _classCallCheck(this, ConditionLinter); | ||
try { | ||
var tokens = new ExpressionTokenizer(condition).tokenize(); | ||
var ast = new ExpressionAst(tokens).value; | ||
const tokens = new ExpressionTokenizer(condition).tokenize(); | ||
const ast = new ExpressionAst(tokens).value; | ||
ast && ast.accept(new LintVisitor(this.attributes)); | ||
@@ -2102,0 +2110,0 @@ return null; |
@@ -30,3 +30,5 @@ export declare enum TokenType { | ||
Separator = 27, | ||
Function = 28 | ||
Function = 28, | ||
Between = 29, | ||
Outside = 30 | ||
} | ||
@@ -33,0 +35,0 @@ export declare type TokenValue = string | number | boolean | null; |
export declare class Char { | ||
static readonly LEFT_BRACKET = "{"; | ||
static readonly OPEN_BRACKET = "("; | ||
static readonly BETWEEN = "between"; | ||
static readonly OUTSIDE = "!between"; | ||
static readonly SINGLE_QUOTE = "'"; | ||
@@ -5,0 +7,0 @@ static readonly DOUBLE_QUOTE = "\""; |
{ | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"license": "MIT", | ||
@@ -36,3 +36,3 @@ "main": "dist/index.js", | ||
"module": "dist/condition.esm.js", | ||
"gitHead": "5c35f6d790ce6f8d7a35c3cf2aa2fce4c8256d50" | ||
"gitHead": "e9c4e0afea3b056da0ac9a4657082d10b79c3ba8" | ||
} |
@@ -0,0 +0,0 @@ # @everigs/condition |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
415080
3833
2
1