Пример #1
0
        public static bool TryParseObjectProperty(IParsingSourceStream sourceStream, string text, out IDeclarationSource objectSource, out IDeclarationSource memberSource, out IDeclarationSource keySource)
        {
            if (!text.Contains("."))
            {
                objectSource = null;
                memberSource = null;
                keySource    = null;
                return(false);
            }

            else
            {
                string MemberName;
                ParseStringPair(sourceStream, text, '.', out objectSource, out MemberName);

                string Key;
                int    StartIndex = MemberName.IndexOf("[");
                int    EndIndex   = MemberName.IndexOf("]");
                if (StartIndex > 0 && EndIndex > StartIndex)
                {
                    Key        = MemberName.Substring(StartIndex + 1, EndIndex - StartIndex - 1);
                    MemberName = MemberName.Substring(0, StartIndex);
                    keySource  = new DeclarationSource(Key, sourceStream);
                }
                else
                {
                    keySource = null;
                }

                memberSource = new DeclarationSource(MemberName, sourceStream);
                return(true);
            }
        }
Пример #2
0
        public static void ParseStringPair(IParsingSourceStream sourceStream, string line, char separator, out IDeclarationSource nameSource, out string value)
        {
            if (string.IsNullOrEmpty(line))
            {
                throw new ParsingException(19, sourceStream, "Unexpected empty line.");
            }

            string[] Splitted = line.Split(separator);
            if (Splitted.Length < 2)
            {
                throw new ParsingException(20, sourceStream, $"<key>{separator}<value> expected.");
            }

            string Name = Splitted[0].Trim();

            if (string.IsNullOrEmpty(Name))
            {
                throw new ParsingException(21, sourceStream, $"<key>{separator}<value> expected, found empty key.");
            }

            string Value = Splitted[1];

            for (int i = 2; i < Splitted.Length; i++)
            {
                Value = $"{Value}{separator}{Splitted[i]}";
            }

            value = Value.Trim();
            if (string.IsNullOrEmpty(value))
            {
                throw new ParsingException(22, sourceStream, $"<key>{separator}<value> expected, found empty value.");
            }

            nameSource = new DeclarationSource(Name, sourceStream);
        }
Пример #3
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)));
        }
Пример #4
0
        private void ParseComponent(IParsingSourceStream sourceStream, ref IComponentEvent queryEvent, ref IDeclarationSource areaSource, ref IParsingSource allAreaLayoutsSource, ref Dictionary <IDeclarationSource, string> areaLayoutsPairs, ref IDeclarationSource designSource, ref IDeclarationSource widthSource, ref IDeclarationSource heightSource, ref bool isScrollable, ref IDeclarationSource backgroundSource, ref IDeclarationSource backgroundColorSource, ref string tag)
        {
            string Line = sourceStream.Line;

            if (Line.Trim() == "scrollable")
            {
                isScrollable = true;
                return;
            }

            IDeclarationSource ComponentSource;
            string             ComponentValue;

            ParserDomain.ParseStringPair(sourceStream, ':', out ComponentSource, out ComponentValue);
            //ComponentValue = ComponentValue.ToLower();

            if (ComponentSource.Name == "open on query")
            {
                if (queryEvent == null)
                {
                    queryEvent = ParseQueryEvent(sourceStream, ComponentValue);
                }
                else
                {
                    throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once.");
                }
            }
            else if (ComponentSource.Name == "area")
            {
                if (areaSource == null)
                {
                    areaSource = new DeclarationSource(ComponentValue, sourceStream);
                }
                else
                {
                    throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once.");
                }
            }
            else if (ComponentSource.Name == "default area layout")
            {
                if (areaLayoutsPairs == null)
                {
                    allAreaLayoutsSource = sourceStream.FreezedPosition();
                    areaLayoutsPairs     = ParseAreaLayoutsPairs(sourceStream, ComponentValue);
                }
                else
                {
                    throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once.");
                }
            }
            else if (ComponentSource.Name == "design")
            {
                if (designSource == null)
                {
                    designSource = new DeclarationSource(ComponentValue, sourceStream);
                }
                else
                {
                    throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once.");
                }
            }
            else if (ComponentSource.Name == "width")
            {
                if (widthSource == null)
                {
                    widthSource = new DeclarationSource(ComponentValue, sourceStream);
                }
                else
                {
                    throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once.");
                }
            }
            else if (ComponentSource.Name == "height")
            {
                if (heightSource == null)
                {
                    heightSource = new DeclarationSource(ComponentValue, sourceStream);
                }
                else
                {
                    throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once.");
                }
            }
            else if (ComponentSource.Name == "background")
            {
                if (backgroundSource == null)
                {
                    backgroundSource = new DeclarationSource(ComponentValue, sourceStream);
                }
                else
                {
                    throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once.");
                }
            }
            else if (ComponentSource.Name == "background color")
            {
                if (backgroundColorSource == null)
                {
                    backgroundColorSource = new DeclarationSource(ComponentValue, sourceStream);
                }
                else
                {
                    throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once.");
                }
            }
            else if (ComponentSource.Name == "tag")
            {
                if (tag == null)
                {
                    tag = ComponentValue;
                }
                else
                {
                    throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once.");
                }
            }
            else
            {
                throw new ParsingException(115, sourceStream, $"Specifier '{ComponentSource.Name}' was unexpected.");
            }
        }
