コード例 #1
0
ファイル: ParserColorTheme.cs プロジェクト: dlebansais/Wrist
        private Dictionary <IDeclarationSource, string> ParseColors(IParsingSourceStream sourceStream)
        {
            Dictionary <IDeclarationSource, string> Colors = new Dictionary <IDeclarationSource, string>();

            while (!sourceStream.EndOfStream)
            {
                sourceStream.ReadLine();

                IDeclarationSource ColorSource;
                string             ColorValue;
                ParserDomain.ParseStringPair(sourceStream, ':', out ColorSource, out ColorValue);

                foreach (KeyValuePair <IDeclarationSource, string> Entry in Colors)
                {
                    if (Entry.Key.Name == ColorSource.Name)
                    {
                        throw new ParsingException(81, sourceStream, $"Color '{ColorSource.Name}' defined more than once.");
                    }
                }

                Colors.Add(ColorSource, ColorValue);
            }

            return(Colors);
        }
コード例 #2
0
        private Dictionary <IDeclarationSource, string> ParseAreaLayoutsPairs(IParsingSourceStream sourceStream, string line)
        {
            Dictionary <IDeclarationSource, string> Result = new Dictionary <IDeclarationSource, string>();

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

            foreach (string Split in Splitted)
            {
                IDeclarationSource AreaSource;
                string             LayoutName;
                ParserDomain.ParseStringPair(sourceStream, Split, '=', out AreaSource, out LayoutName);

                Result.Add(AreaSource, LayoutName);
            }

            return(Result);
        }
コード例 #3
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.");
            }
        }
コード例 #4
0
ファイル: ParserDynamic.cs プロジェクト: dlebansais/Wrist
        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;
                        }
コード例 #5
0
        private IComponent ParseComponent(IParsingSourceStream sourceStream)
        {
            IDeclarationSource NameSource;
            string             ComponentInfo;

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

            string[] SplittedInfo = ComponentInfo.Split(',');
            if (SplittedInfo.Length < 1)
            {
                throw new ParsingException(25, sourceStream, "Component type expected.");
            }

            string ComponentTypeName = SplittedInfo[0].Trim();

            if (string.IsNullOrEmpty(ComponentTypeName))
            {
                throw new ParsingException(25, sourceStream, "Component type expected.");
            }

            List <ComponentInfo> InfoList = new List <ComponentInfo>();

            for (int i = 1; i < SplittedInfo.Length; i++)
            {
                InfoList.Add(Parser.ComponentInfo.Parse(sourceStream, SplittedInfo[i]));
            }

            if (ComponentTypeName == "area")
            {
                return(ParseComponentArea(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "button")
            {
                return(ParseComponentButton(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "checkbox")
            {
                return(ParseComponentCheckBox(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "text")
            {
                return(ParseComponentText(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "html")
            {
                return(ParseComponentHtml(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "image")
            {
                return(ParseComponentImage(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "edit")
            {
                return(ParseComponentEdit(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "password edit")
            {
                return(ParseComponentPasswordEdit(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "popup")
            {
                return(ParseComponentPopup(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "selector")
            {
                return(ParseComponentSelector(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "index")
            {
                return(ParseComponentIndex(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "container")
            {
                return(ParseComponentContainer(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "container list")
            {
                return(ParseComponentContainerList(NameSource, sourceStream, InfoList));
            }
            else if (ComponentTypeName == "radio button")
            {
                return(ParseComponentRadioButton(NameSource, sourceStream, InfoList));
            }
            else
            {
                throw new ParsingException(26, sourceStream, $"Unknown component type '{ComponentTypeName}'.");
            }
        }
コード例 #6
0
ファイル: ParserObject.cs プロジェクト: dlebansais/Wrist
        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}'.");
            }
        }