Пример #1
0
        public override BaseNode VisitFilterExpression(QueryFilteringParser.FilterExpressionContext context)
        {
            BaseNode resultNode = context.children[0].Accept(this);

            for (int i = 1; i < context.children.Count; i += 2)
            {
                var left  = resultNode;
                var right = context.children[i + 1].Accept(this);

                var aggregateNode = (ITerminalNode)context.children[i];

                switch (aggregateNode.Symbol.Type)
                {
                case QueryFilteringLexer.AND:
                    resultNode = new AndNode(left, right);
                    continue;

                case QueryFilteringLexer.OR:
                    resultNode = new OrNode(left, right);
                    continue;

                default:
                    throw new ParseRuleException(
                              nameof(FilterExpressionVisitor),
                              $"неизвестный тип предиката '{aggregateNode.Symbol.Type}'");
                }
            }

            return(resultNode);
        }
 /// <summary>
 /// Visit a parse tree produced by <see cref="QueryFilteringParser.filterExpression"/>.
 /// <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 VisitFilterExpression([NotNull] QueryFilteringParser.FilterExpressionContext context)
 {
     return(VisitChildren(context));
 }