Пример #1
0
        public void Parse(CompileContext context, System.Xml.XmlNode node)
        {
            if (node.Attributes["Value"] != null)
            {
                ASTScalar scalar = new ASTScalar();
                scalar.Parse(context, Token.StackForm(Token.Tokenize(node.Attributes["Value"].InnerText)));

                data = scalar.Scalar;
            }
            else
            {
                throw new ParseException("Value of scalar not present in 'Value' attribute.");
            }
        }
Пример #2
0
        public void Parse(CompileContext context, Stack <Token> stream)
        {
            float pixel = 0.0f, parent = 0.0f, canvas = 0.0f;

            // We now parse until unknown token is found.
            Token token;

            while (true)
            {
                token = stream.Pop();
                bool?sign = true;

                // May be '+' or '-'.
                if (token.TokenId == TokenId.Plus)
                {
                    sign  = true;
                    token = stream.Pop();
                }
                else if (token.TokenId == TokenId.Minus)
                {
                    sign  = false;
                    token = stream.Pop();
                }

                // We parse number.
                if (token.TokenId != TokenId.Number)
                {
                    stream.Push(token);
                    if (sign.HasValue)
                    {
                        throw new ParseException("Number expected after +/-");
                    }
                    break;
                }

                float  number    = float.Parse(token.Identifier);
                string specifier = "p";

                // We parse specifier
                token = stream.Pop();

                // We also allow '%' elements, id specifier is empty.
                if (token.TokenId == TokenId.Percent)
                {
                    if (token.TokenId == TokenId.Percent)
                    {
                        number *= 0.01f;
                    }

                    token = stream.Pop();
                }
                else if (token.TokenId == TokenId.Identifier)
                {
                    specifier = token.Identifier;

                    token = stream.Pop();
                }

                if (sign.HasValue)
                {
                    number *= sign.Value ? 1.0f : -1.0f;
                }

                // We apply values.
                specifier = specifier.ToLower();
                if (specifier == "p")
                {
                    parent += number;
                }
                else if (specifier == "px")
                {
                    pixel += number;
                }
                else if (specifier == "c")
                {
                    canvas += number;
                }
                else
                {
                    throw new ParseException("Scalar parsing failed: expected '', 'p', 'px' or 'c' specifier");
                }

                stream.Push(token);
                // We now need '+', or we break it.
                if (token.TokenId != TokenId.Plus && token.TokenId != TokenId.Minus)
                {
                    break;
                }

                // We do not pop it, part of stream.
            }

            data = new GuiScalar(pixel, canvas, parent);
        }