public override Value ReadStartValue(CssLexer lexer) { // Read off the at: lexer.Read(); // Read the name now: string name = lexer.ReadString(); // Skip any junk: lexer.SkipJunk(); // Map to an at rule: CssAtRule rule = CssAtRules.GetLocal(name); if (rule == null) { // Unrecognised - enter error recovery mode: lexer.ErrorRecovery(); // Done: return(null); } // Create the representitive unit: AtRuleUnit at = new AtRuleUnit(); at.AtRule = rule; // Now in @ mode: rule.SetupParsing(lexer); return(at); }
public override Value ReadStartValue(CssLexer lexer) { // Skip the [: lexer.Read(); // Note that we do not read off the close bracket. // This is so the lexer knows it's done reading the value // and can terminate accordingly. SquareBracketUnit block = new SquareBracketUnit(); // Create the value: ValueSet cValue = new ValueSet(); List <Css.Value> values = new List <Css.Value>(); // Keep reading single values until a ] is reached. while (lexer.Peek() != '\0') { // Skip junk: lexer.SkipJunk(); // Read the value: Css.Value value = lexer.ReadSingleValue(); if (value.Type == ValueType.Text) { if (value.Text == "]") { break; } } values.Add(value); } cValue.Count = values.Count; // Copy over: for (int i = 0; i < values.Count; i++) { cValue[i] = values[i]; } block.Value = cValue; return(block); }
public override Value ReadStartValue(CssLexer lexer) { // Skip the hash: lexer.Read(); if (lexer.SelectorMode) { // Just a hash (ID selector): return(new TextUnit("#")); } // Read the hex string now: string hex = lexer.ReadString(); ColourUnit result = new ColourUnit(); result.SetHex(hex); return(result); }
public override Value ReadStartValue(CssLexer lexer) { // No longer in selector mode: lexer.SelectorMode = false; // Skip the {: lexer.Read(); if (lexer.PropertyMapMode) { // Clear: lexer.PropertyMapMode = false; // Create map: PropertyMapUnit map = new PropertyMapUnit(); // Create the style: Style mapStyle = new Style(lexer.Scope); // Read the values: mapStyle.LoadProperties(lexer, delegate(Style s, string pName, Css.Value value){ return(map.OnReadProperty(s, pName, value)); }); map.Style = mapStyle; return(map); } // Result: SelectorBlockUnit block = new SelectorBlockUnit(); if (lexer.AtRuleMode) { // Clear at rule mode: lexer.AtRuleMode = false; List <Rule> rules = null; lexer.SkipJunk(); while (lexer.Peek() != '}' && lexer.Peek() != '\0') { Rule[] set; Rule single = lexer.ReadRules(out set); if (single == null) { if (set != null) { if (rules == null) { rules = new List <Rule>(); } for (int x = 0; x < set.Length; x++) { rules.Add(set[x]); } } } else { if (rules == null) { rules = new List <Rule>(); } rules.Add(single); } lexer.SkipJunk(); } block.Rules = rules; } else { // Create the style: Style style = new Style(lexer.Scope); // Read the values: style.LoadProperties(lexer, null); block.Style = style; } // Note that we do not read off the close bracket. // This is so the lexer knows it's done reading the value // and can terminate accordingly. return(block); }
public override Value ReadStartValue(CssLexer lexer) { // Skip quote: char quote = lexer.Read(); char current = lexer.Read(); bool delimMode = false; StringBuilder result = lexer.Builder; result.Length = 0; while ((delimMode || current != quote) && current != '\0') { if (delimMode) { if (current == quote) { result.Append(current); delimMode = false; } else if (current == '\n' || current == '\f') { // Ignore it - act like it's not there. delimMode = false; } else if (current == '\r') { // Must we ignore an \n too? current = lexer.Peek(); if (current == '\n') { // Yep - Ignore it too: lexer.Read(); } delimMode = false; } else { // Unicode character? [0-9a-f]{1,6} delimMode = false; int charIndex = (int)current; bool unicode = false; int charcode = 0; for (int i = 0; i < 6; i++) { if (charIndex >= (int)'0' && charIndex <= (int)'9') { // Apply to charcode: charcode = (charcode << 4) | (charIndex - (int)'0'); // Move on: current = lexer.Read(); charIndex = (int)current; unicode = true; } else if (charIndex >= (int)'a' && charIndex <= (int)'f') { // Apply to charcode: charcode = (charcode << 4) | (charIndex + 10 - (int)'a'); // Move on: current = lexer.Read(); charIndex = (int)current; unicode = true; } else { // No longer valid unicode. break; } } if (unicode) { result.Append(char.ConvertFromUtf32(charcode)); // Don't read another character, unless the current one should be ignored. if (current == '\r') { current = lexer.Peek(); if (current == '\n') { lexer.Read(); } } else if (current == ' ' || current == '\n' || current == '\t' || current == '\f') { // Ignore this char. } else { // Append it: continue; } } else { // It's any other character: result.Append(current); } } } else if (current == '\\') { delimMode = true; } else { result.Append(current); } current = lexer.Read(); } return(new TextUnit(result.ToString())); }