public override Expression VisitStringAtom([NotNull] ExpressionAntlrParser.StringAtomContext context)
            {
                var text = context.GetText();

                if (text.StartsWith("'"))
                {
                    return(Expression.ConstantExpression(Regex.Unescape(text.Trim('\''))));
                }
                else
                {
                    // start with "
                    return(Expression.ConstantExpression(Regex.Unescape(text.Trim('"'))));
                }
            }
示例#2
0
            public override Expression VisitStringAtom([NotNull] ExpressionAntlrParser.StringAtomContext context)
            {
                var text = context.GetText();

                if (text.StartsWith("'") && text.EndsWith("'"))
                {
                    text = text.Substring(1, text.Length - 2).Replace("\\'", "'");
                }
                else if (text.StartsWith("\"") && text.EndsWith("\""))
                {
                    text = text.Substring(1, text.Length - 2).Replace("\\\"", "\"");
                }
                else
                {
                    throw new Exception($"Invalid string {text}");
                }

                return(Expression.ConstantExpression(EvalEscape(text)));
            }