<commit_before>﻿namespace AngleSharp.Parser.Css
{
    using AngleSharp.Css;
    using AngleSharp.DOM;
    using AngleSharp.DOM.Css;
    using AngleSharp.DOM.Html;
    using AngleSharp.Extensions;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;

    /// <summary>
    /// Class for construction for CSS selectors as specified in
    /// http://www.w3.org/html/wg/drafts/html/master/selectors.html.
    /// </summary>
    [DebuggerStepThrough]
    sealed class CssSelectorConstructor
    {
        #region Constants

        static readonly String nthChildOdd = "odd";
        static readonly String nthChildEven = "even";
        static readonly String nthChildN = "n";

        static readonly String pseudoClassRoot = "root";
        static readonly String pseudoClassOnlyType = "only-of-type";
        static readonly String pseudoClassFirstOfType = "first-of-type";
        static readonly String pseudoClassLastOfType = "last-of-type";
        static readonly String pseudoClassOnlyChild = "only-child";
        static readonly String pseudoClassFirstChild = "first-child";
        static readonly String pseudoClassLastChild = "last-child";
        static readonly String pseudoClassEmpty = "empty";
        static readonly String pseudoClassLink = "link";
        static readonly String pseudoClassVisited = "visited";
        static readonly String pseudoClassActive = "active";
        static readonly String pseudoClassHover = "hover";
        static readonly String pseudoClassFocus = "focus";
        static readonly String pseudoClassTarget = "target";
        static readonly String pseudoClassEnabled = "enabled";
        static readonly String pseudoClassDisabled = "disabled";
        static readonly String pseudoClassChecked = "checked";
        static readonly String pseudoClassUnchecked = "unchecked";
        static readonly String pseudoClassIndeterminate = "indeterminate";
        static readonly String pseudoClassDefault = "default";

        static readonly String pseudoClassValid = "valid";
        static readonly String pseudoClassInvalid = "invalid";
        static readonly String pseudoClassRequired = "required";
        static readonly String pseudoClassInRange = "in-range";
        static readonly String pseudoClassOutOfRange = "out-of-range";
        static readonly String pseudoClassOptional = "optional";
        static readonly String pseudoClassReadOnly = "read-only";
        static readonly String pseudoClassReadWrite = "read-write";

        static readonly String pseudoClassFunctionDir = "dir";
        static readonly String pseudoClassFunctionNthChild = "nth-child";
        static readonly String pseudoClassFunctionNthLastChild = "nth-last-child";
        static readonly String pseudoClassFunctionNthOfType = "nth-of-type";
        static readonly String pseudoClassFunctionNthLastOfType = "nth-last-of-type";
        static readonly String pseudoClassFunctionNot = "not";
        static readonly String pseudoClassFunctionLang = "lang";
        static readonly String pseudoClassFunctionContains = "contains";

        static readonly String pseudoElementBefore = "before";
        static readonly String pseudoElementAfter = "after";
        static readonly String pseudoElementSelection = "selection";
        static readonly String pseudoElementFirstLine = "first-line";
        static readonly String pseudoElementFirstLetter = "first-letter";

        #endregion

        #region Fields

		State state;
        ISelector temp;
		ListSelector group;
		ComplexSelector complex;
        Boolean hasCombinator;
		CssCombinator combinator;
		CssSelectorConstructor nested;
		String attrName;
		String attrValue;
		String attrOp;
        String attrNs;
        Boolean valid;

        #endregion

        #region Initialization

        static Dictionary<String, ISelector> pseudoClassSelectors = new Dictionary<String, ISelector>(StringComparer.OrdinalIgnoreCase);
        static Dictionary<String, ISelector> pseudoElementSelectors = new Dictionary<String, ISelector>(StringComparer.OrdinalIgnoreCase);

        static CssSelectorConstructor()
        {
            pseudoClassSelectors.Add(pseudoClassRoot, SimpleSelector.PseudoClass(el => el.Owner.DocumentElement == el, pseudoClassRoot));
            pseudoClassSelectors.Add(pseudoClassOnlyType, SimpleSelector.PseudoClass(el => el.IsOnlyOfType(), pseudoClassOnlyType));
            pseudoClassSelectors.Add(pseudoClassFirstOfType, SimpleSelector.PseudoClass(el => el.IsFirstOfType(), pseudoClassFirstOfType));
            pseudoClassSelectors.Add(pseudoClassLastOfType, SimpleSelector.PseudoClass(el => el.IsLastOfType(), pseudoClassLastOfType));
            pseudoClassSelectors.Add(pseudoClassOnlyChild, SimpleSelector.PseudoClass(el => el.IsOnlyChild(), pseudoClassOnlyChild));
            pseudoClassSelectors.Add(pseudoClassFirstChild, SimpleSelector.PseudoClass(el => el.IsFirstChild(), pseudoClassFirstChild));
            pseudoClassSelectors.Add(pseudoClassLastChild, SimpleSelector.PseudoClass(el => el.IsLastChild(), pseudoClassLastChild));
            pseudoClassSelectors.Add(pseudoClassEmpty, SimpleSelector.PseudoClass(el => el.ChildNodes.Length == 0, pseudoClassEmpty));
            pseudoClassSelectors.Add(pseudoClassLink, SimpleSelector.PseudoClass(el => el.IsLink(), pseudoClassLink));
            pseudoClassSelectors.Add(pseudoClassVisited, SimpleSelector.PseudoClass(el => el.IsVisited(), pseudoClassVisited));
            pseudoClassSelectors.Add(pseudoClassActive, SimpleSelector.PseudoClass(el => el.IsActive(), pseudoClassActive));
            pseudoClassSelectors.Add(pseudoClassHover, SimpleSelector.PseudoClass(el => el.IsHovered(), pseudoClassHover));
            pseudoClassSelectors.Add(pseudoClassFocus, SimpleSelector.PseudoClass(el => el.IsFocused, pseudoClassFocus));
            pseudoClassSelectors.Add(pseudoClassTarget, SimpleSelector.PseudoClass(el => el.IsTarget(), pseudoClassTarget));
            pseudoClassSelectors.Add(pseudoClassEnabled, SimpleSelector.PseudoClass(el => el.IsEnabled(), pseudoClassEnabled));
            pseudoClassSelectors.Add(pseudoClassDisabled, SimpleSelector.PseudoClass(el => el.IsDisabled(), pseudoClassDisabled));
            pseudoClassSelectors.Add(pseudoClassDefault, SimpleSelector.PseudoClass(el => el.IsDefault(), pseudoClassDefault));
            pseudoClassSelectors.Add(pseudoClassChecked, SimpleSelector.PseudoClass(el => el.IsChecked(), pseudoClassChecked));
            pseudoClassSelectors.Add(pseudoClassIndeterminate, SimpleSelector.PseudoClass(el => el.IsIndeterminate(), pseudoClassIndeterminate));
            pseudoClassSelectors.Add(pseudoClassUnchecked, SimpleSelector.PseudoClass(el => el.IsUnchecked(), pseudoClassUnchecked));
            pseudoClassSelectors.Add(pseudoClassValid, SimpleSelector.PseudoClass(el => el.IsValid(), pseudoClassValid));
            pseudoClassSelectors.Add(pseudoClassInvalid, SimpleSelector.PseudoClass(el => el.IsInvalid(), pseudoClassInvalid));
            pseudoClassSelectors.Add(pseudoClassRequired, SimpleSelector.PseudoClass(el => el.IsRequired(), pseudoClassRequired));
            pseudoClassSelectors.Add(pseudoClassReadOnly, SimpleSelector.PseudoClass(el => el.IsReadOnly(), pseudoClassReadOnly));
            pseudoClassSelectors.Add(pseudoClassReadWrite, SimpleSelector.PseudoClass(el => el.IsEditable(), pseudoClassReadWrite));
            pseudoClassSelectors.Add(pseudoClassInRange, SimpleSelector.PseudoClass(el => el.IsInRange(), pseudoClassInRange));
            pseudoClassSelectors.Add(pseudoClassOutOfRange, SimpleSelector.PseudoClass(el => el.IsOutOfRange(), pseudoClassOutOfRange));
            pseudoClassSelectors.Add(pseudoClassOptional, SimpleSelector.PseudoClass(el => el.IsOptional(), pseudoClassOptional));

            // LEGACY STYLE OF DEFINING PSEUDO ELEMENTS - AS PSEUDO CLASS!
            pseudoClassSelectors.Add(pseudoElementBefore, SimpleSelector.PseudoClass(MatchBefore, pseudoElementBefore));
            pseudoClassSelectors.Add(pseudoElementAfter, SimpleSelector.PseudoClass(MatchAfter, pseudoElementAfter));
            pseudoClassSelectors.Add(pseudoElementFirstLine, SimpleSelector.PseudoClass(MatchFirstLine, pseudoElementFirstLine));
            pseudoClassSelectors.Add(pseudoElementFirstLetter, SimpleSelector.PseudoClass(MatchFirstLetter, pseudoElementFirstLetter));

            pseudoElementSelectors.Add(pseudoElementBefore, SimpleSelector.PseudoElement(MatchBefore, pseudoElementBefore));
            pseudoElementSelectors.Add(pseudoElementAfter, SimpleSelector.PseudoElement(MatchAfter, pseudoElementAfter));
            pseudoElementSelectors.Add(pseudoElementSelection, SimpleSelector.PseudoElement(el => true, pseudoElementSelection));
            pseudoElementSelectors.Add(pseudoElementFirstLine, SimpleSelector.PseudoElement(MatchFirstLine, pseudoElementFirstLine));
            pseudoElementSelectors.Add(pseudoElementFirstLetter, SimpleSelector.PseudoElement(MatchFirstLetter, pseudoElementFirstLetter));
        }

        #endregion

        #region ctor

        /// <summary>
        /// Creates a new constructor object.
        /// </summary>
        public CssSelectorConstructor()
        {
			Reset();
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets if the stored selector is valid.
        /// </summary>
        public Boolean IsValid
        {<commit_msg>Improved empty pseudo selector<commit_after>﻿namespace AngleSharp.Parser.Css
{
    using AngleSharp.Css;
    using AngleSharp.DOM;
    using AngleSharp.DOM.Css;
    using AngleSharp.DOM.Html;
    using AngleSharp.Extensions;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;

    /// <summary>
    /// Class for construction for CSS selectors as specified in
    /// http://www.w3.org/html/wg/drafts/html/master/selectors.html.
    /// </summary>
    [DebuggerStepThrough]
    sealed class CssSelectorConstructor
    {
        #region Constants

        static readonly String nthChildOdd = "odd";
        static readonly String nthChildEven = "even";
        static readonly String nthChildN = "n";

        static readonly String pseudoClassRoot = "root";
        static readonly String pseudoClassOnlyType = "only-of-type";
        static readonly String pseudoClassFirstOfType = "first-of-type";
        static readonly String pseudoClassLastOfType = "last-of-type";
        static readonly String pseudoClassOnlyChild = "only-child";
        static readonly String pseudoClassFirstChild = "first-child";
        static readonly String pseudoClassLastChild = "last-child";
        static readonly String pseudoClassEmpty = "empty";
        static readonly String pseudoClassLink = "link";
        static readonly String pseudoClassVisited = "visited";
        static readonly String pseudoClassActive = "active";
        static readonly String pseudoClassHover = "hover";
        static readonly String pseudoClassFocus = "focus";
        static readonly String pseudoClassTarget = "target";
        static readonly String pseudoClassEnabled = "enabled";
        static readonly String pseudoClassDisabled = "disabled";
        static readonly String pseudoClassChecked = "checked";
        static readonly String pseudoClassUnchecked = "unchecked";
        static readonly String pseudoClassIndeterminate = "indeterminate";
        static readonly String pseudoClassDefault = "default";

        static readonly String pseudoClassValid = "valid";
        static readonly String pseudoClassInvalid = "invalid";
        static readonly String pseudoClassRequired = "required";
        static readonly String pseudoClassInRange = "in-range";
        static readonly String pseudoClassOutOfRange = "out-of-range";
        static readonly String pseudoClassOptional = "optional";
        static readonly String pseudoClassReadOnly = "read-only";
        static readonly String pseudoClassReadWrite = "read-write";

        static readonly String pseudoClassFunctionDir = "dir";
        static readonly String pseudoClassFunctionNthChild = "nth-child";
        static readonly String pseudoClassFunctionNthLastChild = "nth-last-child";
        static readonly String pseudoClassFunctionNthOfType = "nth-of-type";
        static readonly String pseudoClassFunctionNthLastOfType = "nth-last-of-type";
        static readonly String pseudoClassFunctionNot = "not";
        static readonly String pseudoClassFunctionLang = "lang";
        static readonly String pseudoClassFunctionContains = "contains";

        static readonly String pseudoElementBefore = "before";
        static readonly String pseudoElementAfter = "after";
        static readonly String pseudoElementSelection = "selection";
        static readonly String pseudoElementFirstLine = "first-line";
        static readonly String pseudoElementFirstLetter = "first-letter";

        #endregion

        #region Fields

		State state;
        ISelector temp;
		ListSelector group;
		ComplexSelector complex;
        Boolean hasCombinator;
		CssCombinator combinator;
		CssSelectorConstructor nested;
		String attrName;
		String attrValue;
		String attrOp;
        String attrNs;
        Boolean valid;

        #endregion

        #region Initialization

        static Dictionary<String, ISelector> pseudoClassSelectors = new Dictionary<String, ISelector>(StringComparer.OrdinalIgnoreCase);
        static Dictionary<String, ISelector> pseudoElementSelectors = new Dictionary<String, ISelector>(StringComparer.OrdinalIgnoreCase);

        static CssSelectorConstructor()
        {
            pseudoClassSelectors.Add(pseudoClassRoot, SimpleSelector.PseudoClass(el => el.Owner.DocumentElement == el, pseudoClassRoot));
            pseudoClassSelectors.Add(pseudoClassOnlyType, SimpleSelector.PseudoClass(el => el.IsOnlyOfType(), pseudoClassOnlyType));
            pseudoClassSelectors.Add(pseudoClassFirstOfType, SimpleSelector.PseudoClass(el => el.IsFirstOfType(), pseudoClassFirstOfType));
            pseudoClassSelectors.Add(pseudoClassLastOfType, SimpleSelector.PseudoClass(el => el.IsLastOfType(), pseudoClassLastOfType));
            pseudoClassSelectors.Add(pseudoClassOnlyChild, SimpleSelector.PseudoClass(el => el.IsOnlyChild(), pseudoClassOnlyChild));
            pseudoClassSelectors.Add(pseudoClassFirstChild, SimpleSelector.PseudoClass(el => el.IsFirstChild(), pseudoClassFirstChild));
            pseudoClassSelectors.Add(pseudoClassLastChild, SimpleSelector.PseudoClass(el => el.IsLastChild(), pseudoClassLastChild));
            pseudoClassSelectors.Add(pseudoClassEmpty, SimpleSelector.PseudoClass(el => el.ChildElementCount == 0 && el.TextContent.Equals(String.Empty), pseudoClassEmpty));
            pseudoClassSelectors.Add(pseudoClassLink, SimpleSelector.PseudoClass(el => el.IsLink(), pseudoClassLink));
            pseudoClassSelectors.Add(pseudoClassVisited, SimpleSelector.PseudoClass(el => el.IsVisited(), pseudoClassVisited));
            pseudoClassSelectors.Add(pseudoClassActive, SimpleSelector.PseudoClass(el => el.IsActive(), pseudoClassActive));
            pseudoClassSelectors.Add(pseudoClassHover, SimpleSelector.PseudoClass(el => el.IsHovered(), pseudoClassHover));
            pseudoClassSelectors.Add(pseudoClassFocus, SimpleSelector.PseudoClass(el => el.IsFocused, pseudoClassFocus));
            pseudoClassSelectors.Add(pseudoClassTarget, SimpleSelector.PseudoClass(el => el.IsTarget(), pseudoClassTarget));
            pseudoClassSelectors.Add(pseudoClassEnabled, SimpleSelector.PseudoClass(el => el.IsEnabled(), pseudoClassEnabled));
            pseudoClassSelectors.Add(pseudoClassDisabled, SimpleSelector.PseudoClass(el => el.IsDisabled(), pseudoClassDisabled));
            pseudoClassSelectors.Add(pseudoClassDefault, SimpleSelector.PseudoClass(el => el.IsDefault(), pseudoClassDefault));
            pseudoClassSelectors.Add(pseudoClassChecked, SimpleSelector.PseudoClass(el => el.IsChecked(), pseudoClassChecked));
            pseudoClassSelectors.Add(pseudoClassIndeterminate, SimpleSelector.PseudoClass(el => el.IsIndeterminate(), pseudoClassIndeterminate));
            pseudoClassSelectors.Add(pseudoClassUnchecked, SimpleSelector.PseudoClass(el => el.IsUnchecked(), pseudoClassUnchecked));
            pseudoClassSelectors.Add(pseudoClassValid, SimpleSelector.PseudoClass(el => el.IsValid(), pseudoClassValid));
            pseudoClassSelectors.Add(pseudoClassInvalid, SimpleSelector.PseudoClass(el => el.IsInvalid(), pseudoClassInvalid));
            pseudoClassSelectors.Add(pseudoClassRequired, SimpleSelector.PseudoClass(el => el.IsRequired(), pseudoClassRequired));
            pseudoClassSelectors.Add(pseudoClassReadOnly, SimpleSelector.PseudoClass(el => el.IsReadOnly(), pseudoClassReadOnly));
            pseudoClassSelectors.Add(pseudoClassReadWrite, SimpleSelector.PseudoClass(el => el.IsEditable(), pseudoClassReadWrite));
            pseudoClassSelectors.Add(pseudoClassInRange, SimpleSelector.PseudoClass(el => el.IsInRange(), pseudoClassInRange));
            pseudoClassSelectors.Add(pseudoClassOutOfRange, SimpleSelector.PseudoClass(el => el.IsOutOfRange(), pseudoClassOutOfRange));
            pseudoClassSelectors.Add(pseudoClassOptional, SimpleSelector.PseudoClass(el => el.IsOptional(), pseudoClassOptional));

            // LEGACY STYLE OF DEFINING PSEUDO ELEMENTS - AS PSEUDO CLASS!
            pseudoClassSelectors.Add(pseudoElementBefore, SimpleSelector.PseudoClass(MatchBefore, pseudoElementBefore));
            pseudoClassSelectors.Add(pseudoElementAfter, SimpleSelector.PseudoClass(MatchAfter, pseudoElementAfter));
            pseudoClassSelectors.Add(pseudoElementFirstLine, SimpleSelector.PseudoClass(MatchFirstLine, pseudoElementFirstLine));
            pseudoClassSelectors.Add(pseudoElementFirstLetter, SimpleSelector.PseudoClass(MatchFirstLetter, pseudoElementFirstLetter));

            pseudoElementSelectors.Add(pseudoElementBefore, SimpleSelector.PseudoElement(MatchBefore, pseudoElementBefore));
            pseudoElementSelectors.Add(pseudoElementAfter, SimpleSelector.PseudoElement(MatchAfter, pseudoElementAfter));
            pseudoElementSelectors.Add(pseudoElementSelection, SimpleSelector.PseudoElement(el => false, pseudoElementSelection));
            pseudoElementSelectors.Add(pseudoElementFirstLine, SimpleSelector.PseudoElement(MatchFirstLine, pseudoElementFirstLine));
            pseudoElementSelectors.Add(pseudoElementFirstLetter, SimpleSelector.PseudoElement(MatchFirstLetter, pseudoElementFirstLetter));
        }

        #endregion

        #region ctor

        /// <summary>
        /// Creates a new constructor object.
        /// </summary>
        public CssSelectorConstructor()
        {
			Reset();
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets if the stored selector is valid.
        /// </summary>
        public Boolean IsValid
        {
{'fraction_non_alphanumeric': 0.08691987567823842, 'fraction_numerical': 0.00021071485012906285, 'mean_word_length': 3.9644351464435146, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5317259', 'n_tokens_mistral': 4750, 'n_tokens_neox': 4730, 'n_words': 966}