Beispiel #1
0
 public override Node Clone(Node newParent)
 {
     var newAssignment = new PropertyAssignment(newParent);
     newAssignment.Name = Name;
     newAssignment.Value = Value.Clone(newAssignment);
     return newAssignment;
 }
Beispiel #2
0
        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out PropertyAssignment property)
        {
            if (remainingWords.Skip(1).First().Text != ":")
            {
                property = null;
                return false;
            }

            property = new PropertyAssignment(parent);
            property.Name = remainingWords.Dequeue().Text;
            // remove ':'
            remainingWords.Dequeue();

            Block block;
            if (Block.TryParse(property, remainingWords, out block))
            {
                property.Value = block;
                return true;
            }
            Expression expression;
            if (Expression.TryParse(property, remainingWords, out expression))
            {
                property.Value = expression;
                // remove ';'
                if (remainingWords.Peek().Text == ";")
                {
                    remainingWords.Dequeue();
                }
                return true;
            }

            property = null;
            return false;
        }
Beispiel #3
0
        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out IncludeDirective directive)
        {
            directive = null;
            if (remainingWords.Peek().Text != "@include")
            {
                return false;
            }

            directive = new IncludeDirective(parent);
            // remove '@include'
            remainingWords.Dequeue();

            Expression expression;
            if (!Expression.TryParse(directive, remainingWords, out expression))
            {
                throw new Exception("errp?");
            }
            // remove ';'
            if (remainingWords.Peek().Text == ";")
            {
                remainingWords.Dequeue();
            }
            directive.Name = expression;

            return true;
        }
Beispiel #4
0
        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Parameters parameters)
        {
            if (remainingWords.Count == 0 ||
                remainingWords.Peek().Text != "(")
            {
                parameters = null;
                return false;
            }
            remainingWords.Dequeue();

            parameters = new Parameters(parent);
            while (remainingWords.Peek().Text != ")")
            {
                if (remainingWords.Peek().Text == ",")
                {
                    remainingWords.Dequeue();
                    continue;
                }

                Expression expression;
                if (Expression.TryParse(parent, remainingWords, out expression))
                {
                    parameters.Children.Add(expression);
                    continue;
                }
            }
            remainingWords.Dequeue();

            return true;
        }
Beispiel #5
0
        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out ExtendDirective directive)
        {
            directive = null;
            if (remainingWords.Peek().Text != "@extend")
            {
                return false;
            }

            directive = new ExtendDirective(parent);
            directive.Name = remainingWords.Dequeue().Text.Substring(1);

            Expression expression;
            if (!Expression.TryParse(directive, remainingWords, out expression))
            {
                throw new Exception("errp?");
            }
            // remove ';'
            if (remainingWords.Peek().Text == ";")
            {
                remainingWords.Dequeue();
            }
            directive.Value = expression;

            return true;
        }
Beispiel #6
0
        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out MixinDefinition definition)
        {
            definition = null;
            if (remainingWords.Peek().Text != "@mixin")
            {
                return false;
            }

            definition = new MixinDefinition(parent);
            // remove '@mixin'
            remainingWords.Dequeue();

            var remainingNameWords = new Queue<Word>();
            while (remainingWords.Peek().Text != "{")
            {
                remainingNameWords.Enqueue(remainingWords.Dequeue());
            }

            Expression name;
            if (!Expression.TryParse(definition, remainingNameWords, out name))
            {
                throw new Exception("errp?");
            }
            definition.Name = name;

            Block block;
            if (!Block.TryParse(definition, remainingWords, out block))
            {
                throw new Exception("erh?");
            }
            definition.Value = block;
            return true;
        }
Beispiel #7
0
 public override Node Clone(Node newParent)
 {
     var newDirective = new ExtendDirective(newParent);
     newDirective.Name = Name;
     newDirective.Value = Value.Clone(newDirective);
     return newDirective;
 }
