/// <summary> /// 5.4.3. Consume a qualified rule /// </summary> /// <returns></returns> private QualifiedRule ConsumeQualifiedRule() { //To consume a qualified rule: //Create a new qualified rule with its prelude initially set to an empty list, and its value initially set to nothing. QualifiedRule rule = new QualifiedRule(); // set operation is performed by CTOR. int startindex = -1; cssToken token = null; while (true) { //Repeatedly consume the next input token: token = ConsumeNextToken(); if (startindex == -1) { startindex = token.startIndex; } //<EOF-token> if (token.Type == enumTokenType.EOF) { //This is a parse error. Return nothing. return(null); } //<{-token> else if (token.Type == enumTokenType.curly_bracket_left) { //Consume a simple block and assign it to the qualified rule’s block. Return the qualified rule. SimpleBlock block = ConsumeSimpleBlock(); block.startindex = token.startIndex; rule.block = block; rule.startindex = startindex; rule.endindex = block.endindex; return(rule); } //simple block with an associated token of <{-token> //???????TODO: this must be an mistake in the syntax paper.. //Assign the block to the qualified rule’s block. Return the qualified rule. //anything else else { //Reconsume the current input token. Consume a component value. Append the returned value to the qualified rule’s prelude. ReconsumeToken(); ComponentValue value = ConsumeComponentValue(); rule.prelude.Add(value); } } }
/// <summary> /// From W3C, in most case, th preclude matchs to Selector and block value contains declaration. /// </summary> /// <param name="rule"></param> /// <returns></returns> private static CSSRule ParseQualifiedRule(QualifiedRule rule, ref string OriginalCss) { CSSStyleRule cssrule = new CSSStyleRule(); string selectorText = string.Empty; int startindex = -1; int endindex = -1; int endindexselector = -1; selectorText = ComponentValueExtension.getString(rule.prelude, ref startindex, ref endindexselector, ref OriginalCss); cssrule.selectorText = selectorText; cssrule.style = ParseDeclarations(rule.block, ref endindex, ref OriginalCss); cssrule.StartIndex = rule.startindex; cssrule.EndIndex = rule.endindex; cssrule.EndSelectorIndex = endindexselector - cssrule.StartIndex + 1; return(cssrule); }
/// <summary> /// 5.4.1. Consume a list of rules /// </summary> /// <param name="tokenizer"></param> /// <param name="top_level_flag"></param> /// <returns></returns> private List <Rule> ConsumeListOfRules(bool top_level_flag) { //To consume a list of rules: //Create an initially empty list of rules. List <Rule> rulelist = new List <Rule>(); cssToken token; while (true) { //Repeatedly consume the next input token: token = ConsumeNextToken(); //<whitespace-token> if (token.Type == enumTokenType.whitespace) { //Do nothing. } //<EOF-token> else if (token.Type == enumTokenType.EOF) { //Return the list of rules. return(rulelist); } //<CDO-token> //<CDC-token> else if (token.Type == enumTokenType.CDC || token.Type == enumTokenType.CDO) { //If the top-level flag is set, do nothing. if (!top_level_flag) { //Otherwise, reconsume the current input token. Consume a qualified rule. If anything is returned, append it to the list of rules. ReconsumeToken(); QualifiedRule rule = ConsumeQualifiedRule(); if (rule != null) { rulelist.Add(rule); } } } //<at-keyword-token> else if (token.Type == enumTokenType.at_keyword) { //Reconsume the current input token. Consume an at-rule. If anything is returned, append it to the list of rules. ReconsumeToken(); AtRule rule = ConsumeAtRule(); if (rule != null) { rulelist.Add(rule); } } //anything else else { //Reconsume the current input token. Consume a qualified rule. If anything is returned, append it to the list of rules. ReconsumeToken(); QualifiedRule rule = ConsumeQualifiedRule(); if (rule != null) { rulelist.Add(rule); } } } }