示例#1
0
        private IPage Parse(string name, IParsingSourceStream sourceStream)
        {
            IComponentEvent    QueryEvent           = null;
            IDeclarationSource AreaSource           = null;
            IParsingSource     AllAreaLayoutsSource = null;
            Dictionary <IDeclarationSource, string> AreaLayoutsPairs = null;
            IDeclarationSource DesignSource = null;
            IDeclarationSource WidthSource  = null;
            IDeclarationSource HeightSource = null;
            bool IsScrollable = false;
            IDeclarationSource BackgroundSource      = null;
            IDeclarationSource BackgroundColorSource = null;
            string             Tag = null;

            while (!sourceStream.EndOfStream)
            {
                sourceStream.ReadLine();
                string Line = sourceStream.Line;
                if (!string.IsNullOrWhiteSpace(Line))
                {
                    ParseComponent(sourceStream, ref QueryEvent, ref AreaSource, ref AllAreaLayoutsSource, ref AreaLayoutsPairs, ref DesignSource, ref WidthSource, ref HeightSource, ref IsScrollable, ref BackgroundSource, ref BackgroundColorSource, ref Tag);
                }
            }

            if (AreaSource == null || string.IsNullOrEmpty(AreaSource.Name))
            {
                throw new ParsingException(109, sourceStream, "Missing area name.");
            }

            if (AreaLayoutsPairs == null)
            {
                throw new ParsingException(110, sourceStream, "Missing default area layout.");
            }

            if (DesignSource == null || string.IsNullOrEmpty(DesignSource.Name))
            {
                throw new ParsingException(111, sourceStream, "Missing design name.");
            }

            if (WidthSource == null || string.IsNullOrEmpty(WidthSource.Name))
            {
                throw new ParsingException(112, sourceStream, "Missing width.");
            }

            if (HeightSource == null || string.IsNullOrEmpty(HeightSource.Name))
            {
                throw new ParsingException(113, sourceStream, "Missing height.");
            }

            if (BackgroundColorSource == null || string.IsNullOrEmpty(BackgroundColorSource.Name))
            {
                throw new ParsingException(114, sourceStream, "Missing background color.");
            }

            return(new Page(name, ParserDomain.ToCSharpName(sourceStream, name + "Page"), ParserDomain.ToXamlName(sourceStream, name, "Page"), QueryEvent, AreaSource, AllAreaLayoutsSource, AreaLayoutsPairs, DesignSource, WidthSource, HeightSource, IsScrollable, BackgroundSource, BackgroundColorSource, Tag));
        }
示例#2
0
        private IObjectEvent ParseEvent(IParsingSourceStream sourceStream, string line)
        {
            string Name = line.Trim();

            if (Name.Length <= 0)
            {
                throw new ParsingException(107, sourceStream, "Event name cannot be empty.");
            }

            IDeclarationSource NameSource = new DeclarationSource(Name, sourceStream);

            return(new ObjectEvent(NameSource, ParserDomain.ToCSharpName(sourceStream, Name)));
        }
示例#3
0
        private IDynamic Parse(string name, IParsingSourceStream sourceStream)
        {
            IDynamicPropertyCollection Properties = new DynamicPropertyCollection();

            sourceStream.ReadLine();
            string Line        = sourceStream.Line;
            int    Indentation = -1;
            bool   UseTab      = false;

            while (Line != null)
            {
                IDynamicProperty Property = Parse(sourceStream, ref Line, ref Indentation, ref UseTab);
                Properties.Add(Property);
            }

            string FileName     = ParserDomain.ToCSharpName(sourceStream, name + "PageDynamic");
            string XamlPageName = ParserDomain.ToXamlName(sourceStream, name, "Page");

            return(new Dynamic(name, FileName, XamlPageName, Properties));
        }
