Exemple #1
0
 internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Colour colour)
 {
     if (!remainingWords.Peek().Text.StartsWith("#"))
     {
         colour = null;
         return false;
     }
     var word = remainingWords.Dequeue();
     colour = new Colour(parent) { Text = word.Text };
     return true;
 }
Exemple #2
0
        public void DoesDoVariableExample()
        {
            var host = new Host();
            var source =
            @"$blue: #3bbfce;
            $margin: 16px;

            .content-navigation {
              border-color: $blue;
              color:
            darken($blue, 9%);
            }

            .border {
              padding: $margin / 2;
              margin: $margin / 2;
              border-color: $blue;
            }
            ";
            var expected =
            @".content-navigation {
              border-color: #3bbfce;
              color: #2b9eab;
            }

            .border {
              padding: 8px;
              margin: 8px;
              border-color: #3bbfce;
            }

            ";
            var result = host.Execute(source,
                (string name, Parameters parameters, out Node node) =>
                {
                    node = new Colour(parameters.Parent) { Text = "#2b9eab" };
                    return true;
                });

            Assert.AreEqual(expected, result);
        }
Exemple #3
0
        internal static bool TryParse(Node parent, Queue <Word> remainingWords, out Expression expression)
        {
            expression = new Expression(parent);
            while (remainingWords.Count > 0 &&
                   remainingWords.Peek().Text != ";" &&
                   remainingWords.Peek().Text != "," &&
                   remainingWords.Peek().Text != ")" &&
                   remainingWords.Peek().Text != "}")
            {
                Add add;
                if (Add.TryParse(expression, remainingWords, out add))
                {
                    expression.Children.Add(add);
                }

                Subtract subtract;
                if (Subtract.TryParse(expression, remainingWords, out subtract))
                {
                    expression.Children.Add(subtract);
                }

                Multiply multiply;
                if (Multiply.TryParse(expression, remainingWords, out multiply))
                {
                    expression.Children.Add(multiply);
                }

                Divide divide;
                if (Divide.TryParse(expression, remainingWords, out divide))
                {
                    expression.Children.Add(divide);
                }

                Variable variable;
                if (Variable.TryParse(expression, remainingWords, out variable))
                {
                    expression.Children.Add(variable);
                    continue;
                }

                Colour colour;
                if (Colour.TryParse(expression, remainingWords, out colour))
                {
                    expression.Children.Add(colour);
                    continue;
                }

                Units unit;
                if (Units.TryParse(expression, remainingWords, out unit))
                {
                    expression.Children.Add(unit);
                    continue;
                }

                MethodCall methodCall;
                if (MethodCall.TryParse(expression, remainingWords, out methodCall))
                {
                    expression.Children.Add(methodCall);
                    continue;
                }

                if (remainingWords.Count > 0)
                {
                    var namedValue = new NamedValue(expression)
                    {
                        Text = remainingWords.Dequeue().Text
                    };
                    expression.Children.Add(namedValue);
                }
            }



            return(true);
        }