Beispiel #1
0
        private bool AreAttributesCorrect(Tag tag)
        {
            var attribLexer = new Lexer.Lexer(
                new TokenDefinition("equal", @"="),
                new TokenDefinition("string", @"""[^""']+"""),
                new TokenDefinition("string", @"'[^""']+'"),
                new TokenDefinition("float", @"[-+]?\d*\.\d+([eE][-+]?\d+)?"),
                new TokenDefinition("number", @"\d+"),
                new TokenDefinition("word", @"[^<>\s=""]+")
                )
            {
                MatchEverything = true
            };

            foreach (var attrib in tag.AttributesList)
            {
                if (!IsAttributeCorrect(attribLexer.Tokanize(attrib).Select(s => s.Type).ToArray()))
                {
                    ErrorMessage = "Incorrect attribute\n" +
                                   $"in tag {tag.Name} at position ({tag.Line}, {tag.Line}).";
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
 public HtmlValidator()
 {
     _lexer = new Lexer.Lexer(
         new TokenDefinition("NewLine", @"(\n|\r\n?)"),
         new TokenDefinition("Space", @"\s+"),
         new TokenDefinition("SelfClosingTag", @"<[^<>/]+/>"),
         new TokenDefinition("ClosingTag", @"</[^<>/]+>"),
         new TokenDefinition("OpeningTag", @"<[^<>/]+>"),
         new TokenDefinition("Word", @"[^<>\s]+")
         )
     {
         MatchEverything = true
     };
 }