Esempio n. 1
0
        public BPrimitive <TElement> this[int index]
        {
            get
            {
                BPrimitive <TElement> pointer = this;

                for (int i = 0; i < index; i++)
                {
                    if (pointer.LeftLink is BTerminal <TElement> )
                    {
                        return(default(BPrimitive <TElement>));
                    }

                    pointer = pointer.LeftLink;
                }

                return(pointer);
            }
            set
            {
                BPrimitive <TElement> pointer = this;

                for (int i = 0; i < index; i++)
                {
                    if (pointer.LeftLink is BTerminal <TElement> )
                    {
                        return;
                    }
                    pointer = pointer.LeftLink;
                }

                pointer.PushLeft(value.LeftLink);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Push element to the last right side ('till BTermainal<TElement> element)
        /// </summary>
        public void BranchRight(TElement element)
        {
            BPrimitive <TElement> parentRight = this;
            BPrimitive <TElement> nextRight   = new BNode <TElement>(element);

            if (parentRight.RightLink is BTerminal <TElement> )
            {
                parentRight.PushRight(nextRight);
            }
            else
            {
                while (!(parentRight.LeftLink is BTerminal <TElement>))
                {
                    parentRight = parentRight.RightLink;
                }

                nextRight = new BNode <TElement>(element);
                parentRight.PushLeft(nextRight);
            }

            BranchNodeLogging?.Invoke("Element brached right");
        }
Esempio n. 3
0
        /// <summary>
        ///     Set raw data associated with this element
        /// </summary>
        /// <param name="context">Data provider context</param>
        /// <param name="tree">Tree context</param>
        /// <param name="data">Data this element should interpret</param>
        /// <param name="addChild">True to automatically add node to tree</param>
        public BNode BuildNode(ReaderContext context, ParseTree <BNode> tree, byte[] data, bool addChild)
        {
            Ensure.IsNotNull(nameof(data), data);

            _rawData = new byte[data.Length];
            Array.Copy(data, _rawData, _rawData.Length);

            BNode result = null;

            // Do not try to format the data if spec says to elide
            if (Elide)
            {
                result = new BPrimitive <Phrase>(this, new Phrase($"Elided {data.Length} bytes"));
            }
            else
            {
                try
                {
                    if (!(Enumeration is null))
                    {
                        result = BuildEnumeration();
                    }
                    else if (!(Matrix is null))
                    {
                        if (_rawData.Length == 0)
                        {
                            result = new BPrimitive <Phrase>(this, new Phrase("Empty matrix"));
                        }
                        else
                        {
                            result = BuildMatrix(context, tree);

                            // A Matrix may contain a structure which adds itself to the parse tree automatically
                            addChild = Structure is null;
                        }
                    }
Esempio n. 4
0
 public override void PushRight(BPrimitive <TElement> primitive)
 {
     base.PushRight(primitive);
     BranchNodeLogging?.Invoke("Element brached right");
 }