Esempio n. 1
0
        private List <Diagnostic> CheckExpression(ParserRuleContext expressionContext, string prefix = "")
        {
            var exp    = expressionContext.GetText();
            var result = new List <Diagnostic>();

            if (!exp.EndsWith("}"))
            {
                result.Add(BuildLGDiagnostic(TemplateErrors.NoCloseBracket, context: expressionContext));
            }
            else
            {
                exp = exp.TrimExpression();

                try
                {
                    ExpressionParser.Parse(exp);
                }
                catch (Exception e)
                {
                    var suffixErrorMsg = Evaluator.ConcatErrorMsg(TemplateErrors.ExpressionParseError(exp), e.Message);
                    var errorMsg       = Evaluator.ConcatErrorMsg(prefix, suffixErrorMsg);

                    result.Add(BuildLGDiagnostic(errorMsg, context: expressionContext));
                    return(result);
                }
            }

            return(result);
        }
Esempio n. 2
0
        private List <Diagnostic> CheckExpression(ParserRuleContext expressionContext, string prefix = "")
        {
            var exp    = expressionContext.GetText();
            var result = new List <Diagnostic>();

            if (!exp.EndsWith("}", StringComparison.Ordinal))
            {
                result.Add(BuildLGDiagnostic(TemplateErrors.NoCloseBracket, context: expressionContext));
            }
            else
            {
                exp = exp.TrimExpression();

                try
                {
                    ExpressionParser.Parse(exp);
                }
#pragma warning disable CA1031 // Do not catch general exception types (catch any exception and return it in the result)
                catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    var suffixErrorMsg = Evaluator.ConcatErrorMsg(TemplateErrors.ExpressionParseError(exp), e.Message);
                    var errorMsg       = Evaluator.ConcatErrorMsg(prefix, suffixErrorMsg);

                    result.Add(BuildLGDiagnostic(errorMsg, context: expressionContext));
                    return(result);
                }
            }

            return(result);
        }
Esempio n. 3
0
        private List <Diagnostic> CheckExpression(string exp, ParserRuleContext context, string prefix = "")
        {
            var result = new List <Diagnostic>();

            if (!exp.EndsWith("}"))
            {
                result.Add(BuildLGDiagnostic(TemplateErrors.NoCloseBracket, context: context));
            }
            else
            {
                exp = exp.TrimExpression();

                try
                {
                    ExpressionParser.Parse(exp);
                }
                catch (Exception e)
                {
                    var errorMsg = prefix + TemplateErrors.ExpressionParseError(exp) + e.Message;

                    result.Add(BuildLGDiagnostic(errorMsg, context: context));
                    return(result);
                }
            }

            return(result);
        }