Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChildEnumerator"/> class.
 /// This class is used to initialize the enumerator.
 /// </summary>
 /// <param name="childIterable">The referenced <see cref="ChildIterable"/> class.</param>
 /// <param name="treeContext">The tree context, <see cref="ParserRuleContext"/>.</param>
 internal ChildEnumerator(ChildIterable childIterable, ParserRuleContext treeContext)
 {
     this.childIterable = childIterable;
     if (treeContext.children is null)
     {
         this.childIter = null;
         this.Current   = null;
         this.index     = -1;
     }
     else
     {
         this.childIter = treeContext.children.GetEnumerator();
     }
 }
Пример #2
0
        /// <summary>
        /// Initialize the <see cref="UserAgentGetChildrenVisitor"/> by the name and provided range.
        /// </summary>
        /// <param name="name">The name of the visitor based on the kind of node we need to iterate children.</param>
        /// <param name="start">The start range.</param>
        /// <param name="end">>The end range.</param>
        private void Init(string name, int start, int end)
        {
            switch (name)
            {
            case UserAgentTreeFlattener.KEYVALUE:
                this.childIterable = new ChildIterable(false, start, end, clazz => (
                                                           clazz is UserAgentParser.KeyValueContext ||
                                                           clazz is UserAgentParser.KeyWithoutValueContext ||
                                                           clazz is UserAgentParser.ProductNameKeyValueContext));
                break;

            case UserAgentTreeFlattener.PRODUCT:
                this.childIterable = new ChildIterable(false, start, end, clazz => (
                                                           clazz is UserAgentParser.ProductContext ||
                                                           clazz is UserAgentParser.CommentProductContext ||
                                                           clazz is UserAgentParser.ProductNameNoVersionContext));
                break;

            case UserAgentTreeFlattener.UUID:
                this.childIterable = new ChildIterable(false, start, end, clazz => (
                                                           clazz is UserAgentParser.UuIdContext ||
                                                           clazz is UserAgentParser.ProductNameUuidContext));
                break;

            case UserAgentTreeFlattener.BASE64:
                this.childIterable = new ChildIterable(false, start, end, clazz => (
                                                           clazz is UserAgentParser.Base64Context));
                break;

            case UserAgentTreeFlattener.URL:
                this.childIterable = new ChildIterable(false, start, end, clazz => (
                                                           clazz is UserAgentParser.SiteUrlContext ||
                                                           clazz is UserAgentParser.ProductNameUrlContext));
                break;

            case UserAgentTreeFlattener.EMAIL:
                this.childIterable = new ChildIterable(false, start, end, clazz => (
                                                           clazz is UserAgentParser.EmailAddressContext ||
                                                           clazz is UserAgentParser.ProductNameEmailContext));
                break;

            case UserAgentTreeFlattener.TEXT:
                this.childIterable = new ChildIterable(false, start, end, clazz => (
                                                           clazz is UserAgentParser.MultipleWordsContext ||
                                                           clazz is UserAgentParser.VersionWordsContext ||
                                                           clazz is UserAgentParser.EmptyWordContext ||
                                                           clazz is UserAgentParser.RootTextContext ||
                                                           clazz is UserAgentParser.KeyValueVersionNameContext));
                break;

            case UserAgentTreeFlattener.NAME:
                this.childIterable = new ChildIterable(false, start, end, clazz => (
                                                           clazz is UserAgentParser.ProductNameContext));
                break;

            case UserAgentTreeFlattener.VERSION:
                this.childIterable = new ChildIterable(true, start, end, clazz => (
                                                           clazz is UserAgentParser.ProductVersionContext ||
                                                           clazz is UserAgentParser.ProductVersionWithCommasContext ||
                                                           clazz is UserAgentParser.ProductVersionWordsContext ||
                                                           clazz is UserAgentParser.ProductVersionSingleWordContext));
                break;

            case UserAgentTreeFlattener.COMMENTS:
                this.childIterable = new ChildIterable(true, start, end, clazz => (
                                                           clazz is UserAgentParser.CommentBlockContext));
                break;

            case UserAgentTreeFlattener.KEY:
                this.childIterable = new ChildIterable(false, start, end, clazz => (
                                                           clazz is UserAgentParser.KeyNameContext));
                break;

            case UserAgentTreeFlattener.VALUE:
                this.childIterable = new ChildIterable(false, start, end, clazz => (
                                                           clazz is UserAgentParser.UuIdContext ||
                                                           clazz is UserAgentParser.MultipleWordsContext ||
                                                           clazz is UserAgentParser.SiteUrlContext ||
                                                           clazz is UserAgentParser.EmailAddressContext ||
                                                           clazz is UserAgentParser.KeyValueVersionNameContext ||
                                                           clazz is UserAgentParser.KeyValueProductVersionNameContext));
                break;

            case UserAgentTreeFlattener.ENTRY:
                this.childIterable = new ChildIterable(false, start, end, clazz => (
                                                           clazz is UserAgentParser.CommentEntryContext));
                break;

            default:
                this.childIterable = new ChildIterable(false, start, end, clazz => false);
                break;
            }
        }