Пример #5
0
        private IUnitTest Parse(string fileName, IParsingSourceStream SourceStream)
        {
            List <ITestingOperation> Operations = new List <ITestingOperation>();

            while (!SourceStream.EndOfStream)
            {
                SourceStream.ReadLine();
                string Line = SourceStream.Line;
                if (string.IsNullOrEmpty(Line))
                {
                    break;
                }

                string[] Splitted = Line.Split(',');

                if (Splitted.Length < 4)
                {
                    throw new ParsingException(232, SourceStream, "Invalid line in the unit testing file.");
                }

                IDeclarationSource PageName   = new DeclarationSource(Splitted[0].Trim(), SourceStream);
                string             Operation  = Splitted[1].Trim();
                IDeclarationSource AreaName   = new DeclarationSource(Splitted[2].Trim(), SourceStream);
                string             Parameters = Splitted[3];
                for (int i = 4; i < Splitted.Length; i++)
                {
                    Parameters += "," + Splitted[i];
                }

                ITestingOperation NewOperation;

                if (Operation == "click")
                {
                    IDeclarationSource ComponentName = new DeclarationSource(Parameters.Trim(), SourceStream);
                    NewOperation = new ClickOperation(PageName, AreaName, ComponentName);
                }

                else if (Operation == "toggle")
                {
                    IDeclarationSource ComponentName = new DeclarationSource(Parameters.Trim(), SourceStream);
                    NewOperation = new ToggleOperation(PageName, AreaName, ComponentName);
                }

                else if (Operation == "fill")
                {
                    string[] FillParameters = Parameters.Split('=');
                    if (FillParameters.Length < 2)
                    {
                        throw new ParsingException(233, SourceStream, "Invalid line in the unit testing file.");
                    }

                    IDeclarationSource ComponentName = new DeclarationSource(FillParameters[0].Trim(), SourceStream);
                    string             Content       = FillParameters[1].Trim();

                    NewOperation = new FillOperation(PageName, AreaName, ComponentName, Content);
                }

                else if (Operation == "select")
                {
                    string[] FillParameters = Parameters.Split('=');
                    if (FillParameters.Length < 2)
                    {
                        throw new ParsingException(234, SourceStream, "Invalid line in the unit testing file.");
                    }

                    IDeclarationSource ComponentName = new DeclarationSource(FillParameters[0].Trim(), SourceStream);

                    int Index;
                    if (!int.TryParse(FillParameters[1].Trim(), out Index))
                    {
                        throw new ParsingException(235, SourceStream, "Invalid line in the unit testing file.");
                    }

                    NewOperation = new SelectOperation(PageName, AreaName, ComponentName, Index);
                }
                else
                {
                    throw new ParsingException(236, SourceStream, $"Unknown unit testing operation '{Operation}'.");
                }

                Operations.Add(NewOperation);
            }

            return(new UnitTest(fileName, Operations));
        }
Пример #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}'.");
            }
        }