示例#4
0
        private IObject Parse(string name, IParsingSourceStream sourceStream)
        {
            IObjectPropertyCollection ObjectPropertyList;
            List <IObjectEvent>       ObjectEventList;

            sourceStream.ReadLine();
            string Line = sourceStream.Line;

            bool IsGlobal;

            if (!string.IsNullOrEmpty(Line) && Line.Trim().ToLower() == "global")
            {
                IsGlobal = true;
                sourceStream.ReadLine();
            }
            else
            {
                IsGlobal = false;
            }

            try
            {
                ObjectPropertyList = ParseObjectProperties(sourceStream, ref Line);
                ObjectEventList    = ParseEvents(sourceStream, ref Line);
            }
            catch (ParsingException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ParsingException(94, sourceStream, e);
            }

            string CSharpname = ParserDomain.ToCSharpName(sourceStream, name);

            return(new Object(name, CSharpname, IsGlobal, ObjectPropertyList, ObjectEventList));
        }
示例#5
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;
                        }
示例#6
0
        private IObjectProperty ParseProperty(IParsingSourceStream sourceStream)
        {
            IDeclarationSource NameSource;
            string             Details;

            ParserDomain.ParseStringPair(sourceStream, ':', out NameSource, out Details);

            string[] SplittedDetails  = Details.Split(',');
            string   PropertyTypeName = SplittedDetails[0].Trim();

            int MaximumLength = int.MaxValue;
            IDeclarationSource ObjectSource = null;

            for (int i = 1; i < SplittedDetails.Length; i++)
            {
                string   Detail         = SplittedDetails[i].Trim();
                string[] SplittedDetail = Detail.Split('=');
                int      ParsedLength;

                if (SplittedDetail.Length == 2 && SplittedDetail[0].Trim() == "maximum length" && int.TryParse(SplittedDetail[1].Trim(), out ParsedLength) && ParsedLength >= 0)
                {
                    if (MaximumLength == int.MaxValue)
                    {
                        MaximumLength = ParsedLength;
                    }
                    else
                    {
                        throw new ParsingException(97, sourceStream, "Maximum length specified more than once.");
                    }
                }

                else if (SplittedDetail.Length == 2 && SplittedDetail[0].Trim() == "object")
                {
                    if (ObjectSource == null)
                    {
                        ObjectSource = new DeclarationSource(SplittedDetail[1].Trim(), sourceStream);
                        if (string.IsNullOrEmpty(ObjectSource.Name))
                        {
                            throw new ParsingException(98, sourceStream, "Invalid empty object name.");
                        }
                    }
                    else
                    {
                        throw new ParsingException(99, sourceStream, "Object name specified more than once.");
                    }
                }

                else
                {
                    throw new ParsingException(100, sourceStream, $"Unknown specifier '{Detail}'.");
                }
            }

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

            if (PropertyTypeName == "string")
            {
                return(new ObjectPropertyString(NameSource, CSharpName, MaximumLength));
            }
            else if (PropertyTypeName == "readonly string")
            {
                return(new ObjectPropertyReadonlyString(NameSource, CSharpName));
            }
            else if (PropertyTypeName == "string dictionary")
            {
                return(new ObjectPropertyStringDictionary(NameSource, CSharpName));
            }
            else if (PropertyTypeName == "string list")
            {
                return(new ObjectPropertyStringList(NameSource, CSharpName));
            }
            else if (MaximumLength != int.MaxValue)
            {
                throw new ParsingException(101, sourceStream, "Specifiers 'maximum length' not valid for this property type.");
            }
            else if (PropertyTypeName == "integer")
            {
                return(new ObjectPropertyInteger(NameSource, CSharpName));
            }
            else if (PropertyTypeName == "enum")
            {
                return(new ObjectPropertyEnum(NameSource, CSharpName));
            }
            else if (PropertyTypeName == "boolean")
            {
                return(new ObjectPropertyBoolean(NameSource, CSharpName));
            }
            else if (PropertyTypeName == "item")
            {
                if (ObjectSource != null)
                {
                    return(new ObjectPropertyItem(NameSource, CSharpName, ObjectSource));
                }
                else
                {
                    throw new ParsingException(102, sourceStream, "Object name not specified for 'item'.");
                }
            }
            else if (PropertyTypeName == "items")
            {
                if (ObjectSource != null)
                {
                    return(new ObjectPropertyItemList(NameSource, CSharpName, ObjectSource));
                }
                else
                {
                    throw new ParsingException(103, sourceStream, "Object name not specified for 'items'.");
                }
            }
            else
            {
                throw new ParsingException(104, sourceStream, $"Unknown property type '{PropertyTypeName}'.");
            }
        }