示例#1
0
 protected virtual object EvaluateValueValueList(CssNode node)
 {
     throw new System.Exception("Implement.");
 }
示例#2
0
        protected override object EvaluateSelectorLEFT_CURLY_BRACEDeclarationListRIGHT_CURLY_BRACE(CssNode node)
        {
            string Selector = (string)Evaluate(node.Nodes[0].Nodes[0]);

            if (node.Nodes[0].Nodes[1].Nodes.Count == 0)
            {
                this._styleRule = new StyleRule(Selector);
            }
            else
            {
                string key   = (string)Evaluate(node.Nodes[0].Nodes[1].Nodes[1]);
                string value = (string)Evaluate(node.Nodes[0].Nodes[1].Nodes[3]);
                this._styleRule = new KeyValueStyleRule(Selector, key, value);
            }
            this._styleSheet.Rules.Add(this._styleRule);

            // DeclarationList
            if (node.Nodes[2].Nodes.Count > 0)
            {
                Evaluate(node.Nodes[2]);
            }

            return(null);
        }
示例#3
0
 protected virtual object EvaluateIDENTIFIERSelectorTail(CssNode node)
 {
     throw new System.Exception("Implement.");
 }
示例#4
0
 protected virtual object EvaluateLEFT_BRACKETIDENTIFIEREQUALSSTRINGRIGHT_BRACKET(CssNode node)
 {
     throw new System.Exception("Implement.");
 }
示例#5
0
 protected virtual object EvaluateIDENTIFIERCOLONValueListSEMICOLON(CssNode node)
 {
     throw new System.Exception("Implement.");
 }
示例#6
0
 protected virtual object EvaluateSelectorLEFT_CURLY_BRACEDeclarationListRIGHT_CURLY_BRACE(CssNode node)
 {
     throw new System.Exception("Implement.");
 }
