コード例 #1
0
ファイル: PropertyAssignment.cs プロジェクト: lzcd/Crass
 public override Node Clone(Node newParent)
 {
     var newAssignment = new PropertyAssignment(newParent);
     newAssignment.Name = Name;
     newAssignment.Value = Value.Clone(newAssignment);
     return newAssignment;
 }
コード例 #2
0
ファイル: PropertyAssignment.cs プロジェクト: lzcd/Crass
        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;
        }
コード例 #3
0
ファイル: IncludeDirective.cs プロジェクト: lzcd/Crass
        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;
        }
コード例 #4
0
ファイル: Parameters.cs プロジェクト: lzcd/Crass
        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;
        }
コード例 #5
0
ファイル: ExtendDirective.cs プロジェクト: lzcd/Crass
        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;
        }
コード例 #6
0
ファイル: MixinDefinition.cs プロジェクト: lzcd/Crass
        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;
        }
コード例 #7
0
ファイル: ExtendDirective.cs プロジェクト: lzcd/Crass
 public override Node Clone(Node newParent)
 {
     var newDirective = new ExtendDirective(newParent);
     newDirective.Name = Name;
     newDirective.Value = Value.Clone(newDirective);
     return newDirective;
 }
コード例 #8
0
ファイル: Selector.cs プロジェクト: lzcd/Crass
 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;
 }
コード例 #9
0
ファイル: Selector.cs プロジェクト: lzcd/Crass
        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;
        }
コード例 #10
0
ファイル: MixinDefinition.cs プロジェクト: lzcd/Crass
 public override Node Clone(Node newParent)
 {
     var newDefinition = new MixinDefinition(newParent);
     newDefinition.Name = (Expression)Name.Clone(newDefinition);
     newDefinition.Value = Value.Clone(newDefinition);
     return newDefinition;
 }
コード例 #11
0
ファイル: Script.cs プロジェクト: lzcd/Crass
        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;
        }
コード例 #12
0
ファイル: MethodCall.cs プロジェクト: lzcd/Crass
 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;
 }
コード例 #13
0
ファイル: Parameters.cs プロジェクト: lzcd/Crass
 public override Node Clone(Node newParent)
 {
     var newParameters = new Parameters(newParent);
     foreach (var child in Children)
     {
         newParameters.Children.Add(child.Clone(newParameters));
     }
     return newParameters;
 }
コード例 #14
0
ファイル: Expression.cs プロジェクト: lzcd/Crass
 public override Node Clone(Node newParent)
 {
     var newExpression = new Expression(newParent);
     foreach (var child in Children)
     {
         newExpression.Children.Add(child.Clone(newExpression));
     }
     return newExpression;
 }
コード例 #15
0
ファイル: Script.cs プロジェクト: lzcd/Crass
        public override Node Clone(Node newParent)
        {
            var newScript = new Script(newParent);
            foreach (var child in Children)
            {
                newScript.Children.Add(child.Clone(newScript));
            }

            return newScript;
        }
コード例 #16
0
ファイル: Block.cs プロジェクト: lzcd/Crass
        public override Node Clone(Node newParent)
        {
            var newBlock = new Block(newParent);
            foreach (var child in Children)
            {
                newBlock.Children.Add(child.Clone(newBlock));
            }

            return newBlock;
        }
コード例 #17
0
ファイル: Variable.cs プロジェクト: lzcd/Crass
 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;
 }
コード例 #18
0
ファイル: Colour.cs プロジェクト: lzcd/Crass
 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;
 }
コード例 #19
0
ファイル: Add.cs プロジェクト: 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;
 }
コード例 #20
0
ファイル: Subtract.cs プロジェクト: lzcd/Crass
 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;
 }
コード例 #21
0
ファイル: Multiply.cs プロジェクト: lzcd/Crass
 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;
 }
コード例 #22
0
ファイル: Divide.cs プロジェクト: lzcd/Crass
 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;
 }
コード例 #23
0
ファイル: Block.cs プロジェクト: lzcd/Crass
        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;
        }
コード例 #24
0
ファイル: Units.cs プロジェクト: lzcd/Crass
 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;
 }
コード例 #25
0
ファイル: VariableAssignment.cs プロジェクト: lzcd/Crass
 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;
 }
コード例 #26
0
ファイル: MethodCall.cs プロジェクト: lzcd/Crass
        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;
        }
コード例 #27
0
ファイル: Node.cs プロジェクト: lzcd/Crass
 public abstract Node Clone(Node newParent);
コード例 #28
0
ファイル: Node.cs プロジェクト: lzcd/Crass
 public Node(Node parent)
 {
     Parent = parent;
 }
コード例 #29
0
ファイル: Expression.cs プロジェクト: lzcd/Crass
        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;
        }
コード例 #30
0
ファイル: Expression.cs プロジェクト: lzcd/Crass
 public Expression(Node parent)
     : base(parent)
 {
     Children = new List<Node>();
 }