Пример #1
0
        private IDynamicProperty Parse(IParsingSourceStream sourceStream, ref string line, ref int indentation, ref bool useTab)
        {
            while (string.IsNullOrEmpty(line) && !sourceStream.EndOfStream)
            {
                sourceStream.ReadLine();
                line = sourceStream.Line;
            }

            IDeclarationSource PropertySource;
            string             ResultValue;

            ParserDomain.ParseStringPair(sourceStream, ':', out PropertySource, out ResultValue);

            if (string.IsNullOrEmpty(PropertySource.Name))
            {
                throw new ParsingException(209, sourceStream, "Missing dynamic property name.");
            }

            string CSharpName = ParserDomain.ToCSharpName(PropertySource.Source, PropertySource.Name);

            DynamicOperationResults Result;

            if (ResultValue == "boolean")
            {
                Result = DynamicOperationResults.Boolean;
            }
            else
            {
                throw new ParsingException(210, sourceStream, $"Invalid dynamic property type '{ResultValue}'.");
            }

            Stack <IDynamicOperation> OperationStack = new Stack <IDynamicOperation>();
            IDynamicOperation         RootOperation  = null;

            for (;;)
            {
                sourceStream.ReadLine();
                line = sourceStream.Line;

                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                if (indentation < 0)
                {
                    MeasureIndentation(sourceStream, ref indentation, ref useTab);
                }

                int Depth = GetIndentation(sourceStream, indentation, useTab);

                string Text = line.Trim();
                if (Text == "NOT")
                {
                    OperationStack.Push(new UnaryOperation(DynamicOperationTypes.NOT));
                }
                else if (Text == "OR")
                {
                    OperationStack.Push(new BinaryOperation(DynamicOperationTypes.OR));
                }
                else if (Text == "AND")
                {
                    OperationStack.Push(new BinaryOperation(DynamicOperationTypes.AND));
                }
                else if (Text == "EQUALS")
                {
                    OperationStack.Push(new BinaryOperation(DynamicOperationTypes.EQUALS));
                }
                else if (Text == "GREATER THAN")
                {
                    OperationStack.Push(new BinaryOperation(DynamicOperationTypes.GREATER_THAN));
                }
                else if (Text == "IS EMPTY")
                {
                    OperationStack.Push(new UnaryOperation(DynamicOperationTypes.IS_EMPTY));
                }
                else
                {
                    IDynamicOperation Operand;

                    int IntegerConstantValue;
                    if (int.TryParse(Text, out IntegerConstantValue))
                    {
                        Operand = new IntegerConstantOperation(IntegerConstantValue);
                    }
                    else
                    {
                        IDeclarationSource ObjectSource;
                        IDeclarationSource MemberSource;
                        IDeclarationSource KeySource;
                        if (!ParserDomain.TryParseObjectProperty(sourceStream, Text, out ObjectSource, out MemberSource, out KeySource))
                        {
                            throw new ParsingException(211, sourceStream, $"Expected operator, integer constant or object property.");
                        }

                        ComponentInfo Info = new ComponentInfo();
                        Info.ObjectSource = ObjectSource;
                        Info.MemberSource = MemberSource;
                        Info.KeySource    = KeySource;

                        ComponentProperty ValueProperty = new ComponentProperty(Info);

                        Operand = new PropertyValueOperation(ValueProperty);
                    }

                    while (OperationStack.Count > 0)
                    {
                        IDynamicOperation CurrentOperation = OperationStack.Peek();

                        if ((CurrentOperation is IUnaryOperation AsUnary) && (AsUnary.Operand == null))
                        {
                            AsUnary.SetOperand(Operand);

                            RootOperation = OperationStack.Pop();
                            Operand       = RootOperation;
                        }