Пример #1
0
    private static void ReadRootOpenParenthesys(ReadRootContext context)
    {
        if (context.Current is not null)
        {
            context.Current             = ReadingError(context.Reader, context.Messages, MissingLogicalOperator);
            context.ShouldReturnCurrent = true;
            return;
        }

        context.Current             = ReadRoot(context.Reader, context.Messages, true, false);
        context.ShouldReturnCurrent = context.Current is null;
    }
Пример #2
0
    private static void ReadRootVariableOrConstant(ReadRootContext context)
    {
        if (context.Current is not null)
        {
            context.Current             = ReadingError(context.Reader, context.Messages, MissingLogicalOperator);
            context.ShouldReturnCurrent = true;
            return;
        }

        context.Current = ReadCondition(context.Reader, context.Messages);

        if (context.SingleCondition || context.Current is null)
        {
            context.ShouldReturnCurrent = true;
        }
    }
Пример #3
0
    private static void ReadRootNot(ReadRootContext context)
    {
        if (context.Current is not null)
        {
            context.Current             = ReadingError(context.Reader, context.Messages, MissingLogicalOperator);
            context.ShouldReturnCurrent = true;
            return;
        }

        var right = ReadRoot(context.Reader, context.Messages, false, true);

        if (right is null)
        {
            context.Current             = null;
            context.ShouldReturnCurrent = true;
            return;
        }

        context.Current = new NotCondition(right);
    }
Пример #4
0
    private static ICondition?ReadRoot(IWordReader reader, List <string> messages, bool allowCloseParenthesys, bool singleCondition)
    {
        if (!reader.Read())
        {
            messages.Add(UnexpectedExpressionEnd);
            return(null);
        }

        var context = new ReadRootContext(reader, messages, allowCloseParenthesys, singleCondition);

        do
        {
            switch (reader.WordType)
            {
            case WordType.Invalid:
                return(ReadingError(reader, messages, InvalidToken));

            case WordType.Variable:
            case WordType.String:
            case WordType.Number:
            case WordType.Null:
                ReadRootVariableOrConstant(context);
                break;

            case WordType.OpenParenthesys:
                ReadRootOpenParenthesys(context);
                break;

            case WordType.CloseParenthesys:
                ReadRootCloseParenthesys(context);
                break;

            case WordType.And:
                ReadRootLogicalOperator(context, (l, r) => new AndCondition(l, r));
                break;

            case WordType.Or:
                ReadRootLogicalOperator(context, (l, r) => new OrCondition(l, r));
                break;

            case WordType.Not:
                ReadRootNot(context);
                break;

            default:
                return(ReadingError(reader, messages, MisplacedKeyword));
            }

            if (context.ShouldReturnCurrent)
            {
                return(context.Current);
            }
        }while (reader.Read());

        if (context.AllowCloseParenthesys || context.Current is null)
        {
            messages.Add(UnexpectedExpressionEnd);
            return(null);
        }

        return(context.Current);
    }