Ejemplo n.º 1
0
    public void ParseMaterialStyle()
    {
        var nodes = StyleParser.Parse(@"
            style simple {
                Material = ""noise"" { 
                    shake = 4;
                };
            }
        ");

        Assert.AreEqual(1, nodes.Count);
        StyleRootNode rootNode = ((StyleRootNode)nodes[0]);

        Assert.AreEqual("simple", rootNode.identifier);
        Assert.AreEqual(null, rootNode.tagName);
        Assert.AreEqual(1, rootNode.children.Count);

        var propertyNode = rootNode.children[0];

        Assert.AreEqual(StyleASTNodeType.Property, propertyNode.type);

        PropertyNode typedPropertyNode = (((PropertyNode)propertyNode));

        Assert.AreEqual("Material", typedPropertyNode.identifier);
        Assert.AreEqual(StyleASTNodeType.StringLiteral, typedPropertyNode.children[0].type);
    }
Ejemplo n.º 2
0
    public void ParseMultipleAttributes()
    {
        var nodes = StyleParser.Parse(@"
            style hasBackgroundOnHover {
                not [attr:attrName1] and not [attr:attrName2] and [attr:attrName3]{ }
            }
        ");

        Assert.AreEqual(1, nodes.Count);
        StyleRootNode styleRootNode = (StyleRootNode)nodes[0];

        Assert.AreEqual(1, styleRootNode.children.Count);

        var attributeGroupContainer3 = (((AttributeNodeContainer)styleRootNode.children[0]));

        Assert.AreEqual("attrName3", attributeGroupContainer3.identifier);
        Assert.AreEqual(false, attributeGroupContainer3.invert);

        var attributeGroupContainer2 = attributeGroupContainer3.next;

        Assert.AreEqual("attrName2", attributeGroupContainer2.identifier);
        Assert.AreEqual(true, attributeGroupContainer2.invert);

        var attributeGroupContainer1 = attributeGroupContainer2.next;

        Assert.AreEqual("attrName1", attributeGroupContainer1.identifier);
        Assert.AreEqual(true, attributeGroupContainer1.invert);
        Assert.IsNull(attributeGroupContainer1.next);
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Takes on all the things after a 'style' keyword on the root level of a style file.
        /// </summary>
        /// <exception cref="ParseException"></exception>
        private void ParseStyle()
        {
            string     identifier        = null;
            string     tagName           = null;
            StyleToken initialStyleToken = tokenStream.Current;

            switch (initialStyleToken.styleTokenType)
            {
            // <TagName> { ... }
            case StyleTokenType.LessThan:
                tokenStream.Advance();
                AssertTokenType(StyleTokenType.Identifier);
                tagName = tokenStream.Current.value;
                tokenStream.Advance();
                if (tokenStream.Current.styleTokenType == StyleTokenType.LessThan)
                {
                    tagName += tokenStream.Current.value;
                    tokenStream.Advance();
                    tagName += tokenStream.Current.value;
                    AssertTokenTypeAndAdvance(StyleTokenType.Identifier);
                    tagName += tokenStream.Current.value;
                    AssertTokenTypeAndAdvance(StyleTokenType.GreaterThan);
                }

                AssertTokenTypeAndAdvance(StyleTokenType.GreaterThan);
                break;

            // styleId { ... }
            case StyleTokenType.Identifier:
                identifier = tokenStream.Current.value;
                tokenStream.Advance();
                break;

            default:
                throw new ParseException(initialStyleToken, $"Expected style definition or tag name but found {initialStyleToken.styleTokenType}");
            }

            StyleRootNode styleRootNode = StyleASTNodeFactory.StyleRootNode(identifier, tagName);

            styleRootNode.WithLocation(initialStyleToken);
            nodes.Add(styleRootNode);

            // we just read an element name or style name
            // now move forward and expect an open curly brace

            // next there should be one of those:
            // - property
            // - state
            // - attribute with or without boolean modifier
            // - expression with constants
            ParseStyleGroupBody(styleRootNode);
        }
Ejemplo n.º 4
0
        private UIStyleGroupContainer CompileStyleGroup(StyleRootNode styleRoot, AnimationData[] styleSheetAnimations, UISoundData[] uiSoundData)
        {
            UIStyleGroup defaultGroup = new UIStyleGroup();

            defaultGroup.normal = UIStyleRunCommand.CreateInstance();
            defaultGroup.name   = styleRoot.identifier ?? styleRoot.tagName;
            StyleType styleType = styleRoot.tagName != null ? StyleType.Implicit : StyleType.Shared;

            scratchGroupList.size = 0;

            scratchGroupList.Add(defaultGroup);

            CompileStyleGroups(styleRoot, styleType, scratchGroupList, defaultGroup, styleSheetAnimations, uiSoundData);

            return(new UIStyleGroupContainer(styleSheetImporter.NextStyleGroupId, defaultGroup.name, styleType, scratchGroupList.ToArray()));
        }
Ejemplo n.º 5
0
    public void ParseGridTemplateComplex()
    {
        LightList <StyleASTNode> nodes = StyleParser.Parse(@"
            style grid-thing {
                GridLayoutRowTemplate = repeat(4, 1mx) repeat(auto-fill, grow(1cnt, 300px) 300px) repeat(2, shrink(200px, 1fr));
            }
        ");

        Assert.AreEqual(1, nodes.Count);
        StyleRootNode rootNode = nodes[0] as StyleRootNode;

        Assert.AreEqual(1, rootNode.children.Count);
        PropertyNode propertyNode0 = (PropertyNode)rootNode.children[0];

        Assert.AreEqual(3, propertyNode0.children.Count);

        Assert.IsInstanceOf <StyleFunctionNode>(propertyNode0.children[0]);
        StyleFunctionNode repeat0 = propertyNode0.children[0] as StyleFunctionNode;
        StyleFunctionNode repeat1 = propertyNode0.children[1] as StyleFunctionNode;
        StyleFunctionNode repeat2 = propertyNode0.children[2] as StyleFunctionNode;

        AssertStyleNodesEqual(new StyleNodeTestDef()
        {
            type       = typeof(StyleFunctionNode),
            identifier = "repeat",
            children   = new[] {
                new StyleNodeTestDef()
                {
                    type     = typeof(StyleLiteralNode),
                    nodeType = StyleASTNodeType.NumericLiteral,
                    rawValue = "4"
                },
                StyleNodeTestDef.CreateMeasurementNode("1", "mx")
            }
        }, repeat0);

        AssertStyleNodesEqual(new StyleNodeTestDef()
        {
            type       = typeof(StyleFunctionNode),
            identifier = "repeat",
            children   = new[] {
                new StyleNodeTestDef()
                {
                    type       = typeof(StyleIdentifierNode),
                    nodeType   = StyleASTNodeType.Identifier,
                    identifier = "auto-fill"
                },
                new StyleNodeTestDef()
                {
                    type       = typeof(StyleFunctionNode),
                    identifier = "grow",
                    children   = new[] {
                        StyleNodeTestDef.CreateMeasurementNode("1", "cnt"),
                        StyleNodeTestDef.CreateMeasurementNode("300", "px")
                    }
                },
                StyleNodeTestDef.CreateMeasurementNode("300", "px")
            }
        }, repeat1);

        AssertStyleNodesEqual(new StyleNodeTestDef()
        {
            type       = typeof(StyleFunctionNode),
            identifier = "repeat",
            children   = new[] {
                new StyleNodeTestDef()
                {
                    type     = typeof(StyleLiteralNode),
                    nodeType = StyleASTNodeType.NumericLiteral,
                    rawValue = "2"
                },
                new StyleNodeTestDef()
                {
                    type       = typeof(StyleFunctionNode),
                    identifier = "shrink",
                    children   = new[] {
                        StyleNodeTestDef.CreateMeasurementNode("200", "px"),
                        StyleNodeTestDef.CreateMeasurementNode("1", "fr")
                    }
                }
            }
        }, repeat2);
    }