/// <summary> /// Called before the property name has been detected. /// </summary> public void CreateDeclarationWith(ICssProperties properties, ref CssToken token) { CollectTrivia(ref token); var start = token.Position; if (token.IsNot(CssTokenType.EndOfFile, CssTokenType.CurlyBracketClose, CssTokenType.Colon) && token.IsNot(CssTokenType.Semicolon, CssTokenType.CurlyBracketOpen)) { var name = token.Data; while (token.Type == CssTokenType.Delim) { token = NextToken(); name += token.Data; } token = NextToken(); CollectTrivia(ref token); if (token.Type == CssTokenType.Colon) { token = NextToken(); CollectTrivia(ref token); var value = CreateValue(ref token, out var important); if (String.IsNullOrEmpty(value)) { RaiseErrorOccurred(CssParseError.ValueMissing, token.Position); } else { properties.SetProperty(name, value, important ? CssKeywords.Important : null); } } else { RaiseErrorOccurred(CssParseError.ColonMissing, token.Position); } JumpToDeclEnd(ref token); } else if (token.Type != CssTokenType.EndOfFile) { RaiseErrorOccurred(CssParseError.IdentExpected, start); JumpToDeclEnd(ref token); } if (token.Type == CssTokenType.Semicolon) { token = NextToken(); } }
private void JumpToEnd(ref CssToken current) { while (current.IsNot(CssTokenType.EndOfFile, CssTokenType.Semicolon)) { current = NextToken(); } }
/// <summary> /// Fills the given parent style with declarations given by the tokens. /// </summary> public CssStyleDeclaration FillDeclarations(CssStyleDeclaration style, CssToken token) { CollectTrivia(ref token); while (token.IsNot(CssTokenType.EndOfFile, CssTokenType.CurlyBracketClose)) { CreateDeclarationWith(style, ref token); CollectTrivia(ref token); } return(style); }
public List<CssMedium> CreateMedia(ref CssToken token) { var list = new List<CssMedium>(); while (token.Type != CssTokenType.Eof) { var medium = CreateMedium(ref token); if (medium == null || token.IsNot(CssTokenType.Comma, CssTokenType.Eof)) throw new DomException(DomError.Syntax); list.Add(medium); token = _tokenizer.Get(); } return list; }
/// <summary> /// State that is called once we are in a CSS selector. /// </summary> ISelector CreateSelector(ref CssToken token) { var selector = Pool.NewSelectorConstructor(); _tokenizer.State = CssParseMode.Selector; var start = token; while (token.IsNot(CssTokenType.Eof, CssTokenType.CurlyBracketOpen, CssTokenType.CurlyBracketClose)) { selector.Apply(token); token = _tokenizer.Get(); } if (selector.IsValid == false) RaiseErrorOccurred(CssParseError.InvalidSelector, start); _tokenizer.State = CssParseMode.Data; return selector.ToPool(); }
/// <summary> /// Creates a list of CssMedium objects. /// </summary> public List<CssMedium> CreateMedia(ref CssToken token) { var list = new List<CssMedium>(); CollectTrivia(ref token); while (token.Type != CssTokenType.EndOfFile) { var medium = CreateMedium(ref token); if (medium == null || token.IsNot(CssTokenType.Comma, CssTokenType.EndOfFile)) throw new DomException(DomError.Syntax); token = NextToken(); CollectTrivia(ref token); list.Add(medium); } return list; }
private MediaFeature CreateFeature(ref CssToken token) { if (token.Type == CssTokenType.Ident) { var start = token.Position; var val = CssValue.Empty; var feature = _parser.Options.IsToleratingInvalidConstraints ? new UnknownMediaFeature(token.Data) : Factory.MediaFeatures.Create(token.Data); token = NextToken(); if (token.Type == CssTokenType.Colon) { var value = Pool.NewValueBuilder(); token = NextToken(); while (token.IsNot(CssTokenType.RoundBracketClose, CssTokenType.EndOfFile) || !value.IsReady) { value.Apply(token); token = NextToken(); } val = value.ToPool(); } else if (token.Type == CssTokenType.EndOfFile) { return null; } if (feature != null && feature.TrySetValue(val)) { var node = feature as CssNode; if (node != null) { var end = token.Position.Shift(-1); node.SourceCode = CreateView(start, end); } return feature; } } else { JumpToArgEnd(ref token); } return null; }
private CssValue CreateValue(CssTokenType closing, ref CssToken token, out Boolean important) { var value = Pool.NewValueBuilder(); _tokenizer.IsInValue = true; token = NextToken(); var start = token.Position; while (token.IsNot(CssTokenType.EndOfFile, CssTokenType.Semicolon, closing)) { value.Apply(token); token = NextToken(); } important = value.IsImportant; _tokenizer.IsInValue = false; var valueIsValid = value.IsValid; var result = value.ToPool(); var node = result as CssNode; if (node != null) { var end = token.Position.Shift(-1); node.SourceCode = CreateView(start, end); } if (!valueIsValid && !_parser.Options.IsToleratingInvalidValues) { RaiseErrorOccurred(CssParseError.InvalidValue, start); result = null; } return result; }
private ISelector CreateSelector(ref CssToken token) { var selector = _parser.GetSelectorCreator(); var start = token.Position; while (token.IsNot(CssTokenType.EndOfFile, CssTokenType.CurlyBracketOpen, CssTokenType.CurlyBracketClose)) { selector.Apply(token); token = NextToken(); } var selectorIsValid = selector.IsValid; var result = selector.ToPool(); var node = result as CssNode; if (node != null) { var end = token.Position.Shift(-1); node.SourceCode = CreateView(start, end); } if (!selectorIsValid && !_parser.Options.IsToleratingInvalidValues) { RaiseErrorOccurred(CssParseError.InvalidSelector, start); result = null; } return result; }