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('"'))));
                }
            }
Example #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)));
            }
Example #3
0
 /// <summary>
 /// Exit a parse tree produced by the <c>stringAtom</c>
 /// labeled alternative in <see cref="ExpressionAntlrParser.primaryExpression"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitStringAtom([NotNull] ExpressionAntlrParser.StringAtomContext context)
 {
 }
 /// <summary>
 /// Visit a parse tree produced by the <c>stringAtom</c>
 /// labeled alternative in <see cref="ExpressionAntlrParser.primaryExpression"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitStringAtom([NotNull] ExpressionAntlrParser.StringAtomContext context)
 {
     return(VisitChildren(context));
 }