Beispiel #8
0
 public override Node Clone(Node newParent)
 {
     var newSelector = new Selector(newParent);
     newSelector.Names = new List<string>(Names);
     newSelector.Block = (Block)Block.Clone(newSelector);
     return newSelector;
 }
Beispiel #9
0
        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Selector selector)
        {
            var openingBraceFound = false;
            foreach (var word in remainingWords)
            {
                if (word.Text == "{")
                {
                    openingBraceFound = true;
                    break;
                }
            }

            if (!openingBraceFound)
            {
                selector = null;
                return false;
            }

            selector = new Selector(parent);
            while (remainingWords.Peek().Text != "{")
            {
                selector.Names.Add(remainingWords.Dequeue().Text);
            }
            Block block;
            if (!Block.TryParse(selector, remainingWords, out block))
            {
                selector = null;
                return false;
            }
            selector.Block = block;
            return true;
        }
Beispiel #10
0
 public override Node Clone(Node newParent)
 {
     var newDefinition = new MixinDefinition(newParent);
     newDefinition.Name = (Expression)Name.Clone(newDefinition);
     newDefinition.Value = Value.Clone(newDefinition);
     return newDefinition;
 }
Beispiel #11
0
        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Script script)
        {
            script = new Script(parent);

            do
            {
                MixinDefinition mixinDefinition;
                if (MixinDefinition.TryParse(script, remainingWords, out mixinDefinition))
                {
                    script.Children.Add(mixinDefinition);
                    continue;
                }

                VariableAssignment variableAssignment;
                if (VariableAssignment.TryParse(script, remainingWords, out variableAssignment))
                {
                    script.Children.Add(variableAssignment);
                    continue;
                }

                Selector selector;
                if (Selector.TryParse(script, remainingWords, out selector))
                {
                    script.Children.Add(selector);
                    continue;
                }
            }
            while (remainingWords.Count > 0);

            return true;
        }
Beispiel #12
0
 public override Node Clone(Node newParent)
 {
     var newMethodCall = new MethodCall(newParent);
     newMethodCall.Name = Name;
     newMethodCall.Parameters = (Parameters)Parameters.Clone(newMethodCall);
     newMethodCall.CalculatedValue = CalculatedValue.Clone(newParent);
     return newMethodCall;
 }
Beispiel #13
0
 public override Node Clone(Node newParent)
 {
     var newParameters = new Parameters(newParent);
     foreach (var child in Children)
     {
         newParameters.Children.Add(child.Clone(newParameters));
     }
     return newParameters;
 }
Beispiel #14
0
 public override Node Clone(Node newParent)
 {
     var newExpression = new Expression(newParent);
     foreach (var child in Children)
     {
         newExpression.Children.Add(child.Clone(newExpression));
     }
     return newExpression;
 }
Beispiel #15
0
        public override Node Clone(Node newParent)
        {
            var newScript = new Script(newParent);
            foreach (var child in Children)
            {
                newScript.Children.Add(child.Clone(newScript));
            }

            return newScript;
        }
Beispiel #16
0
        public override Node Clone(Node newParent)
        {
            var newBlock = new Block(newParent);
            foreach (var child in Children)
            {
                newBlock.Children.Add(child.Clone(newBlock));
            }

            return newBlock;
        }
Beispiel #17
0
 internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Variable variable)
 {
     if (!remainingWords.Peek().Text.StartsWith("$"))
     {
         variable = null;
         return false;
     }
     var word = remainingWords.Dequeue();
     variable = new Variable(parent) { Name = word.Text, SourceLine = word.Line };
     return true;
 }
Beispiel #18
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;
 }
Beispiel #19
0
Datei: Add.cs Projekt: lzcd/Crass
 internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Add add)
 {
     if (remainingWords.Peek().Text != "+")
     {
         add = null;
         return false;
     }
     var word = remainingWords.Dequeue();
     add = new Add(parent);
     return true;
 }
Beispiel #20
0
 internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Subtract subtract)
 {
     if (remainingWords.Peek().Text != "-")
     {
         subtract = null;
         return false;
     }
     var word = remainingWords.Dequeue();
     subtract = new Subtract(parent);
     return true;
 }
