Example #1
0
        public override SelectionRuleNode VisitBooleanExpression(TmtParser.BooleanExpressionContext context)
        {
            SelectionRuleNode result;

            NaryRuleNode rule = null;

            switch (context.op?.GetText())
            {
            case "and":
                rule = new AndRuleNode()
                {
                    Name = "AND"
                };
                break;

            case "or":
                rule = new OrRuleNode()
                {
                    Name = "OR"
                };
                break;
            }

            if (Rule == null)
            {
                Rule = rule;
            }

            var left  = Visit(context.left);
            var right = Visit(context.right);

            if (left != null)
            {
                if (right != null)
                {
                    rule?.Children.Add(left);
                    rule?.Children.Add(right);

                    result = rule;
                }
                else
                {
                    result = left;
                    Rule   = left;
                }
            }
            else
            {
                result = right;
                Rule   = right;
            }

            return(result);
        }
 /// <summary>
 /// Visit a parse tree produced by the <c>booleanExpression</c>
 /// labeled alternative in <see cref="TmtParser.expression"/>.
 /// <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 VisitBooleanExpression([NotNull] TmtParser.BooleanExpressionContext context)
 {
     return(VisitChildren(context));
 }
Example #3
0
 /// <summary>
 /// Exit a parse tree produced by the <c>booleanExpression</c>
 /// labeled alternative in <see cref="TmtParser.expression"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitBooleanExpression([NotNull] TmtParser.BooleanExpressionContext context)
 {
 }