Esempio n. 1
0
        private List <string> EvalExpression(string exp, ParserRuleContext context, string errorPrefix = "")
        {
            exp = exp.TrimExpression();
            var(result, error) = EvalByAdaptiveExpression(exp, CurrentTarget().Scope);

            if (error != null || (result == null && strictMode))
            {
                var errorMsg = string.Empty;

                var childErrorMsg = string.Empty;
                if (error != null)
                {
                    childErrorMsg += error;
                }
                else if (result == null)
                {
                    childErrorMsg += TemplateErrors.NullExpression(exp);
                }

                if (context != null)
                {
                    errorMsg += TemplateErrors.ErrorExpression(context.GetText(), CurrentTarget().TemplateName, errorPrefix);
                }

                if (evaluationTargetStack.Count > 0)
                {
                    evaluationTargetStack.Pop();
                }

                throw new Exception(childErrorMsg + errorMsg);
            }
            else if (result == null && !strictMode)
            {
                result = "null";
            }

            if (result is IList &&
                result.GetType().IsGenericType&&
                result.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(List <>)))
            {
                return((List <string>)result);
            }

            return(new List <string>()
            {
                result.ToString()
            });
        }
Esempio n. 2
0
        private bool EvalExpressionInCondition(string exp, ParserRuleContext context = null, string errorPrefix = "")
        {
            exp = exp.TrimExpression();
            var(result, error) = EvalByAdaptiveExpression(exp, CurrentTarget().Scope);

            if (strictMode && (error != null || result == null))
            {
                var errorMsg = string.Empty;

                var childErrorMsg = string.Empty;
                if (error != null)
                {
                    childErrorMsg += error;
                }
                else if (result == null)
                {
                    childErrorMsg += TemplateErrors.NullExpression(exp);
                }

                if (context != null)
                {
                    errorMsg += TemplateErrors.ErrorExpression(context.GetText(), CurrentTarget().TemplateName, errorPrefix);
                }

                if (evaluationTargetStack.Count > 0)
                {
                    evaluationTargetStack.Pop();
                }

                throw new Exception(childErrorMsg + errorMsg);
            }
            else if (error != null ||
                     result == null ||
                     (result is bool r1 && r1 == false) ||
                     (result is int r2 && r2 == 0))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        internal static void CheckExpressionResult(string exp, string error, object result, string templateName, ParserRuleContext context = null, string errorPrefix = "")
        {
            var errorMsg = string.Empty;

            var childErrorMsg = string.Empty;

            if (error != null)
            {
                childErrorMsg = ConcatErrorMsg(childErrorMsg, error);
            }
            else if (result == null)
            {
                childErrorMsg = ConcatErrorMsg(childErrorMsg, TemplateErrors.NullExpression(exp));
            }

            if (context != null)
            {
                errorMsg = ConcatErrorMsg(errorMsg, TemplateErrors.ErrorExpression(context.GetText(), templateName, errorPrefix));
            }

            throw new Exception(ConcatErrorMsg(childErrorMsg, errorMsg));
        }
Esempio n. 4
0
        internal static void CheckExpressionResult(string exp, string error, object result, string templateName, string lineContent = "", string errorPrefix = "")
        {
            var errorMsg = string.Empty;

            var childErrorMsg = string.Empty;

            if (error != null)
            {
                childErrorMsg = ConcatErrorMsg(childErrorMsg, error);
            }
            else if (result == null)
            {
                childErrorMsg = ConcatErrorMsg(childErrorMsg, TemplateErrors.NullExpression(exp));
            }

            if (!string.IsNullOrWhiteSpace(lineContent))
            {
                errorMsg = ConcatErrorMsg(errorMsg, TemplateErrors.ErrorExpression(lineContent, templateName, errorPrefix));
            }

            throw new Exception(ConcatErrorMsg(childErrorMsg, errorMsg));
        }
Esempio n. 5
0
        private object EvalExpression(string exp, ParserRuleContext context = null, string errorPrefix = "")
        {
            exp = exp.TrimExpression();
            var(result, error) = EvalByAdaptiveExpression(exp, CurrentTarget().Scope);

            if (error != null || (result == null && strictMode))
            {
                var errorMsg = string.Empty;

                var childErrorMsg = string.Empty;
                if (error != null)
                {
                    childErrorMsg += error;
                }
                else if (result == null)
                {
                    childErrorMsg += TemplateErrors.NullExpression(exp);
                }

                if (context != null)
                {
                    errorMsg += TemplateErrors.ErrorExpression(context.GetText(), CurrentTarget().TemplateName, errorPrefix);
                }

                if (evaluationTargetStack.Count > 0)
                {
                    evaluationTargetStack.Pop();
                }

                throw new Exception(childErrorMsg + errorMsg);
            }
            else if (result == null && !strictMode)
            {
                result = "null";
            }

            return(result);
        }