Beispiel #21
0
 internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Multiply multiply)
 {
     if (remainingWords.Peek().Text != "*")
     {
         multiply = null;
         return false;
     }
     var word = remainingWords.Dequeue();
     multiply = new Multiply(parent);
     return true;
 }
Beispiel #22
0
 internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Divide divide)
 {
     if (remainingWords.Peek().Text != "/")
     {
         divide = null;
         return false;
     }
     var word = remainingWords.Dequeue();
     divide = new Divide(parent);
     return true;
 }
Beispiel #23
0
        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Block block)
        {
            if (remainingWords.Peek().Text != "{")
            {
                block = null;
                return false;
            }
            remainingWords.Dequeue();

            block = new Block(parent);
            while (remainingWords.Peek().Text != "}")
            {
                IncludeDirective includeDirective;
                if (IncludeDirective.TryParse(block, remainingWords, out includeDirective))
                {
                    block.Children.Add(includeDirective);
                    continue;
                }

                ExtendDirective excludeDirective;
                if (ExtendDirective.TryParse(block, remainingWords, out excludeDirective))
                {
                    block.Children.Add(excludeDirective);
                    continue;
                }

                PropertyAssignment property;
                if (PropertyAssignment.TryParse(block, remainingWords, out property))
                {
                    block.Children.Add(property);
                    continue;
                }

                Selector selector;
                if (Selector.TryParse(block, remainingWords, out selector))
                {
                    block.Children.Add(selector);
                    continue;
                }
            }
            remainingWords.Dequeue();

            return true;
        }
Beispiel #24
0
 internal static bool TryParse(Node parent, Queue<Word> remainingWords, out Units units)
 {
     int firstDigit;
     if (!int.TryParse(remainingWords.Peek().Text.Substring(0,1), out firstDigit))
     {
         units = null;
         return false;
     }
     var text = remainingWords.Dequeue().Text;
     var index = 0;
     while (index < text.Length &&
         text.Substring(index, 1).IndexOfAny(numericCharacters) >= 0)
     {
         index++;
     }
     var amount = Decimal.Parse(text.Substring(0, index));
     var unit = text.Substring(index);
     units = new Units(parent) { Amount = amount, Unit = unit };
     return true;
 }
Beispiel #25
0
 internal static bool TryParse(Node parent, Queue<Word> remainingWords, out VariableAssignment assignment)
 {
     assignment = null;
     if (!remainingWords.Peek().Text.StartsWith("$"))
     {
         return false;
     }
     var word = remainingWords.Dequeue();
     assignment = new VariableAssignment(parent) { Name = word.Text, SourceLine = word.Line };
     // remove ':'
     remainingWords.Dequeue();
     Expression expression;
     if (!Expression.TryParse(assignment, remainingWords, out expression))
     {
         return false;
     }
     // remove ';'
     remainingWords.Dequeue();
     assignment.Expression = expression;
     return true;
 }
Beispiel #26
0
        internal static bool TryParse(Node parent, Queue<Word> remainingWords, out MethodCall methodCall)
        {
            if (remainingWords.Count < 2 ||
                remainingWords.Skip(1).First().Text != "(")
            {
                methodCall = null;
                return false;
            }

            methodCall = new MethodCall(parent);

            methodCall.Name = remainingWords.Dequeue().Text;
            Parameters parameters;
            if (!Parameters.TryParse(methodCall, remainingWords, out parameters))
            {
                methodCall = null;
                return false;
            }

            methodCall.Parameters = parameters;

            return true;
        }
Beispiel #27
0
 public abstract Node Clone(Node newParent);
Beispiel #28
0
 public Node(Node parent)
 {
     Parent = parent;
 }
Beispiel #29
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;
        }
Beispiel #30
0
 public Expression(Node parent)
     : base(parent)
 {
     Children = new List<Node>();
 }