Exemple #1
0
            public override Expression VisitStringInterpolationAtom([NotNull] ExpressionAntlrParser.StringInterpolationAtomContext context)
            {
                var children = new List <Expression>();

                foreach (var child in context.stringInterpolation().children)
                {
                    if (child is ITerminalNode node)
                    {
                        switch (node.Symbol.Type)
                        {
                        case ExpressionAntlrParser.TEMPLATE:
                            var expressionString = TrimExpression(node.GetText());
                            children.Add(Expression.Parse(expressionString, _lookupFunction));
                            break;

                        case ExpressionAntlrParser.ESCAPE_CHARACTER:
                            children.Add(Expression.ConstantExpression(EvalEscape(node.GetText().Replace("\\`", "`").Replace("\\$", "$"))));
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        // text content
                        var text = EvalEscape(child.GetText());
                        children.Add(Expression.ConstantExpression(text));
                    }
                }

                return(MakeExpression(ExpressionType.Concat, children.ToArray()));
            }
Exemple #2
0
 /// <summary>
 /// Exit a parse tree produced by the <c>stringInterpolationAtom</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 ExitStringInterpolationAtom([NotNull] ExpressionAntlrParser.StringInterpolationAtomContext context)
 {
 }
 /// <summary>
 /// Visit a parse tree produced by the <c>stringInterpolationAtom</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 VisitStringInterpolationAtom([NotNull] ExpressionAntlrParser.StringInterpolationAtomContext context)
 {
     return(VisitChildren(context));
 }