示例#7
0
        public object Evaluate(CssNode node)
        {
            switch (node.Type)
            {
            case CssNodeType.Declaration:
            {
                if (node.Nodes.Count == 4 && node.Nodes[0].Type == CssNodeType.IDENTIFIER && node.Nodes[1].Type == CssNodeType.COLON && node.Nodes[2].Type == CssNodeType.ValueList && node.Nodes[3].Type == CssNodeType.SEMICOLON)
                {
                    return(EvaluateIDENTIFIERCOLONValueListSEMICOLON(node));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CssNodeType.DeclarationList:
            {
                if (node.Nodes.Count == 2 && node.Nodes[0].Type == CssNodeType.Declaration && node.Nodes[1].Type == CssNodeType.DeclarationList)
                {
                    return(EvaluateDeclarationDeclarationList(node));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CssNodeType.Rule:
            {
                if (node.Nodes.Count == 4 && node.Nodes[0].Type == CssNodeType.Selector && node.Nodes[1].Type == CssNodeType.LEFT_CURLY_BRACE && node.Nodes[2].Type == CssNodeType.DeclarationList && node.Nodes[3].Type == CssNodeType.RIGHT_CURLY_BRACE)
                {
                    return(EvaluateSelectorLEFT_CURLY_BRACEDeclarationListRIGHT_CURLY_BRACE(node));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CssNodeType.RuleList:
            {
                if (node.Nodes.Count == 2 && node.Nodes[0].Type == CssNodeType.Rule && node.Nodes[1].Type == CssNodeType.RuleList)
                {
                    return(EvaluateRuleRuleList(node));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CssNodeType.Selector:
            {
                if (node.Nodes.Count == 2 && node.Nodes[0].Type == CssNodeType.IDENTIFIER && node.Nodes[1].Type == CssNodeType.SelectorTail)
                {
                    return(EvaluateIDENTIFIERSelectorTail(node));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CssNodeType.SelectorTail:
            {
                if (node.Nodes.Count == 5 && node.Nodes[0].Type == CssNodeType.LEFT_BRACKET && node.Nodes[1].Type == CssNodeType.IDENTIFIER && node.Nodes[2].Type == CssNodeType.EQUALS && node.Nodes[3].Type == CssNodeType.STRING && node.Nodes[4].Type == CssNodeType.RIGHT_BRACKET)
                {
                    return(EvaluateLEFT_BRACKETIDENTIFIEREQUALSSTRINGRIGHT_BRACKET(node));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CssNodeType.Value:
            {
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CssNodeType.IDENTIFIER)
                {
                    return(EvaluateIDENTIFIER(node.Nodes[0].Value));
                }
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CssNodeType.STRING)
                {
                    return(EvaluateSTRING(node.Nodes[0].Value));
                }
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CssNodeType.INTEGER)
                {
                    return(EvaluateINTEGER(node.Nodes[0].Value));
                }
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CssNodeType.FLOAT)
                {
                    return(EvaluateFLOAT(node.Nodes[0].Value));
                }
                if (node.Nodes.Count == 1 && node.Nodes[0].Type == CssNodeType.BOOLEAN)
                {
                    return(EvaluateBOOLEAN(node.Nodes[0].Value));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CssNodeType.ValueList:
            {
                if (node.Nodes.Count == 2 && node.Nodes[0].Type == CssNodeType.Value && node.Nodes[1].Type == CssNodeType.ValueList)
                {
                    return(EvaluateValueValueList(node));
                }
                throw new System.Exception("Invalid expression.");
            }

            case CssNodeType.BOOLEAN:
            {
                return(EvaluateBOOLEAN(node.Value));
            }

            case CssNodeType.COLON:
            {
                return(EvaluateCOLON(node.Value));
            }

            case CssNodeType.EQUALS:
            {
                return(EvaluateEQUALS(node.Value));
            }

            case CssNodeType.FLOAT:
            {
                return(EvaluateFLOAT(node.Value));
            }

            case CssNodeType.IDENTIFIER:
            {
                return(EvaluateIDENTIFIER(node.Value));
            }

            case CssNodeType.INTEGER:
            {
                return(EvaluateINTEGER(node.Value));
            }

            case CssNodeType.LEFT_BRACKET:
            {
                return(EvaluateLEFT_BRACKET(node.Value));
            }

            case CssNodeType.LEFT_CURLY_BRACE:
            {
                return(EvaluateLEFT_CURLY_BRACE(node.Value));
            }

            case CssNodeType.RIGHT_BRACKET:
            {
                return(EvaluateRIGHT_BRACKET(node.Value));
            }

            case CssNodeType.RIGHT_CURLY_BRACE:
            {
                return(EvaluateRIGHT_CURLY_BRACE(node.Value));
            }

            case CssNodeType.SEMICOLON:
            {
                return(EvaluateSEMICOLON(node.Value));
            }

            case CssNodeType.STRING:
            {
                return(EvaluateSTRING(node.Value));
            }

            default:
            {
                throw new System.Exception("Invalid expression.");
            }
            }
        }
示例#8
0
 public static void Print(CssNode node, System.IO.TextWriter writer)
 {
     Print(node, writer, 0);
 }
示例#9
0
        private static void Print(CssNode node, System.IO.TextWriter writer, int indentationLevel)
        {
            switch (node.Type)
            {
            case CssNodeType.Declaration:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("Declaration:");
                foreach (CssNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CssNodeType.DeclarationList:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("DeclarationList:");
                foreach (CssNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CssNodeType.Rule:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("Rule:");
                foreach (CssNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CssNodeType.RuleList:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("RuleList:");
                foreach (CssNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CssNodeType.Selector:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("Selector:");
                foreach (CssNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CssNodeType.SelectorTail:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("SelectorTail:");
                foreach (CssNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CssNodeType.Value:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("Value:");
                foreach (CssNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CssNodeType.ValueList:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("ValueList:");
                foreach (CssNode node2 in node.Nodes)
                {
                    Print(node2, writer, indentationLevel + 1);
                }
                break;
            }

            case CssNodeType.BOOLEAN:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("BOOLEAN: " + node.Value);
                break;
            }

            case CssNodeType.COLON:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("COLON: " + node.Value);
                break;
            }

            case CssNodeType.EPSILON:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("EPSILON: " + node.Value);
                break;
            }

            case CssNodeType.EQUALS:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("EQUALS: " + node.Value);
                break;
            }

            case CssNodeType.FLOAT:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("FLOAT: " + node.Value);
                break;
            }

            case CssNodeType.IDENTIFIER:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("IDENTIFIER: " + node.Value);
                break;
            }

            case CssNodeType.INTEGER:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("INTEGER: " + node.Value);
                break;
            }

            case CssNodeType.LEFT_BRACKET:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("LEFT_BRACKET: " + node.Value);
                break;
            }

            case CssNodeType.LEFT_CURLY_BRACE:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("LEFT_CURLY_BRACE: " + node.Value);
                break;
            }

            case CssNodeType.RIGHT_BRACKET:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("RIGHT_BRACKET: " + node.Value);
                break;
            }

            case CssNodeType.RIGHT_CURLY_BRACE:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("RIGHT_CURLY_BRACE: " + node.Value);
                break;
            }

            case CssNodeType.SEMICOLON:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("SEMICOLON: " + node.Value);
                break;
            }

            case CssNodeType.STRING:
            {
                for (int i = 0; i < indentationLevel; i++)
                {
                    System.Console.Write("   ");
                }
                System.Console.WriteLine("STRING: " + node.Value);
                break;
            }

            default:
            {
                throw new System.Exception("Invalid node type.");
            }
            }
        }
示例#10
0
        private void Generate(CssNode node, System.IO.TextWriter writer, ref bool writeWhitespace)
        {
            switch (node.Type)
            {
            case CssNodeType.Declaration:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CssNodeType.DeclarationList:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CssNodeType.Rule:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CssNodeType.RuleList:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CssNodeType.Selector:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CssNodeType.SelectorTail:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CssNodeType.Value:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CssNodeType.ValueList:
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    Generate(node.Nodes[i], writer, ref writeWhitespace);
                }
                break;
            }

            case CssNodeType.BOOLEAN:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.COLON:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.EPSILON:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.EQUALS:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.FLOAT:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.IDENTIFIER:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.INTEGER:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.LEFT_BRACKET:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.LEFT_CURLY_BRACE:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.RIGHT_BRACKET:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.RIGHT_CURLY_BRACE:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.SEMICOLON:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            case CssNodeType.STRING:
            {
                if (writeWhitespace)
                {
                    writer.Write(" ");
                }
                writer.Write(node.Value);
                writeWhitespace = true;
                break;
            }

            default:
            {
                throw new System.Exception("Invalid node type.");
            }
            }
        }
示例#11
0
        public void Generate(CssNode node, System.IO.TextWriter writer)
        {
            bool writeWhitespace = false;

            Generate(node, writer, ref writeWhitespace);
        }