예제 #1
0
        public override IEnumerable <string> IsValid(LinkedListNode <Node> node)
        {
            var errors = base.IsValid(node).ToList();

            _argumentCount = CountArguments(node.Next);

            if (!_functionService.Exists(Id))
            {
                if (Id == _parentId)
                {
                    return(errors);
                }

                errors.Add($"Undefined function {Id}");
            }

            var function = _functionService.Get(Id);

            if (_argumentCount < function.RequiredParameterNumber ||
                (function.MaxParameterNumber != null &&
                 _argumentCount > function.MaxParameterNumber))
            {
                //TODO ajouter un warning quand un argument requis et le node suivant est + ou - incitant a ajouter des {}, ex: $ABS -2 devrait etre $ABS{-2}
                errors.Add($"Function {Id} should have {GetArgumentNumberErrorMessage(function)} but found {_argumentCount}");
            }
            else if (function.ParameterBatchSize != null && (_argumentCount - function.RequiredParameterNumber) % function.ParameterBatchSize != 0)
            {
                errors.Add($"Function {Id} have an invalid number of arguments ({_argumentCount}. Arguments after the {function.RequiredParameterNumber}th should come in batch of {function.ParameterBatchSize}");
            }

            return(errors);
        }
예제 #2
0
        public override LinkedListNode <Node> OnBeforeValidation(LinkedListNode <Node> node)
        {
            var previous = node.Previous?.Value;
            var isUnary  = previous == null || !previous.IsValidLeftOperand();

            if (previous is FunctionNode functionNode &&
                _functionService.Exists(functionNode.Id))
            {
                isUnary = _functionService.Get(functionNode.Id).RequiredParameterNumber > 0;
            }

            if (!isUnary)
            {
                return(node);
            }

            var type = Type == NodeType.PlusOperator ? NodeType.UnaryPlusOperator : NodeType.UnaryMinusOperator;

            var resultNode = node.List !.AddAfter(node, new UnaryAdditionOperatorNode(Text, type));

            node.List !.Remove(node);

            return(resultNode);
        }